Sha256: 674f133e18763fc62f8fe2c7a63c6a8a6870cf000a3cd83b02b8b9fe5291d431

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module MachineShop
  class MachineshopCache
    #require 'Rails'
    #require 'active_support/cache'
    require 'active_record'
    cache = ActiveSupport::Cache.lookup_cache(:memory_store)

    Rails.cache.class.class_eval do
      attr_accessor :enabled

      def read_with_enabled(*args, &block)
        enabled ? read_without_enabled( *args, &block) : nil
      end

      alias_method_chain :read, :enabled

    end

    if File.basename($0) == "rake" && ARGV.include?("db:migrate")
      Rails.cache.enabled = false

    else
      Rails.cache.enabled = true

    end
  end

  describe "Rails.cache" do
    it 'can be disabled and enabled' do
      Rails.cache.enabled = true
      Rails.cache.enabled.should be_true
      Rails.cache.write("foobar","foo")
      Rails.cache.read("foobar").should == "foo"

      Rails.cache.enabled = false
      Rails.cache.enabled.should be_false
      Rails.cache.write("foobar","foo")
      Rails.cache.read("foobar").shoule be_nil

      Rails.cache.enabled = true
      Rails.cache.read("foobar").should == "foo"


    end

  end


end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
machineshop-1.1.1 machineshop/lib/machineshop/machineshop_cache.rb
test_machine_shop-0.0.5 lib/machineshop/machineshop_cache.rb
machineshop-1.0.2 lib/machineshop/machineshop_cache.rb
test_machine_shop-0.0.4 lib/machineshop/machineshop_cache.rb
machineshop-1.0.0 lib/machineshop/machineshop_cache.rb
machineshop-0.0.4 lib/machineshop/machineshop_cache.rb
machineshop-0.0.3 lib/machineshop/machineshop_cache.rb
machineshop-0.0.2 machineshop/lib/machineshop/machineshop_cache.rb
machineshop-0.0.1 lib/machineshop/machineshop_cache.rb