Search code examples
ruby-on-railsrspecruby-on-rails-5rspec-railsapipie

Apipie receiving integer param as String


I have the following RSpec test:

 it 'should not list alerts, since I do not have access to this model' do
   get :index, params: { model_id: @model2.id, workspace_id: @workspace.id }, as: :json
   expect(response).to have_http_status(:forbidden)
 end

and it is failing because Apipie is complaining the workspace_id is a String when it is actually not, it is an Integer. I debugged the call, inspected @workspace and id is definitely an Integer.

I'm seeing this issue now that I'm migrating the application to Rails 5.2.0 (previously Rails 4).

Has anyone seen something like this?


Solution

  • The GET request doesn't contains body, while you're trying to send some payload. In the case of GET request all params passed as url query (e.g. /index?model_id=1&workspace_id=1) and all params are string.

    You have two options here:

    • Change GET to POST, it will allow request with body.
    • Convert string to integer in the action.