如何在集成测试中更改夹具值
How to change fixture values inside integration test
我正在编写集成测试,在测试中的某个时刻,我想更改夹具的两个值。我该怎么做?
我尝试了以下方法:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
然而,这似乎不起作用。尽管 puts @organization1
和 puts @organization1.expires
(见下文)确认了新值,但显示组织概况的 puts @response.body
仍然显示旧值(使测试失败)。我做错了什么?
部分测试代码:
get organization_path(@organization1)
...
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
get organization_path(@organization1) # So that it reloads the screen with the new values
puts @organization1.subscription # Has the new value
puts @organization1.expires # Has the new value
puts @response.body # Still has the old values
您需要在修改值后保存对象。所以改变:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
收件人:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
@organization1.save
我正在编写集成测试,在测试中的某个时刻,我想更改夹具的两个值。我该怎么做?
我尝试了以下方法:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
然而,这似乎不起作用。尽管 puts @organization1
和 puts @organization1.expires
(见下文)确认了新值,但显示组织概况的 puts @response.body
仍然显示旧值(使测试失败)。我做错了什么?
部分测试代码:
get organization_path(@organization1)
...
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
get organization_path(@organization1) # So that it reloads the screen with the new values
puts @organization1.subscription # Has the new value
puts @organization1.expires # Has the new value
puts @response.body # Still has the old values
您需要在修改值后保存对象。所以改变:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
收件人:
@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days
@organization1.save