Grape API をテストしようとしていますが、テストで 400 エラーが発生しますが、テストでテストするはずのアクションを実行すると、予想どおり 201 HTTP 応答が返されます。ここで何が起こっているのかわかりません。以下は特定の RSpec テストですが、ファクトリと実際の Grape API を含むプロジェクト全体を GitHub のhackcentral/hackcentralで表示できます。以下のテストは、Alpha::Applications で POST create アクションをテストしています。(アプリ/api/アルファ/applications.rb)
describe 'POST #create' do
before :each do
@oauth_application = FactoryGirl.build(:oauth_application)
@token = Doorkeeper::AccessToken.create!(:application_id => @oauth_application.id, :resource_owner_id => user.id)
end
context "with valid attributes" do
it "creates a new application" do
expect{
post "http://api.vcap.me:3000/v1/applications?access_token=#{@token.token}", application: FactoryGirl.attributes_for(:application), :format => :json
} .to change(Application, :count).by(1)
end
it "creates a new application, making sure response is #201" do
post "http://api.vcap.me:3000/v1/applications", application: FactoryGirl.attributes_for(:application), :format => :json, :access_token => @token.token
response.status.should eq(201)
end
end
end