Reputation: 2081
I have this in my rspec test
it 'that can be mass inserted' do
score_count = Score.all.length
post '/score', @mass_score_data
Score.all.length.should eq score_count+2
end
where @mass_score_data is an array of hashes [{id: 5, something: 3}, {id: 4, something: 2}]. I'm assuming that I am getting this array from an app that connects to Sinatra.
rspec says
Failure/Error: post '/score', @mass_score_data
NoMethodError:
undefined method `read' for #<Array:0x007fd7e507bd80>
Am I missing something here, or can we just not pass arrays into Sinatra? BTW I also tried arrays like [1, 2, 3, 4], it still is "undefined method 'read'"
Upvotes: 0
Views: 1562
Reputation: 5205
Assuming your post
body in the Score
class looks like:
post '/add_scores' do
scores = params[:scores]
....
end
Then you should be able to do:
post 'add_scores', {:scores => @mass_data}
Look at Testing in Sinatra for further reading.
Upvotes: 2