Sha256: 1c2c014a0f319b51645a8c843706a5374102aa95f8d35cc8be152d9c155c6e1e

Contents?: true

Size: 1.22 KB

Versions: 105

Compression:

Stored size: 1.22 KB

Contents

module Spree
  module TestingSupport
    module Caching
      def cache_writes
        @cache_write_events
      end

      def assert_written_to_cache(key)
        unless @cache_write_events.detect { |event| event[:key].starts_with?(key) }
          fail %Q{Expected to find #{key} in the cache, but didn't.

  Cache writes:
  #{@cache_write_events.join("\n")}
          }
        end
      end

      def clear_cache_events
        @cache_read_events = []
        @cache_write_events = []
      end
    end
  end
end

RSpec.configure do |config|
  config.include Spree::TestingSupport::Caching, :caching => true

  config.before(:each, :caching => true) do
    ActionController::Base.perform_caching = true

    ActiveSupport::Notifications.subscribe("read_fragment.action_controller") do |event, start_time, finish_time, _, details|
      @cache_read_events ||= []
      @cache_read_events << details 
    end

    ActiveSupport::Notifications.subscribe("write_fragment.action_controller") do |event, start_time, finish_time, _, details|
      @cache_write_events ||= []
      @cache_write_events << details
    end
  end

  config.after(:each, :caching => true) do
    ActionController::Base.perform_caching = false
    Rails.cache.clear
  end
end

Version data entries

105 entries across 105 versions & 2 rubygems

Version Path
solidus_core-1.0.3 lib/spree/testing_support/caching.rb
solidus_core-1.1.1 lib/spree/testing_support/caching.rb
solidus_core-1.1.0 lib/spree/testing_support/caching.rb
solidus_core-1.1.0.pre2 lib/spree/testing_support/caching.rb
solidus_core-1.1.0.pre1 lib/spree/testing_support/caching.rb
solidus_core-1.1.0.beta1 lib/spree/testing_support/caching.rb
solidus_core-1.0.2 lib/spree/testing_support/caching.rb
spree_core-3.0.4 lib/spree/testing_support/caching.rb
spree_core-2.4.10 lib/spree/testing_support/caching.rb
spree_core-2.3.13 lib/spree/testing_support/caching.rb
solidus_core-1.0.1 lib/spree/testing_support/caching.rb
spree_core-2.2.14 lib/spree/testing_support/caching.rb
solidus_core-1.0.0 lib/spree/testing_support/caching.rb
solidus_core-1.0.0.rc2 lib/spree/testing_support/caching.rb
solidus_core-1.0.0.rc1 lib/spree/testing_support/caching.rb
spree_core-3.0.3 lib/spree/testing_support/caching.rb
spree_core-2.4.9 lib/spree/testing_support/caching.rb
spree_core-2.3.12 lib/spree/testing_support/caching.rb
spree_core-2.2.13 lib/spree/testing_support/caching.rb
solidus_core-1.0.0.pre3 lib/spree/testing_support/caching.rb