I have a JSON Rails 4 API that I'm testing with Rspec. I'm having trouble passing to two parameters in the post :create request.
Here is the current test:
require 'spec_helper'
module Api
module V1
describe Api::V1::ProductsController, type: :controller do
before do
@api_app = FactoryGirl.create(:api_app, request_origin: "0.0.0.0")
@store = FactoryGirl.create(:store)
end
after(:all) do
Product.all.each {|l| l.destroy}
ApiApp.all.each {|a| a.destroy}
end
describe "POST 'create' " do
context "Creates a product with the correct parameters" do
it "returns a successful response string with success message" do
json = { :format => 'json', product:{first_name:"Hello", last_name:"You", email:"email@email.edu",street1:"103 ABC Street", city:"Pittsburgh", phone:"4125361111", store_id:@store.id, state:"CA", country:"United States", organization:"ABC", organization_type: "Org"}}
post :create, json, access_token: @api_app.access_token
expect(response).to be_success
expect(response.body).to include("Product created")
end
end
context "Incorrect parameters to create a product" do
it "returns a failure response when a parameter is missing" do
json = { :format => 'json', product:{first_name:"Hello", last_name:"You", email:"email@email.edu",street1:"103 ABC Street", city:"Pittsburgh", phone:"4125361111", store_id:@store.id, state:"CA", country:"United States", organization:"ABC"}}
post :create, json, access_token: @api_app.access_token
expect(response).to be_success
expect(response.body).to include("Product failed to create")
end
end
end
end
end
end
I need both json and access_token on the line:
post :create, json, access_token: @api_app.access_token
but the request ignores the second parameter (I can switch their placement to confirm). How do I word the post so that both parameters are read in?