8

I want to test to a controller that works on browser and looks like this

http://url.dev/jobs/1445.json?project_id=1144&accesskey=MyString

this is what i have on my controler spec file:

params = {:id=>"1445", :project_id=>1144, :accesskey=>"MyString"}
get :show, params, format: :json

On the log i see:

Processing by JobsController#show as HTML
    Parameters: {"id"=>"1440"}

Why it is trying to process as HTML and not as JSON? Why it only receives the id parameter?

Also, if I do this:

get :show, id: params[:id], format: :json

It tries to process using JSON but it dont works because I need the other params.

2 Answers 2

13

The format: :json part must be on the 2nd argument.

This works pretty well

params = {:id=>"1445", :project_id=>1144, :accesskey=>"MyString", format: :json}
get :show, params
Sign up to request clarification or add additional context in comments.

Comments

-2

get only takes 2 arguments, the "action" and "args"

Your code:

get :show, params, format: :json

Is passing in 3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.