Topic: Going nuts trying to test a simple GET controller


I have a simple controller that responds to GET requests and accepts a query parameter.  I am trying to write a  test that calls it and I am getting 406 errors back from it.  In my controller, I have:

respond_to :json

In my test, if I call this way:

get :index, :format => :json

It passes the right header and I get in.  If, however, I attempt to pass a parameter like this:

get :index, { my_param_value => 'foo' }, :format => :json

It does pass the parameter (I see this by calling inspect on response) but it does not pass the right header for Content-Type.  If I call inspect on response when I don't pass the parameter (i.e. the first call above), I see that it sets Content-Type to application/json as it should.  When I pass the parameter, it sets Content-Type to text/html.

I'm completely baffled and would LOVE some help from the smart people.


Re: Going nuts trying to test a simple GET controller

I solved my own problem.  I need to call get like this:

get :index, {my_param_value => 'foo', :format => :json}

And that solved my problem.  Doesn't make any kind of syntactical sense to me but hey.  I'll roll with it.