In my specs, when I run the POST request below, everything works fine.
before do
request_payload = {
player: {
first_name: "Joe",
last_name: "Carradine",
team_id: "1"
}
}
post :create, request_payload
end
But when I run a spec for PUT:
before do
request_payload = {
player: {
first_name: "Buck",
last_name: "Carradine",
team_id: "1"
}
}
put :update, id: 3, request_payload
end
I get an error like this:
[filename]_spec.rb:139: syntax error, unexpected '\n', expecting tASSOC (SyntaxError)
[filename]_spec.rb:198: syntax error, unexpected $end, expecting keyword_end
Any ideas? Is there a different syntax for PUT I’m not aware of?
To fix the syntax error, use
put :update, { id: 3 }, request_payload, notput :update, id: 3, request_payload. Ruby only supports “bare” (e.g. curly-braceless) hashes as the last argument to the method, soid: 3cannot appear in the middle of an argument list without being wrapped in curly braces.