0

I am trying to send some raw data in a JSON post request to my RSpec controller test. I have successfully tested the controller with an actual Postman request but I can't get the Rspec test to work

The error I am getting is

param is missing or the value is empty: annotations 

Here is my test set-up, which I have copied verbatimly from rails server log when I run the request via Postman

params = '{annotations"=>[{"id"=>1, "location_start"=>1, "location_end"=>3, "source_text"=>"what", "reading"=>"cool"}, {"id"=>2, "location_start"=>1, "location_end"=>-1, "reading"=>"cool"}]}' patch :update, params, format: :json 

I have also tried

params = {:annotations => [{ :id=>1, :location_start=>1, :location_end=>3}]} patch :update, params.to_json 
1
  • can you try it like this: patch :update, :annotations: [{ :id=>1, :location_start=>1, :location_end=>3}].to_json Commented Nov 26, 2015 at 12:51

1 Answer 1

1

https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/controller-spec#setting-a-different-content-type-for-example-json-(request-type)

Check out how the json body is defined in this example: It's a ruby hash! So you need to not try passing in a raw string but a Hash that then gets automatically converted to JSON for you.

Hope that helps you out

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.