문제

I'm curious if i can mock out somehow the testing of a counter cache. Now I'm creating all the records to test the counter_cache. Is there any good practices to test counter cache effectively?

Edit: I'm just interested in testing that, the counter cache exists on a certain association.

도움이 되었습니까?

해결책

When you add the :counter_cache option, ActiveRecord defines 2 callbacks (source code). You can use Mocha to check if the callback is executed.

instance.expects(:belongs_to_counter_cache_after_create_for_MODELNAME).returns(true)

다른 팁

Add an entry, reload your object with counter_cache and check if it's increment.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top