如何在集成测试中更改夹具值

时间:2015-07-17 10:30:57

标签: ruby-on-rails ruby ruby-on-rails-4 testing integration-testing

我正在编写集成测试,并且在测试中的某个点我想要更改夹具的两个值。我怎么能这样做?

我尝试了以下内容:

@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

1 个答案:

答案 0 :(得分:1)

修改值后需要保存对象。所以改变:

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

要:

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