新手问题 RSpec update 遇到一个问题

ThanksSirAlec · January 25, 2018 · Last by ThanksSirAlec replied at January 25, 2018 · 979 hits

写了一个很简单的测试

let(:coupon) { FactoryGirl.create(:coupon) }
it 'can update a coupon' do
      coupon
      expect{
        put :update, id: coupon.id, discount: 40
      }.to change(coupon, :discount)
end

我在 controller 里面添加了 debugger 确确实实的看到了 discount 值从 20 变到 40,但是为什么回到测试代码的时候值就🈶回到 20 了,怎么测都过不了

coupon.reload

Reply to hging

请问,这个命令干什么用的,为什么不加的话 discount 值不会变呢

Reply to hging

多谢大佬

ThanksSirAlec closed this topic. 25 Jan 16:50
You need to Sign in before reply, if you don't have an account, please Sign up first.