Sha256: d41e2016b70baa090092139a16d211573e10c20e3f3f8c41491375143cebaad4

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe InfoparkComponentCache::Guards::LastChanged do
  let(:cache_component_stub) do
    double.tap do |cache_component_stub|
      cache_component_stub.stub(:cache_key) do |input|
        input.inspect
      end
    end
  end

  let(:maximum_last_changed) { 10.minutes.ago.to_iso }

  let(:obj_stub) do
    double.tap do |obj_stub|
      obj_stub.stub(:scoped).and_return(obj_stub)
      obj_stub.stub(:where).and_return(obj_stub)
      obj_stub.stub(:maximum) do |field|
        maximum_last_changed if field == :last_changed
      end
    end
  end

  before { InfoparkComponentCache::CmsStateGuard.obj_root_class = obj_stub }

  subject { described_class.new(cache_component_stub) }

  context "with cache disabled" do
    disable_cache

    context "without a call to guard!" do
      it { is_expected.not_to be_consistent }
    end

    context "with a call to guard!" do
      before { subject.guard! }
      it { is_expected.not_to be_consistent }
    end
  end

  context "with cache enabled" do
    enable_cache
    before { Rails.cache.clear }

    context "without a call to guard!" do
      it { is_expected.not_to be_consistent }
    end

    context "with a call to guard!" do
      before { subject.guard! }
      it { is_expected.to be_consistent }
    end

    context "after maximum last change changes" do
      before { subject.guard! } 
      before { obj_stub.stub(:maximum).and_return(Time.now.to_iso) }
      it { is_expected.not_to be_consistent }
    end

    context "after maximum last change changes to a past date" do
      before { subject.guard! } 
      before { obj_stub.stub(:maximum).and_return(1.month.ago.to_iso) }
      it { is_expected.to be_consistent }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
infopark_component_cache-3.2.0 spec/lib/guards/last_changed_spec.rb
infopark_component_cache-3.1.1 spec/lib/guards/last_changed_spec.rb
infopark_component_cache-3.1.0 spec/lib/guards/last_changed_spec.rb
infopark_component_cache-3.0.0 spec/lib/guards/last_changed_spec.rb
infopark_component_cache-2.0.0 spec/lib/guards/last_changed_spec.rb