RSpec / FactoryGirl - How to pass parameters in a request specification
I have a Rails API built with soothing routes. I am trying to pass parameters for a post request specification but I am facing some problems.
In my application, the user has a lot of timelines and the timeline has a lot of records. I can correctly create the timeline with the post request by following these steps:
post '/timelines', '{ "timeline": { "title":"My timeline", "body":"My timeline body"}}', @token_header
The problem I have is when I need to transfer more than just a string, i.e. an image. My input model has an attribute image
, but I can't figure out how to navigate to the parameters.
I have the following test that illustrates what I want to do. As you can see, I have declared some entry_attributes, but cannot figure out how to pass them correctly, as with the timeline parameters .:
context 'POST /timelines/:id/entries' do
it 'creates an entry for the given timeline' do
entry_attr = FactoryGirl.attributes_for(:entry)
post "/timelines/#{@timeline.id}/entries", {}, @token_header
expect(response.status).to eq 201
end
end
Any help is greatly appreciated ...
source to share
No one has answered this question yet
Check out similar questions: