merb-cache 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ GEM_EMAIL = "ben@benburkert.com"
17
17
 
18
18
  GEM_NAME = "merb-cache"
19
19
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.8") + PKG_BUILD
20
+ GEM_VERSION = (Merb::VERSION rescue "0.9.9") + PKG_BUILD
21
21
 
22
22
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
23
 
@@ -35,7 +35,7 @@ spec = Gem::Specification.new do |s|
35
35
  s.author = GEM_AUTHOR
36
36
  s.email = GEM_EMAIL
37
37
  s.homepage = PROJECT_URL
38
- s.add_dependency('merb-core', '>= 0.9.8')
38
+ s.add_dependency('merb-core', '>= 0.9.9')
39
39
  s.require_path = 'lib'
40
40
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
41
41
  end
@@ -100,4 +100,4 @@ namespace :memcached do
100
100
  system("kill -9 #{process.to_i}") rescue nil
101
101
  end
102
102
  end
103
- end
103
+ end
@@ -4,6 +4,7 @@ if defined?(Merb::Plugins)
4
4
  require "merb-cache" / "core_ext" / "enumerable"
5
5
  require "merb-cache" / "core_ext" / "hash"
6
6
  require "merb-cache" / "merb_ext" / "controller"
7
+ require "merb-cache" / "cache_request"
7
8
 
8
9
  class Merb::Controller
9
10
  include Merb::Cache::CacheMixin
@@ -7,7 +7,13 @@ module Merb
7
7
  module Cache
8
8
 
9
9
  def self.setup(&blk)
10
- instance_eval(&blk) unless blk.nil?
10
+ if Merb::BootLoader.finished?(Merb::BootLoader::BeforeAppLoads)
11
+ instance_eval(&blk) unless blk.nil?
12
+ else
13
+ Merb::BootLoader.before_app_loads do
14
+ instance_eval(&blk) unless blk.nil?
15
+ end
16
+ end
11
17
  end
12
18
 
13
19
  # autoload is used so that gem dependencies can be required only when needed by
@@ -0,0 +1,38 @@
1
+ module Merb
2
+ module Cache
3
+ class CacheRequest < Merb::Request
4
+
5
+ attr_accessor :path, :params
6
+
7
+ def initialize(path, params = {}, env = {})
8
+ super(DEFAULT_ENV.merge(env))
9
+
10
+ @path, @params = path, params
11
+ end
12
+
13
+ DEFAULT_ENV = Mash.new({
14
+ 'SERVER_NAME' => 'localhost',
15
+ 'PATH_INFO' => '/',
16
+ 'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
17
+ 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0',
18
+ 'SCRIPT_NAME' => '/',
19
+ 'SERVER_PROTOCOL' => 'HTTP/1.1',
20
+ 'HTTP_CACHE_CONTROL' => 'max-age=0',
21
+ 'HTTP_ACCEPT_LANGUAGE' => 'en,ja;q=0.9,fr;q=0.9,de;q=0.8,es;q=0.7,it;q=0.7,nl;q=0.6,sv;q=0.5,nb;q=0.5,da;q=0.4,fi;q=0.3,pt;q=0.3,zh-Hans;q=0.2,zh-Hant;q=0.1,ko;q=0.1',
22
+ 'HTTP_HOST' => 'localhost',
23
+ 'REMOTE_ADDR' => '127.0.0.1',
24
+ 'SERVER_SOFTWARE' => 'Mongrel 1.1',
25
+ 'HTTP_KEEP_ALIVE' => '300',
26
+ 'HTTP_REFERER' => 'http://localhost/',
27
+ 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
28
+ 'HTTP_VERSION' => 'HTTP/1.1',
29
+ 'REQUEST_URI' => '/',
30
+ 'SERVER_PORT' => '80',
31
+ 'GATEWAY_INTERFACE' => 'CGI/1.2',
32
+ 'HTTP_ACCEPT' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
33
+ 'HTTP_CONNECTION' => 'keep-alive',
34
+ 'REQUEST_METHOD' => 'GET'
35
+ }) unless defined?(DEFAULT_ENV)
36
+ end
37
+ end
38
+ end
@@ -37,16 +37,41 @@ module Merb::Cache::CacheMixin
37
37
  alias_method "_eager_cache_#{trigger_action}_to_#{target_controller.name.snake_case}__#{target_action}_after", :_eager_cache_after
38
38
  end
39
39
 
40
- def eager_dispatch(action, env = {}, blk = nil)
41
- kontroller = new(Merb::Request.new(env))
42
- kontroller.force_cache!
40
+ def eager_dispatch(action, params = {}, env = {}, blk = nil)
41
+ kontroller = if blk.nil?
42
+ new(Merb::Request.new(env))
43
+ else
44
+ result = case blk.arity
45
+ when 0 then blk[]
46
+ when 1 then blk[params]
47
+ else blk[*[params, env]]
48
+ end
49
+
50
+ case result
51
+ when NilClass then new(Merb::Request.new(env))
52
+ when Hash, Mash then new(Merb::Request.new(result))
53
+ when Merb::Request then new(result)
54
+ when Merb::Controller then result
55
+ else raise ArgumentError, "Block to eager_cache must return nil, the env Hash, a Request object, or a Controller object"
56
+ end
57
+ end
43
58
 
44
- blk.call(kontroller) unless blk.nil?
59
+ kontroller.force_cache!
45
60
 
46
61
  kontroller._dispatch(action)
47
62
 
48
63
  kontroller
49
64
  end
65
+
66
+ def build_request(path, params = {}, env = {})
67
+ path, params, env = nil, path, params if path.is_a? Hash
68
+
69
+ Merb::Cache::CacheRequest.new(path, params, env)
70
+ end
71
+
72
+ def build_url(*args)
73
+ Merb::Router.url(*args)
74
+ end
50
75
  end
51
76
 
52
77
  def fetch_partial(template, opts={}, conditions = {})
@@ -95,14 +120,14 @@ module Merb::Cache::CacheMixin
95
120
  def _eager_cache_after(klass, action, conditions = {}, blk = nil)
96
121
  if @_skip_cache.nil?
97
122
  run_later do
98
- controller = klass.eager_dispatch(action, request.env, blk)
123
+ controller = klass.eager_dispatch(action, request.params.dup, request.env.dup, blk)
99
124
 
100
125
  Merb::Cache[controller._lookup_store(conditions)].write(controller, nil, *controller._parameters_and_conditions(conditions))
101
126
  end
102
127
  end
103
128
  end
104
129
 
105
- def eager_cache(action, conditions = {}, env = request.env.dup, &blk)
130
+ def eager_cache(action, conditions = {}, params = request.params.dup, env = request.env.dup, &blk)
106
131
  unless @_skip_cache
107
132
  if action.is_a?(Array)
108
133
  klass, action = *action
@@ -111,7 +136,7 @@ module Merb::Cache::CacheMixin
111
136
  end
112
137
 
113
138
  run_later do
114
- controller = klass.eager_dispatch(action, env, blk)
139
+ controller = klass.eager_dispatch(action, params.dup, env.dup, blk)
115
140
  end
116
141
  end
117
142
  end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Merb::Cache::CacheRequest do
4
+ it "should subclass Merb::Request" do
5
+ Merb::Cache::CacheRequest.superclass.should == Merb::Request
6
+ end
7
+
8
+ describe "#path" do
9
+ it "can be specified without manipulating the env" do
10
+ Merb::Cache::CacheRequest.new('/path/to/foo').path.should == '/path/to/foo'
11
+ end
12
+ end
13
+
14
+ describe "#params" do
15
+ it "can be specified without manipulating the env" do
16
+ Merb::Cache::CacheRequest.new('/', 'foo' => 'bar').params.should == {'foo' => 'bar'}
17
+ end
18
+ end
19
+
20
+ describe "#env" do
21
+ it "can be specified in the constructor" do
22
+ Merb::Cache::CacheRequest.new('', {}, 'foo' => 'bar').env['foo'].should == 'bar'
23
+ end
24
+ end
25
+
26
+ it "should setup a default env" do
27
+ Merb::Cache::CacheRequest.new('').env.should_not be_empty
28
+ end
29
+ end
@@ -149,6 +149,84 @@ describe Merb::Cache::CacheMixin do
149
149
  end
150
150
  end
151
151
 
152
+ describe "#eager_cache" do
153
+ before(:each) do
154
+ Object.send(:remove_const, :EagerCacher) if defined?(EagerCacher)
155
+
156
+ class EagerCacher < Merb::Controller
157
+ def index
158
+ "index"
159
+ end
160
+ end
161
+ end
162
+
163
+
164
+
165
+ it "should accept a block with an arity of 1" do
166
+ class EagerCacher
167
+ eager_cache(:index) {|params|}
168
+ end
169
+
170
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error
171
+ end
172
+
173
+ it "should accept a block with an arity greater than 1" do
174
+ class EagerCacher
175
+ eager_cache(:index) {|params, env|}
176
+ end
177
+
178
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error
179
+ end
180
+
181
+ it "should accept a block with an arity of -1" do
182
+ class EagerCacher
183
+ eager_cache(:index) {|*args|}
184
+ end
185
+
186
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error
187
+ end
188
+
189
+ it "should accept a block with an arity of 0" do
190
+ class EagerCacher
191
+ eager_cache(:index) {||}
192
+ end
193
+
194
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error
195
+ end
196
+
197
+ it "should allow the block to return nil" do
198
+ class EagerCacher
199
+ eager_cache(:index) {}
200
+ end
201
+
202
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error
203
+ end
204
+
205
+ it "should allow the block to return a params hash" do
206
+ class EagerCacher
207
+ eager_cache(:index) {|params| params.merge(:foo => :bar)}
208
+ end
209
+
210
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error(ArgumentError)
211
+ end
212
+
213
+ it "should allow the block to return a Merb::Request object" do
214
+ class EagerCacher
215
+ eager_cache(:index) {|params| build_request('/')}
216
+ end
217
+
218
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error(ArgumentError)
219
+ end
220
+
221
+ it "should allow the block to return a Merb::Controller object" do
222
+ class EagerCacher
223
+ eager_cache(:index) {|params, env| EagerCacher.new(env)}
224
+ end
225
+
226
+ lambda { dispatch_to(EagerCacher, :index) }.should_not raise_error(ArgumentError)
227
+ end
228
+ end
229
+
152
230
  describe "eager_cache (Instance Method)" do
153
231
  class HasRun
154
232
  cattr_accessor :has_run
@@ -281,4 +359,22 @@ describe Merb::Cache::CacheMixin do
281
359
  new_controller.fetch_fragment {}
282
360
  end
283
361
  end
362
+
363
+ describe ".build_request" do
364
+ it "should create a CacheRequest" do
365
+ Merb::Controller.build_request({}).class.should == Merb::Cache::CacheRequest
366
+ end
367
+
368
+ it "should use nil if the path is not supplied" do
369
+ Merb::Controller.build_request({}).path.should be_nil
370
+ end
371
+
372
+ it "should allow the params to be specified" do
373
+ Merb::Controller.build_request(:foo => :bar).params[:foo].should == :bar
374
+ end
375
+
376
+ it "should allow the env to be specified" do
377
+ Merb::Controller.build_request({}, :foo => :bar).env[:foo].should == :bar
378
+ end
379
+ end
284
380
  end
@@ -17,227 +17,228 @@ begin
17
17
  raise Exception unless cache.get(key) == value
18
18
  rescue Exception => e
19
19
  puts e.message
20
- raise "Memcached connection failed. Try starting memcached with the memcached:start rake task or installing memcached gem with sudo gem install memcached."
21
- end
20
+ puts "Memcached connection failed. Try starting memcached with the memcached:start rake task or installing memcached gem with sudo gem install memcached."
21
+ else
22
22
 
23
- describe Merb::Cache::MemcachedStore do
24
- it_should_behave_like 'all stores'
23
+ describe Merb::Cache::MemcachedStore do
24
+ it_should_behave_like 'all stores'
25
25
 
26
- before(:each) do
27
- @store = Merb::Cache::MemcachedStore.new(:namespace => "specs", :servers => ["127.0.0.1:43042", "127.0.0.1:43043"])
28
- @memcached = @store.memcached
29
- @memcached.flush
30
- end
26
+ before(:each) do
27
+ @store = Merb::Cache::MemcachedStore.new(:namespace => "specs", :servers => ["127.0.0.1:43042", "127.0.0.1:43043"])
28
+ @memcached = @store.memcached
29
+ @memcached.flush
30
+ end
31
31
 
32
- after(:each) do
33
- @memcached.flush
34
- end
32
+ after(:each) do
33
+ @memcached.flush
34
+ end
35
35
 
36
36
 
37
- it "has accessor for namespace" do
38
- @store.namespace.should == "specs"
39
- end
37
+ it "has accessor for namespace" do
38
+ @store.namespace.should == "specs"
39
+ end
40
40
 
41
- it "has accessor for servers" do
42
- @store.servers.should == ["127.0.0.1:43042", "127.0.0.1:43043"]
43
- end
41
+ it "has accessor for servers" do
42
+ @store.servers.should == ["127.0.0.1:43042", "127.0.0.1:43043"]
43
+ end
44
44
 
45
- it "has accessor for memcached connector" do
46
- @store.memcached.should == @memcached
47
- end
45
+ it "has accessor for memcached connector" do
46
+ @store.memcached.should == @memcached
47
+ end
48
48
 
49
49
 
50
- #
51
- # ==== #writable?
52
- #
50
+ #
51
+ # ==== #writable?
52
+ #
53
53
 
54
- describe "#writable?" do
55
- describe "when conditions hash is empty" do
56
- it "returns true" do
57
- @store.writable?('foo').should be_true
54
+ describe "#writable?" do
55
+ describe "when conditions hash is empty" do
56
+ it "returns true" do
57
+ @store.writable?('foo').should be_true
58
+ end
58
59
  end
59
60
  end
60
- end
61
61
 
62
- #
63
- # ==== #read
64
- #
65
-
66
- describe "#read" do
67
- describe "when cache has NO entry matching key" do
68
- it "returns nil" do
69
- key = "foo"
70
-
71
- @memcached.delete(key) rescue nil
72
- @store.read(key).should be_nil
62
+ #
63
+ # ==== #read
64
+ #
65
+
66
+ describe "#read" do
67
+ describe "when cache has NO entry matching key" do
68
+ it "returns nil" do
69
+ key = "foo"
70
+
71
+ @memcached.delete(key) rescue nil
72
+ @store.read(key).should be_nil
73
+ end
73
74
  end
74
- end
75
75
 
76
- describe "when cache has entry matching key" do
77
- it "returns the entry matching the key" do
78
- key, data = "foo", "bar"
76
+ describe "when cache has entry matching key" do
77
+ it "returns the entry matching the key" do
78
+ key, data = "foo", "bar"
79
79
 
80
- @memcached.set(key, data)
80
+ @memcached.set(key, data)
81
81
 
82
- @store.read(key).should == data
83
- end
84
- end
85
- end
82
+ @store.read(key).should == data
83
+ end
84
+ end
85
+ end
86
86
 
87
- #
88
- # ==== #write
89
- #
87
+ #
88
+ # ==== #write
89
+ #
90
90
 
91
- describe "#write" do
92
- describe "when entry with the same key does not exist" do
93
- it "create a new entry" do
94
- key, data = "foo", "bar"
91
+ describe "#write" do
92
+ describe "when entry with the same key does not exist" do
93
+ it "create a new entry" do
94
+ key, data = "foo", "bar"
95
95
 
96
- @memcached.delete(key) rescue nil
97
- lambda { @memcached.get(key) }.should raise_error(Memcached::NotFound)
96
+ @memcached.delete(key) rescue nil
97
+ lambda { @memcached.get(key) }.should raise_error(Memcached::NotFound)
98
98
 
99
- @store.write(key, data)
100
- @memcached.get(key).should == data
101
- end
102
- end
99
+ @store.write(key, data)
100
+ @memcached.get(key).should == data
101
+ end
102
+ end
103
103
 
104
- describe "when entry with the same key already exists" do
105
- it "overwrites the entry in the cache" do
106
- key, data = "foo", "bar"
104
+ describe "when entry with the same key already exists" do
105
+ it "overwrites the entry in the cache" do
106
+ key, data = "foo", "bar"
107
107
 
108
- @memcached.set(key, "baz")
109
- @memcached.get(key).should == "baz"
108
+ @memcached.set(key, "baz")
109
+ @memcached.get(key).should == "baz"
110
110
 
111
- @store.write(key, data)
112
- @memcached.get(key).should == data
113
- end
114
- end
115
- end
111
+ @store.write(key, data)
112
+ @memcached.get(key).should == data
113
+ end
114
+ end
115
+ end
116
116
 
117
- #
118
- # ==== #fetch
119
- #
117
+ #
118
+ # ==== #fetch
119
+ #
120
120
 
121
- describe "#fetch" do
122
- describe "when the entry exists in the cache" do
123
- it "does NOT call the block" do
124
- key, data = "foo", "bar"
125
- called = false
126
- proc = lambda { called = true }
121
+ describe "#fetch" do
122
+ describe "when the entry exists in the cache" do
123
+ it "does NOT call the block" do
124
+ key, data = "foo", "bar"
125
+ called = false
126
+ proc = lambda { called = true }
127
127
 
128
- @memcached.set(key, data)
129
- @store.fetch(key, &proc)
128
+ @memcached.set(key, data)
129
+ @store.fetch(key, &proc)
130
130
 
131
- called.should be_false
132
- end
133
- end
131
+ called.should be_false
132
+ end
133
+ end
134
134
 
135
- describe "when the entry does not exist in the cache" do
136
- it "calls the block" do
137
- key, data = "foo", "bar"
138
- called = false
139
- proc = lambda { called = true }
140
-
141
- @memcached.delete(key) rescue nil
142
- @store.fetch(key, &proc)
135
+ describe "when the entry does not exist in the cache" do
136
+ it "calls the block" do
137
+ key, data = "foo", "bar"
138
+ called = false
139
+ proc = lambda { called = true }
140
+
141
+ @memcached.delete(key) rescue nil
142
+ @store.fetch(key, &proc)
143
143
 
144
- called.should be_true
145
- end
146
- end
147
- end
144
+ called.should be_true
145
+ end
146
+ end
147
+ end
148
148
 
149
- #
150
- # ==== #delete
151
- #
149
+ #
150
+ # ==== #delete
151
+ #
152
152
 
153
- describe "#delete" do
154
- describe "when the entry exists in the cache" do
155
- it "deletes the entry" do
156
- key, data = "foo", "bar"
153
+ describe "#delete" do
154
+ describe "when the entry exists in the cache" do
155
+ it "deletes the entry" do
156
+ key, data = "foo", "bar"
157
157
 
158
- @memcached.set(key, data)
159
- @memcached.get(key).should == data
158
+ @memcached.set(key, data)
159
+ @memcached.get(key).should == data
160
160
 
161
- @store.delete(key)
162
- lambda { @memcached.get(key) }.should raise_error(Memcached::NotFound)
163
- end
164
- end
161
+ @store.delete(key)
162
+ lambda { @memcached.get(key) }.should raise_error(Memcached::NotFound)
163
+ end
164
+ end
165
165
 
166
- describe "when the entry does not exist in the cache" do
167
- it "raises Memcached::NotFound" do
168
- lambda { @memcached.delete("#{rand}-#{rand}-#{Time.now.to_i}") }.
169
- should raise_error(Memcached::NotFound)
170
- end
166
+ describe "when the entry does not exist in the cache" do
167
+ it "raises Memcached::NotFound" do
168
+ lambda { @memcached.delete("#{rand}-#{rand}-#{Time.now.to_i}") }.
169
+ should raise_error(Memcached::NotFound)
170
+ end
171
+ end
171
172
  end
172
- end
173
173
 
174
- #
175
- # ==== #delete_all
176
- #
174
+ #
175
+ # ==== #delete_all
176
+ #
177
177
 
178
- describe "#delete_all" do
179
- it "flushes Memcached object" do
180
- @memcached.set("ruby", "rb")
181
- @memcached.set("python", "py")
182
- @memcached.set("perl", "pl")
178
+ describe "#delete_all" do
179
+ it "flushes Memcached object" do
180
+ @memcached.set("ruby", "rb")
181
+ @memcached.set("python", "py")
182
+ @memcached.set("perl", "pl")
183
183
 
184
- @store.delete_all
184
+ @store.delete_all
185
185
 
186
- @store.exists?("ruby").should be_nil
187
- @store.exists?("python").should be_nil
188
- @store.exists?("perl").should be_nil
186
+ @store.exists?("ruby").should be_nil
187
+ @store.exists?("python").should be_nil
188
+ @store.exists?("perl").should be_nil
189
+ end
189
190
  end
190
- end
191
191
 
192
- #
193
- # ==== #clone
194
- #
192
+ #
193
+ # ==== #clone
194
+ #
195
195
 
196
- describe "#clone" do
197
- it "clones Memcached instance" do
198
- clone = @store.clone
196
+ describe "#clone" do
197
+ it "clones Memcached instance" do
198
+ clone = @store.clone
199
199
 
200
- clone.memcached.object_id.should_not == @store.memcached.object_id
200
+ clone.memcached.object_id.should_not == @store.memcached.object_id
201
+ end
201
202
  end
202
- end
203
203
 
204
- #
205
- # ==== #normalize
206
- #
204
+ #
205
+ # ==== #normalize
206
+ #
207
207
 
208
- describe "#normalize" do
209
- it "should begin with the key" do
210
- @store.normalize("this/is/the/key").should =~ /^this\/is\/the\/key/
211
- end
208
+ describe "#normalize" do
209
+ it "should begin with the key" do
210
+ @store.normalize("this/is/the/key").should =~ /^this\/is\/the\/key/
211
+ end
212
212
 
213
- it "should not add the '?' if there are no parameters" do
214
- @store.normalize("this/is/the/key").should_not =~ /\?/
215
- end
213
+ it "should not add the '?' if there are no parameters" do
214
+ @store.normalize("this/is/the/key").should_not =~ /\?/
215
+ end
216
216
 
217
- it "should seperate the parameters from the key by a '?'" do
218
- @store.normalize("this/is/the/key", :page => 3, :lang => :en).
219
- should =~ %r!this\/is\/the\/key--#{{:page => 3, :lang => :en}.to_sha2}$!
217
+ it "should seperate the parameters from the key by a '?'" do
218
+ @store.normalize("this/is/the/key", :page => 3, :lang => :en).
219
+ should =~ %r!this\/is\/the\/key--#{{:page => 3, :lang => :en}.to_sha2}$!
220
+ end
220
221
  end
221
- end
222
222
 
223
- #
224
- # ==== #expire_time
225
- #
223
+ #
224
+ # ==== #expire_time
225
+ #
226
226
 
227
- describe "#expire_time" do
228
- describe "when there is NO :expire_in parameter" do
229
- it "returns 0" do
230
- @store.expire_time.should == 0
231
- end
232
- end
227
+ describe "#expire_time" do
228
+ describe "when there is NO :expire_in parameter" do
229
+ it "returns 0" do
230
+ @store.expire_time.should == 0
231
+ end
232
+ end
233
233
 
234
- describe "when there is :expire_in parameter" do
235
- it "returns Time.now + the :expire_in parameter" do
236
- now = Time.now
237
- Time.should_receive(:now).and_return now
234
+ describe "when there is :expire_in parameter" do
235
+ it "returns Time.now + the :expire_in parameter" do
236
+ now = Time.now
237
+ Time.should_receive(:now).and_return now
238
238
 
239
- @store.expire_time(:expire_in => 100).should == now + 100
240
- end
239
+ @store.expire_time(:expire_in => 100).should == now + 100
240
+ end
241
+ end
241
242
  end
242
243
  end
243
244
  end
@@ -104,7 +104,9 @@ describe Merb::Cache::ActionStore do
104
104
 
105
105
  eager_cache :index, [MLBSchedule, :index]
106
106
  eager_cache :overview, :index
107
- eager_cache(:short, :params => :page) {|c| c.params[:page] = (c.params[:page].to_i + 1).to_s}
107
+ eager_cache(:short, :params => :page) do |params, env|
108
+ build_request(params.merge(:page => (params[:page].to_i + 1).to_s))
109
+ end
108
110
 
109
111
  def index
110
112
  "MLBScores index"
@@ -6,10 +6,11 @@ require 'merb-core'
6
6
  require 'merb-action-args'
7
7
  require File.join(File.dirname(__FILE__), '..', 'lib', 'merb-cache')
8
8
 
9
- # We want logging!
10
- Merb.logger = Merb::Logger.new(File.join(File.dirname(__FILE__), '..', 'log', 'merb_test.log'))
9
+ Merb.disable(:initfile)
11
10
 
12
- Merb.start :environment => "test", :adapter => "runner"
11
+ Merb.start :environment => "test",
12
+ :adapter => "runner",
13
+ :log_file => File.join(File.dirname(__FILE__), '..', 'log', 'merb_test.log')
13
14
 
14
15
  require "merb-core/test"
15
16
  Spec::Runner.configure do |config|
@@ -78,4 +79,4 @@ class Merb::Controller
78
79
  def run_later
79
80
  yield
80
81
  end
81
- end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Burkert
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-06 00:00:00 +03:00
12
+ date: 2008-10-13 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.8
23
+ version: 0.9.9
24
24
  version:
25
25
  description: Merb plugin that provides caching (page, action, fragment, object)
26
26
  email: ben@benburkert.com
@@ -39,6 +39,7 @@ files:
39
39
  - TODO
40
40
  - lib/merb-cache
41
41
  - lib/merb-cache/cache.rb
42
+ - lib/merb-cache/cache_request.rb
42
43
  - lib/merb-cache/core_ext
43
44
  - lib/merb-cache/core_ext/enumerable.rb
44
45
  - lib/merb-cache/core_ext/hash.rb
@@ -57,8 +58,8 @@ files:
57
58
  - lib/merb-cache/stores/strategy/page_store.rb
58
59
  - lib/merb-cache/stores/strategy/sha1_store.rb
59
60
  - lib/merb-cache.rb
60
- - spec/log
61
61
  - spec/merb-cache
62
+ - spec/merb-cache/cache_request_spec.rb
62
63
  - spec/merb-cache/cache_spec.rb
63
64
  - spec/merb-cache/core_ext
64
65
  - spec/merb-cache/core_ext/enumerable_spec.rb