erector-rails4 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3ade49fdb2de3d11f397885098e275424687a22
4
- data.tar.gz: 1f706283a313e34c802e310cb4249128ad6dbcb0
3
+ metadata.gz: a74438b8e1a5e68fb0630a400e6863d5eef429d3
4
+ data.tar.gz: 5a3bb013b485b9afd29a816abccf442dfec8126a
5
5
  SHA512:
6
- metadata.gz: 354555dd2a8e63e575993021a39cb7a40a885c6fe73d40c3d599cd974029cd484fbab11d388e6883ef665633d62752b6f9c37303f5c6b801a1a40a7d777e281d
7
- data.tar.gz: f598d530d6054192c74a9b56c89c0d6c631958a2a674ffae3419e17e1944c17b0a54776005b35fe471b79253cddca87b548eefeddde179dde6252efcaff34c46
6
+ metadata.gz: acc2083f696024b0ece8425d4591674dbaadc00d5cfca2e6ab61f7a06fd225c5390bb39694bdca32c70e34d24bf80eaeaf60b145339eb8166cdeadc0faebaf5d
7
+ data.tar.gz: af17c1bb8dbd175f441b7537f7314e4c4de03abfc0c09b44c9422f2f14a264e8499c681062e878bfc18bdc205da678c252f1f51aa040e416bf74b50394a66b4b
@@ -67,7 +67,22 @@ module Erector
67
67
  protected
68
68
  def _emit(options = {})
69
69
  if should_cache?
70
- cache[self.class, self.class.cache_version, cache_key_assigns, options[:content_method_name]] ||= super
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
@@ -1,3 +1,3 @@
1
1
  module Erector
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erector-rails4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee