在我的一个测试中,我必须验证某个offer是否返回404响应,如果可用限制(例如该offer的10个席位)全部售出,或者它已经到期了,这是第一次。rails请求规格json的PUT方法没有通过
我只是不能PUT请求中请求规格的工作,这是我的代码
RSpec.describe "Offers", type: :request do
describe "gives not found response" do
it "when available limit exhausts before date till available" do
offer = Offer.new
Timecop.freeze(Date.today - 12.days) do
offer = FactoryGirl.create(:offer)
end
payload = FactoryGirl.attributes_for(:offer, :available_limit => 0, :discount_id => offer.discount.id, :coupon_id => offer.coupon.id)
sign_in
put '/offers/'<<offer.id, params: { id: offer.id, offer: payload }, as: :json
get "/vouchers/"<<offer.coupon.voucher_code
expect(response.status).to eq 404
end
end
end
针地说,我已经尝试了许多黑客攻击,包括
put '/offers/'<<offer.id.to_s<<".json", params: { offer: payload }
甚至
put '/offers/'<<offer.id.to_s<<".json", payload
我还注意到,在其中一个组合中,请求确实通过了,但它响应H两块HTML和JSON格式,导致规范错误,因为我不是在水豚运行它们(我不想要么)
'format::json'在最近的版本中已经改成'as::json',我不认为这是因为那个破坏 –