On Nov 4, 6:10 pm, Grary Stimon <li...@ruby-forum.com> wrote:
> Hi,
>
> I'm unable to properly test GET calls for my JSON API in Rails 3.1,
> using ActionController::TestCase.
>
> get :loan, ActiveSupport::JSON.encode(minimum_valid_json_params),
> :format => :json
>
> ...where minimum_valid_json_params has the form...
>
> {:one_thing=>"something", :another_thing=>23, ... }
>
> ...gives me the following unsatisfying error in the test:
>
> NoMethodError: undefined method `symbolize_keys' for #<String:0x6304db>
>
> So, my first question is: What setup do I need to properly test a JSON
> GET request that passes parameters, as above?
>

The get method is expecting its second argument to be a hash of
parameter name / value pairs, while JSON.encode is returning a string.
I'm not certain what you'll need to change, as I don't know what
format your controller is expecting the parameters in.

> Next, I'm concerned that if I succeed with TestCase's get method, I may
> run into a problem in my controller: is request.body available for a GET
> request like mine, or is it only for PUT/POST?

GET requests do not typically have request bodies - depending on your
web server, the body may or may not make it all the way to Rails. More
discussion here:

http://stackoverflow.com/questions/978061/http-get-with-request-body

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to