Sha256: 46f8941e37fcc6779caf5b42c358660f4cc25dba71690c3d5cce87d229d7abf6

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')

describe "Lacquer" do
  before(:each) do
    @controller = ControllerClass.new
  end

  describe "talking to varnish" do
    before(:each) do
      @varnish_stub = mock('varnish')
      Lacquer::Varnish.stub!(:new).and_return(@varnish_stub)
    end

    describe "when backend is :none" do
      it "sends commands to varnish instantly" do
        Lacquer.configuration.job_backend = :none

        @varnish_stub.should_receive(:purge).twice
        @controller.clear_cache_for('/', '/blog/posts')
      end
    end

    describe "when backend is :delayed_job" do
      it "sends commands to a delayed_job queue" do
        Lacquer.configuration.job_backend = :delayed_job

        Delayed::Job.should_receive(:enqueue).twice
        @controller.clear_cache_for('/', '/blog/posts')
      end
    end

    describe "when backend is :resque" do
      it "sends commands to a resque queue" do
        Lacquer.configuration.job_backend = :resque

        Resque.should_receive(:enqueue).twice
        @controller.clear_cache_for('/', '/blog/posts')
      end
    end
  end

  describe "when cache is enabled" do
    describe "when no custom ttl is set" do
      it "should send cache control headers based on default ttl" do
        Lacquer.configuration.enable_cache = true
        Lacquer.configuration.default_ttl = 1.week

        @controller.set_default_cache_ttl
        @controller.should_receive(:expires_in).with(1.week, :public => true)
        @controller.send_cache_control_headers
      end
    end

    describe "when custom ttl is set" do
      it "should send cache control headers based on custom set ttl" do
        Lacquer.configuration.enable_cache = true

        @controller.set_cache_ttl(10.week)
        @controller.should_receive(:expires_in).with(10.week, :public => true)
        @controller.send_cache_control_headers
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
lacquer-0.3.0 spec/lacquer/cache_utils_spec.rb
posterous-lacquer-0.2.5 spec/lacquer/cache_utils_spec.rb
posterous-lacquer-0.2.4 spec/lacquer/cache_utils_spec.rb
posterous-lacquer-0.2.3 spec/lacquer/cache_utils_spec.rb