erector-rails4 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/erector/caching.rb +16 -1
- data/lib/erector/version.rb +1 -1
- data/spec/dummy/spec/render_spec.rb +26 -0
- data/spec/erector/caching_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74438b8e1a5e68fb0630a400e6863d5eef429d3
|
4
|
+
data.tar.gz: 5a3bb013b485b9afd29a816abccf442dfec8126a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc2083f696024b0ece8425d4591674dbaadc00d5cfca2e6ab61f7a06fd225c5390bb39694bdca32c70e34d24bf80eaeaf60b145339eb8166cdeadc0faebaf5d
|
7
|
+
data.tar.gz: af17c1bb8dbd175f441b7537f7314e4c4de03abfc0c09b44c9422f2f14a264e8499c681062e878bfc18bdc205da678c252f1f51aa040e416bf74b50394a66b4b
|
data/lib/erector/caching.rb
CHANGED
@@ -67,7 +67,22 @@ module Erector
|
|
67
67
|
protected
|
68
68
|
def _emit(options = {})
|
69
69
|
if should_cache?
|
70
|
-
|
70
|
+
if options[:output]
|
71
|
+
# todo: document that either :buffer or :output can be used to specify an output buffer, and deprecate :output
|
72
|
+
if options[:output].is_a? Output
|
73
|
+
@_output = options[:output]
|
74
|
+
else
|
75
|
+
@_output = Output.new({:buffer => options[:output]}.merge(options))
|
76
|
+
end
|
77
|
+
else
|
78
|
+
@_output = Output.new(options)
|
79
|
+
end
|
80
|
+
|
81
|
+
if (cached_str = cache[self.class, self.class.cache_version, cache_key_assigns, options[:content_method_name]])
|
82
|
+
output << cached_str
|
83
|
+
else
|
84
|
+
cache[self.class, self.class.cache_version, cache_key_assigns, options[:content_method_name]] = super
|
85
|
+
end
|
71
86
|
else
|
72
87
|
super
|
73
88
|
end
|
data/lib/erector/version.rb
CHANGED
@@ -49,6 +49,16 @@ describe ActionController::Base do
|
|
49
49
|
render :widget => TestWidget, :content_method_name => :content_method
|
50
50
|
end
|
51
51
|
|
52
|
+
def render_with_cache_one
|
53
|
+
@name = 'One'
|
54
|
+
render :widget => CashWidget
|
55
|
+
end
|
56
|
+
|
57
|
+
def render_with_cache_two
|
58
|
+
@name = 'Two'
|
59
|
+
render :widget => CashWidget
|
60
|
+
end
|
61
|
+
|
52
62
|
def render_with_rails_options
|
53
63
|
render :widget => TestWidget, :status => 500, :content_type => "application/json"
|
54
64
|
end
|
@@ -229,6 +239,15 @@ describe ActionController::Base do
|
|
229
239
|
end
|
230
240
|
end
|
231
241
|
|
242
|
+
class CashWidget < Erector::Widget
|
243
|
+
needs :name
|
244
|
+
cacheable 'v1'
|
245
|
+
|
246
|
+
def content
|
247
|
+
text @name
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
232
251
|
def test_action(action)
|
233
252
|
@response = TestController.action(action).call(Rack::MockRequest.env_for("/path"))[2]
|
234
253
|
@response.body
|
@@ -365,5 +384,12 @@ describe ActionController::Base do
|
|
365
384
|
test_action(:render_with_widget_as_layout_using_content_for).should == "TOPBEFOREDURINGAFTER"
|
366
385
|
end
|
367
386
|
|
387
|
+
it "should cache properly" do
|
388
|
+
test_action(:render_with_cache_one).should == "One"
|
389
|
+
test_action(:render_with_cache_one).should == "One"
|
390
|
+
test_action(:render_with_cache_two).should == "Two"
|
391
|
+
test_action(:render_with_cache_two).should == "Two"
|
392
|
+
end
|
393
|
+
|
368
394
|
end
|
369
395
|
end
|
@@ -126,6 +126,8 @@ describe Erector::Caching do
|
|
126
126
|
it "uses the only_keys option" do
|
127
127
|
CashWithCacheOpts.new(name: "Adam", occupation: "Hairdresser").to_html
|
128
128
|
@cache[CashWithCacheOpts, 'v3', {occupation: "Hairdresser"}].should == "Adam is a Hairdresser"
|
129
|
+
CashWithCacheOpts.new(name: "Foobar", occupation: "Hairdresser").to_html.should == "Adam is a Hairdresser"
|
130
|
+
CashWithCacheOpts.new(name: "Foobar", occupation: "Hairdressr").to_html.should == "Foobar is a Hairdressr"
|
129
131
|
end
|
130
132
|
|
131
133
|
it "doesn't use the cached value for widgets not declared cachable" do
|