Sha256: f017d863afcd7ed70c3356f9954f7fc83ff78f3dc20b1a3844a3ad15036d7fe8

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe "Caching" do
  before do
    class TestClass < ActiveFedora::Base
      property :title, predicate: ::RDF::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

2 entries across 2 versions & 1 rubygems

Version Path
active-fedora-9.6.2 spec/integration/caching_spec.rb
active-fedora-9.6.1 spec/integration/caching_spec.rb