Sha256: 932b293aa85b789621cd3db9fe8a1fae851e5afa9b3aca393c9afa4a2d8f39ce

Contents?: true

Size: 1.63 KB

Versions: 73

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe "Caching" do
  before do
    class TestClass < ActiveFedora::Base
      property :title, predicate: ::RDF::Vocab::DC.title
    end
  end

  after { Object.send(:remove_const, :TestClass) }

  let!(:object) { TestClass.create(id: '123') }

  describe "#cache" do
    it "finds records in the cache" do
      expect_any_instance_of(Faraday::Connection).to receive(:get).once.and_call_original
      ActiveFedora::Base.cache do
        o1 = TestClass.find(object.id)
        o2 = TestClass.find(object.id)
        expect(o1.ldp_source.get.body.object_id).to eq o2.ldp_source.get.body.object_id
      end
    end

    it "clears the cache at the end of the block" do
      expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
      ActiveFedora::Base.cache do
        TestClass.find(object.id)
      end
      ActiveFedora::Base.cache do
        TestClass.find(object.id)
      end
    end

    context "an update" do
      it "flushes the cache" do
        expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
        ActiveFedora::Base.cache do
          TestClass.find(object.id)
          object.title = ['foo']
          object.save!
          TestClass.find(object.id)
        end
      end
    end
  end

  describe "#uncached" do
    it "does not use the cache" do
      expect_any_instance_of(Faraday::Connection).to receive(:get).twice.and_call_original
      ActiveFedora::Base.cache do
        TestClass.find(object.id)
        ActiveFedora::Base.uncached do
          TestClass.find(object.id)
        end
        TestClass.find(object.id)
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
active-fedora-12.2.4 spec/integration/caching_spec.rb
active-fedora-12.2.3 spec/integration/caching_spec.rb
active-fedora-11.5.6 spec/integration/caching_spec.rb
active-fedora-12.2.2 spec/integration/caching_spec.rb
active-fedora-11.2.1 spec/integration/caching_spec.rb
active-fedora-12.2.1 spec/integration/caching_spec.rb
active-fedora-12.0.3 spec/integration/caching_spec.rb
active-fedora-11.5.5 spec/integration/caching_spec.rb
active-fedora-13.1.2 spec/integration/caching_spec.rb
active-fedora-13.1.1 spec/integration/caching_spec.rb
active-fedora-13.1.0 spec/integration/caching_spec.rb
active-fedora-13.0.0 spec/integration/caching_spec.rb
active-fedora-12.1.1 spec/integration/caching_spec.rb
active-fedora-12.1.0 spec/integration/caching_spec.rb
active-fedora-11.5.4 spec/integration/caching_spec.rb
active-fedora-11.5.3 spec/integration/caching_spec.rb
active-fedora-12.0.2 spec/integration/caching_spec.rb
active-fedora-12.0.1 spec/integration/caching_spec.rb
active-fedora-11.5.2 spec/integration/caching_spec.rb
active-fedora-12.0.0 spec/integration/caching_spec.rb