lacquer 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,30 +1,36 @@
1
1
  = lacquer
2
2
 
3
- Rails drop in for Varnish support.
3
+ Rails drop in for Varnish support. This version is adapted from Russ Smith's gem and is in production use on posterous.com.
4
4
 
5
5
  == Install
6
6
  Basic installation
7
7
 
8
- rails generate lacquer install
8
+ sudo gem install posterous-lacquer
9
9
 
10
10
  config/initializers/lacquer.rb
11
11
 
12
12
  Lacquer.configure do |config|
13
13
  # Globally enable/disable cache
14
14
  config.enable_cache = true
15
-
15
+
16
16
  # Unless overridden in a controller or action, the default will be used
17
17
  config.default_ttl = 1.week
18
-
18
+
19
19
  # Can be :none, :delayed_job, :resque
20
20
  config.job_backend = :none
21
-
21
+
22
22
  # Array of Varnish servers to manage
23
23
  config.varnish_servers << {
24
24
  :host => '0.0.0.0', :port => 6082
25
25
  }
26
+
27
+ # Number of retries
28
+ config.retries = 5
29
+
30
+ # config handler (optional, if you use Hoptoad or another error tracking service)
31
+ config.command_error_handler = lambda {|s| HoptoadNotifier.notify(s) }
26
32
  end
27
-
33
+
28
34
  app/controllers/application_controller.rb
29
35
 
30
36
  class ApplicationController < ActionController::Base
@@ -32,12 +38,40 @@ app/controllers/application_controller.rb
32
38
  end
33
39
 
34
40
  == Usage
41
+
35
42
  To set a custom ttl for a controller:
36
43
 
37
44
  before_filter { |controller| controller.set_cache_ttl(15.minutes) }
38
45
 
46
+ Clearing the cache:
47
+
48
+ class Posts < ApplicationController
49
+ after_filter :clear_cache, :only => [ :create, :update, :destroy ]
50
+
51
+ private
52
+
53
+ def clear_cache
54
+ clear_cache_for(
55
+ root_path,
56
+ posts_path,
57
+ post_path(@post))
58
+ end
59
+ end
60
+
61
+ == Gotchas
62
+
63
+ The default TTL for most actions is set to 0, since for most cases you'll probably want to be fairly explicit about what pages do get cached by varnish. The default cache header is typically
64
+
65
+ Cache-Control: max-age=0, no-cache, private
66
+
67
+ This is good for normal controller actions, since you won't want to cache them. If TTL for an action is set to 0, it won't mess with the default header.
68
+
69
+ The key gotcha here is that cached pages strip cookies, so if your application relies on sessions and uses authenticity tokens, the user will need a session cookie set before form actions will work. Setting default TTL to 0 here will make sure these session cookies won't break.
70
+
71
+ As a result, all you have to do to set a cacheable action is the before filter above.
72
+
39
73
  == Note on Patches/Pull Requests
40
-
74
+
41
75
  * Fork the project.
42
76
  * Make your feature addition or bug fix.
43
77
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "russ@bashme.org"
11
11
  gem.homepage = "http://github.com/russ/lacquer"
12
12
  gem.authors = ["Russ Smith"]
13
+ gem.add_development_dependency "rspec", ">= 1.3.0"
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
@@ -17,36 +18,28 @@ rescue LoadError
17
18
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
19
  end
19
20
 
20
- require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/test_*.rb'
24
- test.verbose = true
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
25
  end
26
26
 
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
38
31
  end
39
32
 
40
- task :test => :check_dependencies
33
+ task :spec => :check_dependencies
41
34
 
42
- task :default => :test
35
+ task :default => :spec
43
36
 
44
37
  require 'rake/rdoctask'
45
38
  Rake::RDocTask.new do |rdoc|
46
39
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
40
 
48
41
  rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "lacquer #{version}"
42
+ rdoc.title = "testing #{version}"
50
43
  rdoc.rdoc_files.include('README*')
51
44
  rdoc.rdoc_files.include('lib/**/*.rb')
52
45
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
data/lacquer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lacquer}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Russ Smith"]
12
- s.date = %q{2010-06-15}
12
+ s.date = %q{2010-09-14}
13
13
  s.description = %q{Rails drop in for Varnish support.}
14
14
  s.email = %q{russ@bashme.org}
15
15
  s.extra_rdoc_files = [
@@ -36,29 +36,33 @@ Gem::Specification.new do |s|
36
36
  "lib/lacquer/resque_job.rb",
37
37
  "lib/lacquer/varnish.rb",
38
38
  "rails/init.rb",
39
- "test/helper.rb",
40
- "test/test_cache_utils.rb",
41
- "test/test_varnish_interface.rb"
39
+ "spec/lacquer/cache_utils_spec.rb",
40
+ "spec/lacquer/varnish_spec.rb",
41
+ "spec/spec.opts",
42
+ "spec/spec_helper.rb"
42
43
  ]
43
44
  s.homepage = %q{http://github.com/russ/lacquer}
44
45
  s.rdoc_options = ["--charset=UTF-8"]
45
46
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.3.6}
47
+ s.rubygems_version = %q{1.3.7}
47
48
  s.summary = %q{Rails drop in for Varnish support.}
48
49
  s.test_files = [
49
- "test/helper.rb",
50
- "test/test_cache_utils.rb",
51
- "test/test_varnish_interface.rb"
50
+ "spec/lacquer/cache_utils_spec.rb",
51
+ "spec/lacquer/varnish_spec.rb",
52
+ "spec/spec_helper.rb"
52
53
  ]
53
54
 
54
55
  if s.respond_to? :specification_version then
55
56
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
57
  s.specification_version = 3
57
58
 
58
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
59
61
  else
62
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
60
63
  end
61
64
  else
65
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
62
66
  end
63
67
  end
64
68
 
@@ -42,8 +42,8 @@ module Lacquer
42
42
  # These are the headers that varnish responds to
43
43
  # to set cache properly.
44
44
  def send_cache_control_headers
45
- if Lacquer.configuration.enable_cache
46
- expires_in(@cache_ttl, :public => true)
45
+ if Lacquer.configuration.enable_cache && @cache_ttl && @cache_ttl != 0
46
+ expires_in(@cache_ttl, :public => true, :private => false)
47
47
  end
48
48
  end
49
49
  end
@@ -11,14 +11,22 @@ module Lacquer
11
11
  # Application default ttl
12
12
  attr_accessor :default_ttl
13
13
 
14
+ # Application default ttl
15
+ attr_accessor :retries
16
+
14
17
  # Job Backend
15
18
  attr_accessor :job_backend
16
19
 
20
+ # Error handler
21
+ attr_accessor :command_error_handler
22
+
17
23
  def initialize
18
24
  @enable_cache = true
19
25
  @varnish_servers = []
20
- @default_ttl = 1.week
26
+ @default_ttl = 0
21
27
  @job_backend = :none
28
+ @retries = 5
29
+ @command_error_handler = nil
22
30
  end
23
31
 
24
32
  # Returns a hash of all configurable options
@@ -1,35 +1,51 @@
1
1
  module Lacquer
2
2
  class Varnish
3
3
  def stats
4
- stats = send_command('stats').split("\n")
5
- stats.shift
6
-
7
- stats = stats.collect do |stat|
8
- stat = stat.strip.match(/(\d+)\s+(.+)$/)
9
- { :key => stat[2], :value => stat[1] }
4
+ send_command('stats').collect do |stats|
5
+ stats = stats.split("\n")
6
+ stats.shift
7
+ stats = stats.collect do |stat|
8
+ stat = stat.strip.match(/(\d+)\s+(.+)$/)
9
+ { :key => stat[2], :value => stat[1] } if stat
10
+ end
10
11
  end
11
12
  end
12
13
 
13
14
  def purge(path)
14
- (send_command('url.purge ' << path) == '200 0') ? true : false
15
+ send_command('url.purge ' << path).all? do |result|
16
+ result =~ /200/
17
+ end
15
18
  end
16
19
 
17
- private
18
-
19
20
  # Sends commands over telnet to varnish servers listed in the config.
20
21
  def send_command(command)
21
- Lacquer.configuration.varnish_servers.each do |server|
22
+ Lacquer.configuration.varnish_servers.collect do |server|
23
+ retries = 0
24
+ response = nil
22
25
  begin
26
+ retries += 1
23
27
  connection = Net::Telnet.new(
24
28
  'Host' => server[:host],
25
29
  'Port' => server[:port],
26
30
  'Timeout' => server[:timeout] || 5)
27
- connection.cmd(command) do |c|
28
- return c.strip
29
- end
31
+ connection.cmd(command + "\nquit\n") {|r| response = r.strip}
32
+ connection.close
30
33
  rescue Exception => e
31
- raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
34
+ if retries < Lacquer.configuration.retries
35
+ retry
36
+ else
37
+ if Lacquer.configuration.command_error_handler
38
+ Lacquer.configuration.command_error_handler.call({
39
+ :error_class => "Varnish Error, retried #{Lacquer.configuration.retries} times",
40
+ :error_message => "Error while trying to connect to #{server[:host]}:#{server[:port]}: #{e}",
41
+ :parameters => server,
42
+ :response => response })
43
+ else
44
+ raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
45
+ end
46
+ end
32
47
  end
48
+ response
33
49
  end
34
50
  end
35
51
  end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Lacquer" do
4
+ before(:each) do
5
+ @controller = ControllerClass.new
6
+ end
7
+
8
+ describe "talking to varnish" do
9
+ before(:each) do
10
+ @varnish_stub = mock('varnish')
11
+ Lacquer::Varnish.stub!(:new).and_return(@varnish_stub)
12
+ end
13
+
14
+ describe "when backend is :none" do
15
+ it "sends commands to varnish instantly" do
16
+ Lacquer.configuration.job_backend = :none
17
+
18
+ @varnish_stub.should_receive(:purge).twice
19
+ @controller.clear_cache_for('/', '/blog/posts')
20
+ end
21
+ end
22
+
23
+ describe "when backend is :delayed_job" do
24
+ it "sends commands to a delayed_job queue" do
25
+ Lacquer.configuration.job_backend = :delayed_job
26
+
27
+ Delayed::Job.should_receive(:enqueue).twice
28
+ @controller.clear_cache_for('/', '/blog/posts')
29
+ end
30
+ end
31
+
32
+ describe "when backend is :resque" do
33
+ it "sends commands to a resque queue" do
34
+ Lacquer.configuration.job_backend = :resque
35
+
36
+ Resque.should_receive(:enqueue).twice
37
+ @controller.clear_cache_for('/', '/blog/posts')
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "when cache is enabled" do
43
+ describe "when no custom ttl is set" do
44
+ it "should send cache control headers based on default ttl" do
45
+ Lacquer.configuration.enable_cache = true
46
+ Lacquer.configuration.default_ttl = 1.week
47
+
48
+ @controller.set_default_cache_ttl
49
+ @controller.should_receive(:expires_in).with(1.week, :public => true)
50
+ @controller.send_cache_control_headers
51
+ end
52
+ end
53
+
54
+ describe "when custom ttl is set" do
55
+ it "should send cache control headers based on custom set ttl" do
56
+ Lacquer.configuration.enable_cache = true
57
+
58
+ @controller.set_cache_ttl(10.week)
59
+ @controller.should_receive(:expires_in).with(10.week, :public => true)
60
+ @controller.send_cache_control_headers
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
2
+
3
+ describe "Varnish" do
4
+ before(:each) do
5
+ @telnet_mock = mock('Net::Telnet')
6
+ Net::Telnet.stub!(:new).and_return(@telnet_mock)
7
+ @telnet_mock.stub!(:close)
8
+ @telnet_mock.stub!(:cmd)
9
+ @telnet_mock.stub!(:puts)
10
+ @telnet_mock.stub!(:waitfor)
11
+ Lacquer.configuration.retries.should == 5
12
+ end
13
+
14
+ describe "with any command" do
15
+ describe "when connection is unsuccessful" do
16
+ it "should raise a Lacquer::VarnishError" do
17
+ @telnet_mock.stub!(:cmd).and_raise(Timeout::Error)
18
+ lambda {
19
+ Lacquer::Varnish.new.purge('/')
20
+ }.should raise_error(Lacquer::VarnishError)
21
+ end
22
+
23
+ it "should retry on failure before erroring" do
24
+ @telnet_mock.stub!(:cmd).and_raise(Timeout::Error)
25
+ Net::Telnet.should_receive(:new).exactly(5).times
26
+ lambda {
27
+ Lacquer::Varnish.new.purge('/')
28
+ }.should raise_error(Lacquer::VarnishError)
29
+ end
30
+
31
+ it "should close the connection afterwards" do
32
+ @telnet_mock.should_receive(:close).exactly(1).times
33
+ Lacquer::Varnish.new.purge('/')
34
+ end
35
+ end
36
+
37
+ describe "when connection is unsuccessful and an error handler is set" do
38
+ before(:each) do
39
+ Lacquer.configuration.command_error_handler = mock("command_error_handler")
40
+ end
41
+ it "should call handler on error" do
42
+ @telnet_mock.stub!(:cmd).and_raise(Timeout::Error)
43
+ Lacquer.configuration.command_error_handler.should_receive(:call).exactly(1).times
44
+ lambda {
45
+ Lacquer::Varnish.new.purge('/')
46
+ }.should_not raise_error(Lacquer::VarnishError)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "when sending a stats command" do
52
+ it "should return an array of stats" do
53
+ @telnet_mock.stub!(:cmd).and_yield(%Q[
54
+ 200 2023
55
+ 6263596 Client connections accepted
56
+ 6260911 Client requests received
57
+ 919605 Cache hits for pass
58
+ 2123848 Cache misses
59
+ 6723161 Backend conn. success
60
+ 6641493 Fetch with Length
61
+ 81512 Fetch wanted close
62
+ 11 Fetch failed
63
+ 1648 N struct sess_mem
64
+ 81 N struct sess
65
+ 22781 N struct object
66
+ 23040 N struct objectcore
67
+ 36047 N struct objecthead
68
+ 56108 N struct smf
69
+ 1646 N small free smf
70
+ 263 N large free smf
71
+ 55 N struct vbe_conn
72
+ 804 N worker threads
73
+ 1583 N worker threads created
74
+ 2114 N worker threads limited
75
+ 1609 N overflowed work requests
76
+ 1 N backends
77
+ 1693663 N expired objects
78
+ 400637 N LRU nuked objects
79
+ 10 N LRU moved objects
80
+ 254 HTTP header overflows
81
+ 2506470 Objects sent with write
82
+ 6263541 Total Sessions
83
+ 6260911 Total Requests
84
+ 40 Total pipe
85
+ 4599215 Total pass
86
+ 6722994 Total fetch
87
+ 2607029095 Total header bytes
88
+ 55280196533 Total body bytes
89
+ 6263536 Session Closed
90
+ 5 Session herd
91
+ 511352337 SHM records
92
+ 33376035 SHM writes
93
+ 33177 SHM flushes due to overflow
94
+ 208858 SHM MTX contention
95
+ 246 SHM cycles through buffer
96
+ 6361382 allocator requests
97
+ 54199 outstanding allocations
98
+ 953389056 bytes allocated
99
+ 120352768 bytes free
100
+ 323 SMS allocator requests
101
+ 151528 SMS bytes allocated
102
+ 151528 SMS bytes freed
103
+ 6723053 Backend requests made
104
+ 1 N vcl total
105
+ 1 N vcl available
106
+ 49 N total active purges
107
+ 197 N new purges added
108
+ 148 N old purges deleted
109
+ 6117 N objects tested
110
+ 60375 N regexps tested against
111
+ 140 N duplicate purges removed
112
+ 944407 HCB Lookups without lock
113
+ 3 HCB Lookups with lock
114
+ 2099076 HCB Inserts
115
+ 515351 Objects ESI parsed (unlock)
116
+ 35371 Client uptime
117
+
118
+ 500 22
119
+ Closing CLI connection
120
+ ].strip)
121
+ stats = Lacquer::Varnish.new.stats
122
+ stats.size.should be(1)
123
+ end
124
+ end
125
+
126
+ describe "when sending a purge command" do
127
+ it "should return successfully" do
128
+ @telnet_mock.stub!(:cmd).and_yield('200')
129
+ Lacquer::Varnish.new.purge('/').should be(true)
130
+ end
131
+ end
132
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,11 +1,9 @@
1
- require 'rubygems'
2
- require 'active_support'
3
- require 'test/unit'
4
- require 'shoulda'
5
-
6
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
8
4
  require 'lacquer'
5
+ require 'spec'
6
+ require 'spec/autorun'
9
7
 
10
8
  class ControllerClass
11
9
  def self.before_filter(arg); end
@@ -20,5 +18,12 @@ end
20
18
 
21
19
  module Resque; end
22
20
 
23
- class ActiveSupport::TestCase
21
+ Lacquer.configure do |config|
22
+ config.enable_cache = true
23
+ config.default_ttl = 1.week
24
+ config.job_backend = :none
25
+ config.varnish_servers << { :host => '0.0.0.0', :port => 6082 }
26
+ end
27
+
28
+ Spec::Runner.configure do |config|
24
29
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacquer
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 2
8
8
  - 3
9
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Russ Smith
@@ -14,10 +15,25 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-15 00:00:00 -07:00
18
+ date: 2010-09-14 00:00:00 -07:00
18
19
  default_executable:
19
- dependencies: []
20
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 1
32
+ - 3
33
+ - 0
34
+ version: 1.3.0
35
+ type: :development
36
+ version_requirements: *id001
21
37
  description: Rails drop in for Varnish support.
22
38
  email: russ@bashme.org
23
39
  executables: []
@@ -47,9 +63,10 @@ files:
47
63
  - lib/lacquer/resque_job.rb
48
64
  - lib/lacquer/varnish.rb
49
65
  - rails/init.rb
50
- - test/helper.rb
51
- - test/test_cache_utils.rb
52
- - test/test_varnish_interface.rb
66
+ - spec/lacquer/cache_utils_spec.rb
67
+ - spec/lacquer/varnish_spec.rb
68
+ - spec/spec.opts
69
+ - spec/spec_helper.rb
53
70
  has_rdoc: true
54
71
  homepage: http://github.com/russ/lacquer
55
72
  licenses: []
@@ -60,27 +77,31 @@ rdoc_options:
60
77
  require_paths:
61
78
  - lib
62
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
63
81
  requirements:
64
82
  - - ">="
65
83
  - !ruby/object:Gem::Version
84
+ hash: 3
66
85
  segments:
67
86
  - 0
68
87
  version: "0"
69
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
70
90
  requirements:
71
91
  - - ">="
72
92
  - !ruby/object:Gem::Version
93
+ hash: 3
73
94
  segments:
74
95
  - 0
75
96
  version: "0"
76
97
  requirements: []
77
98
 
78
99
  rubyforge_project:
79
- rubygems_version: 1.3.6
100
+ rubygems_version: 1.3.7
80
101
  signing_key:
81
102
  specification_version: 3
82
103
  summary: Rails drop in for Varnish support.
83
104
  test_files:
84
- - test/helper.rb
85
- - test/test_cache_utils.rb
86
- - test/test_varnish_interface.rb
105
+ - spec/lacquer/cache_utils_spec.rb
106
+ - spec/lacquer/varnish_spec.rb
107
+ - spec/spec_helper.rb
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLacquer < ActiveSupport::TestCase
4
- setup do
5
- @controller = ControllerClass.new
6
- end
7
-
8
- context "when job backend is :none" do
9
- should "take paths to clear cache for" do
10
- varnish_stub = mock('Varnish')
11
- Lacquer::Varnish.stubs('new').returns(varnish_stub)
12
- varnish_stub.expects(:purge).twice
13
- Lacquer.configuration.job_backend = :none
14
- @controller.clear_cache_for('/', '/blog/posts')
15
- end
16
- end
17
-
18
- context "when job backend is :delayed_job" do
19
- should "take paths to clear cache for" do
20
- Lacquer.configuration.job_backend = :delayed_job
21
- Delayed::Job.expects(:enqueue).twice
22
- @controller.clear_cache_for('/', '/blog/posts')
23
- end
24
- end
25
-
26
- context "when job backend is :resque" do
27
- should "take paths to clear cache for" do
28
- Lacquer.configuration.job_backend = :resque
29
- Resque.expects(:enqueue).twice
30
- @controller.clear_cache_for('/', '/blog/posts')
31
- end
32
- end
33
-
34
- context "when cache is enabled" do
35
- should "send cache control headers based on ttl" do
36
- Lacquer.configuration.enable_cache = true
37
- @controller.set_cache_ttl(10.week)
38
- @controller.expects(:expires_in).with(10.week, :public => true)
39
- @controller.send_cache_control_headers
40
- end
41
- end
42
-
43
- context "when cache is disabled" do
44
- should "do not send cache control headers" do
45
- Lacquer.configuration.enable_cache = false
46
- @controller.expects(:expires_in).never
47
- @controller.send_cache_control_headers
48
- end
49
- end
50
- end
@@ -1,30 +0,0 @@
1
- require 'helper'
2
-
3
- class TestLacquer < ActiveSupport::TestCase
4
- setup do
5
- Lacquer.configure do |config|
6
- config.varnish_servers << { :host => '0.0.0.0', :port => 6082 }
7
- end
8
-
9
- @telnet_mock = mock('Net::Telnet')
10
- @telnet_mock.stubs(:cmd)
11
-
12
- @controller = ControllerClass.new
13
- end
14
-
15
- context "when connection is succesful" do
16
- should "send command to varnish server" do
17
- Net::Telnet.stubs(:new).returns(@telnet_mock)
18
- Lacquer::Varnish.new.purge('/')
19
- end
20
- end
21
-
22
- context "when connection is unsuccesful" do
23
- should "raise timeout exception" do
24
- Net::Telnet.stubs(:new).raises(Timeout::Error)
25
- assert_raise Lacquer::VarnishError do
26
- Lacquer::Varnish.new.purge('/')
27
- end
28
- end
29
- end
30
- end