Skip to content

Commit e33a2db

Browse files
committed
Add a spec
1 parent 5671ac5 commit e33a2db

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spec/compiler_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ def square?(width:, height:)
138138
render("{{#square? width=2 height=2}}yeah!{{/square?}}").should == "yeah!"
139139
end
140140

141+
it "caches context blocks" do
142+
define_presenter do
143+
presents :author
144+
145+
def author(&block)
146+
block.call(@author)
147+
end
148+
149+
def x
150+
"x"
151+
end
152+
end
153+
154+
define_presenter "AuthorPresenter" do
155+
presents :author
156+
157+
def name
158+
@author.name
159+
end
160+
161+
def cache_key
162+
"static"
163+
end
164+
end
165+
166+
author = double("author", name: "john")
167+
template = "{{@author}}{{name}}{{/author}}"
168+
169+
expect(render(template, locals: { author: author })).to eq "john"
170+
171+
author.stub(:name) { "jane" }
172+
173+
expect(render(template, locals: { author: author })).to eq "john"
174+
end
175+
141176
it "gives an error on incomplete blocks" do
142177
expect do
143178
render("{{#hello?}}")

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def render(source, options = {}, &block)
3535
template = ActionView::Template.new(source, identifier, handler, details)
3636
view = ActionView::Base.new
3737
view.lookup_context.stub(:find_template) { source }
38+
view.stub(:view_cache_dependencies) { [] }
39+
view.controller = ActionView::TestCase::TestController.new
40+
view.controller.perform_caching = true
3841

3942
begin
4043
template.render(view, options.fetch(:locals, {}), &block)

0 commit comments

Comments
 (0)