Reputation: 5147
This is my user model and I don't know how can I write test for active_and_approved_creative_count cache test.
User.rb
class User < ActiveRecord::Base
class << self
def active_and_approved_creative_count
Rails.cache.fetch('active_and_approved_creative_count', :expires_in => 30.minutes) do
User.active_and_approved_creative.count
end
end
...
scope :active_and_approved_creative ,where("user_type = ? AND (membership_cancelled IS NULL OR membership_cancelled = false)", :approved_creative)
end
Upvotes: 1
Views: 1501
Reputation: 17647
You could probably:
active_and_approved_creative_count
to prime the cache and verify the initial valueOne might argue that this is testing the Rails internals unnecessarily, consider whether simply performing step #1 may be enough.
Upvotes: 1