3

编写具有 counter_cache 列的夹具既繁琐又复杂,我尝试在 test_helper.rb 中使用方法 reset_counters 但它不起作用。同样的方式让它工作?

4

1 回答 1

2

我使用猴子路径在测试环境中禁用 counter_cache 解决了这个问题。

配置/环境/test.rb

module ActiveRecord::Associations
    class HasManyAssociation
        def has_cached_counter?(reflection = reflection())
            false
        end
    end
end
于 2015-02-19T17:10:04.700 回答