Sha256: 5e9a8796f4c9a16a4242d41d2dbad03ad729fbe25d670be1c74a8125fdd22356

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

require "spec_helper"

describe InfoparkComponentCache::Guards::ValidFrom 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_from) { 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_from if field == :valid_from
      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 from 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 from 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
  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_from_spec.rb
infopark_component_cache-5.0.1 spec/lib/infopark_component_cache/guards/valid_from_spec.rb
infopark_component_cache-4.2.0 spec/lib/infopark_component_cache/guards/valid_from_spec.rb
infopark_component_cache-4.1.0 spec/lib/infopark_component_cache/guards/valid_from_spec.rb
infopark_component_cache-4.0.1 spec/lib/infopark_component_cache/guards/valid_from_spec.rb
infopark_component_cache-4.0.0 spec/lib/infopark_component_cache/guards/valid_from_spec.rb