I am currently creating a JSON API running on Rails / rails-api. I have a route that accepts JSON sending through a PATCH request and a filter before that needs access to the raw / JSON request .
For testing purposes, I added the following before the filter to show my problem:
before_filter do puts "Raw Post: #{request.raw_post.inspect}" puts "Params: #{params.inspect}" end
The following curl request works as intended:
curl -X PATCH -H "Content-Type: application/json" -d '{"key":"value"}' http://localhost:3000/update # Raw Post: "{\"key\":\"value\"}" # Params: {"key"=>"value", "action"=>"update", "controller"=>"posts"}
However, I have not tested this method, none of the following calls work:
Params are included, but not as passed JSON
test 'passing hash' do patch :update, { key: "value" } end # Raw Post: "key=value" # Params: {"key"=>"value", "controller"=>"posts", "action"=>"update"}
Passwords are included, but again not as passed JSON
test 'passing hash, setting the format' do patch :update, { key: "value" }, format: :json end # Raw Post: "key=value" # Params: {"key"=>"value", "controller"=>"posts", "action"=>"update", "format"=>"json"}
JSON format but not included in parameters
test 'passing JSON' do patch :update, { key: "value" }.to_json end
JSON format but not included in parameters
test 'passing JSON, setting format' do patch :update, { key: "value" }.to_json, format: :json end
This list is even longer, I just wanted to show you my problem. I tested setting the Accept and Content-Type headers to application/json too, nothing seems to help. Am I doing something wrong, or is this a bug in Rails functional tests?
source share