测试after_save回调评估saved_change_to_attribute?

时间:2017-12-06 14:59:42

标签: ruby-on-rails

我最近将我的应用程序升级到rails 5.1,导致我开始在after_save回调中使用after_save。这导致了一次破裂的考验。

我试图测试的代码是通过def items_update_needed? return (online_only? || saved_change_to_online_only?) && (saved_change_to_published? && !complete? || saved_change_to_online_only? || saved_change_to_listing? || saved_change_to_third_party_bidding_url? || saved_change_to_starts_at? || saved_change_to_scheduled_end_time? || saved_change_to_closing_speed_lots? || saved_change_to_closing_speed_minutes?) end 中的另一个函数调用的代码:

MODEL.RB:

test "items_update_needed? NOT for a live auction UNLESS it was previous timed" do
  #  Timed auction NEEDS items update if starts_at changes
  @online_only.starts_at = 5.minutes.from_now
  assert @online_only.items_update_needed?
  @online_only.reload
end

TEST.RB:

Expected false to be truthy.

断言行失败,错误为:items_update_needed?

如果我在saved_changes_to_starts_at?中删除调试器,则false会返回false

如果我在断言之前放置了一个保存它仍然返回after_save这是有道理的,因为该函数已经通过true回调被调用。

所以我试图确定你如何实际测试这个方法并获得{{1}}的回报?

0 个答案:

没有答案