Hello,
I'm converting a Rails 4.2 project to Rails 5.0 and changing the existing controller specs. rspec-rails is at 3.6.0, ruby is 2.3.3. I've included the rails-controller-testing gem in the project.
One spec passes a param that is a hash, like that:
describe "#submit" do
before do
params = {param1: 'hello', param2: {}, id: quiz.id}
post :submit, params: params
end
it { is_expected.to respond_with(:found) }
it { is_expected.to redirect_to(quiz_path(quiz)) }
end
In the controller action if I print the received params:
def submit
p params
...
end
the output is like that:
<ActionController::Parameters {"param1"=>"hello", "id"=>"7938", "controller"=>"quizzes", "action"=>"submit"} permitted: false>
The param2 param is missing, while the param1 param is present. This is why it seems to me that the hash param is skipped somehow.
You need to pas as: :json to your request. See related issue https://github.com/rails/rails/issues/26569
post :submit, params: params, as: :json
@laertispappas: thanks for the comment, updating to Rails 5.0.5 and using as: :json resolves the issue.
Most helpful comment
You need to pas
as: :jsonto your request. See related issue https://github.com/rails/rails/issues/26569