Question

I am building a grape api for a rails app. I am testing it with rspec request specs. I have encountered the problem when making a post route like this:

resources :events do
  segment '/:event_id' do
    resources :tickets do
       post do
         event = current_user.events.find params[:event_id]
         ...#do sth with event using params[:tickets_ids]

the corresponding spec:

it "should should return the JSON hash of validated tickets" do
  post "/api/mobile/#{version}/events/#{event.id}/tickets/", { tickets_ids: [1,2] }, credentials
  response.should be_success
  JSON.parse(response.body).should be_kind_of Hash
end

Grape 'controller' is not able to see any params which are not sent as a part of url. When printing out params[:tickets_ids] it is nil. I do not have this problem when using get requests. I am able to reproduce the issue when sending request manually using curl. Nested resources routing is also not a problem since it behaves the same with top level route.

I have found the following issue on github but applying the given monkey patch does not work and breaks the server on startup. https://github.com/intridea/grape/issues/417

I am using the following version of gems and am unable to upgrade them due to dependency conflicts:

grape (0.2.1.1)
rails(3.0.7)
rspec-rails (2.6.1)

Any help and tips will be greatly appreciated.

Was it helpful?

Solution

If I recall there should be a header set Content-Type with the value application/x-www-form-urlencoded

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top