caching - rails rspec testing cache method -
this user model , don't know how can write test 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) user.active_and_approved_creative.count end end ... scope :active_and_approved_creative ,where("user_type = ? , (membership_cancelled null or membership_cancelled = false)", :approved_creative) end
you probably:
- access
active_and_approved_creative_count
prime cache , verify initial value - perform action increment count
- use timecop move 29 minutes
- verify count still cached value
- travel minute or two
- verify count has incremented
one might argue testing rails internals unnecessarily, consider whether performing step #1 may enough.
Comments
Post a Comment