Sha256: f26cbcebf263662c8c68cc6163899bc0715bdfad8f9c0fe2dd15e79bb45d7feb

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

require "spec_helper"

describe InfoparkComponentCache::Guards::ValidUntil do
  subject(:guard) { described_class.new(cache_component_stub) }

  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(:minimum_valid_until) { 10.minutes.since }

  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(:minimum) do |field|
        minimum_valid_until if field == :valid_until
      end
    end
  end

  before { InfoparkComponentCache::CmsStateGuard.obj_root_class = obj_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 { guard.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 { guard.guard! }

      it { is_expected.to be_consistent }
    end

    context "when after minimum valid until changes to a present date" do
      before do
        guard.guard!
        obj_stub.stub(:minimum).and_return(Time.now.to_iso)
      end

      it { is_expected.not_to be_consistent }
    end

    context "when after minimum valid until changes to a past date" do
      before do
        guard.guard!
        obj_stub.stub(:minimum).and_return(1.month.ago.to_iso)
      end

      it { is_expected.not_to be_consistent }
    end

    context "when nil valid until" do
      let(:minimum_valid_until) { nil }

      before { guard.guard! }

      it { is_expected.to be_consistent }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infopark_component_cache-5.0.2 spec/lib/infopark_component_cache/guards/valid_until_spec.rb
infopark_component_cache-5.0.1 spec/lib/infopark_component_cache/guards/valid_until_spec.rb
infopark_component_cache-4.2.0 spec/lib/infopark_component_cache/guards/valid_until_spec.rb
infopark_component_cache-4.1.0 spec/lib/infopark_component_cache/guards/valid_until_spec.rb
infopark_component_cache-4.0.1 spec/lib/infopark_component_cache/guards/valid_until_spec.rb
infopark_component_cache-4.0.0 spec/lib/infopark_component_cache/guards/valid_until_spec.rb