这是我的用户模型,我不知道如何为 active_and_approved_creative_count 缓存测试编写测试。
用户.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