我正在编写一个集成测试,在测试的某个点上,我希望更改一个fixture的两个值。我该怎么做?
我尝试了以下方法:

@organization1.toggle!(:subscription)
@organization1.expires = Time.zone.now + 50.days

然而,这似乎不起作用。尽管puts @organization1puts @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

10-06 01:34