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:

  1. access active_and_approved_creative_count prime cache , verify initial value
  2. perform action increment count
  3. use timecop move 29 minutes
  4. verify count still cached value
  5. travel minute or two
  6. verify count has incremented

one might argue testing rails internals unnecessarily, consider whether performing step #1 may enough.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -