I've written an update action with the Grape API in rails, shown here:
put do
work = Work.find(permitted_params[:id])
work.title = permitted_params[:title]
work.date = permitted_params[:date]
work.save!
end
Testing it with the swagger documentation in my browser, I get success.
I have a spec for it that isn't working quite right. Despite the success in the browser, my test fails because it says it's getting a 405 in the response. Here's the spec:
describe "PUT /api/v1/works/work_id" do
let(:user) { FactoryGirl.create(:user) }
let(:collection) { FactoryGirl.create(:collection, user: user) }
let(:work) { FactoryGirl.create(:work, collection: collection) }
let(:work_data) do
{
collection: collection.id,
title: "Lorem ipsum dolor sit amet",
date: 1492,
place: "Chicago",
}
end
describe "Modify title" do
let(:work_title) { "gfd" }
before :each do
work_data[:title] = work_title
put "/api/v1/works/#{work.id}", work_data
work.reload
end
it "returns success" do
expect(response).to be_success
end
it "updates the title of the work" do
expect(work.title).to eql(work_title)
end
end
end
I'm curious why it seems to be working correctly, but I'm still getting a 405 error in my test.
Edit to include response from the server 405 {"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Allow"=>"OPTIONS, GET, HEAD", "Content-Type"=>"text/plain", "Content-Length"=>"0", "Cache-Control"=>"no-cache", "X-Request-Id"=>"5edd38be-289d-4e97-875d-2461389a746d", "X-Runtime"=>"0.088867"} #