Skip to content

Commit

Permalink
Add a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Jul 31, 2015
1 parent 5671ac5 commit fe414b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ def square?(width:, height:)
render("{{#square? width=2 height=2}}yeah!{{/square?}}").should == "yeah!"
end

it "caches context blocks" do
define_presenter do
presents :author

def author(&block)
block.call(@author)
end
end

define_presenter "AuthorPresenter" do
presents :author

def name
@author.name
end

def cache_key
"static"
end
end

author = double("author", name: "john")
template = "{{@author}}{{name}}{{/author}}"

expect(render(template, locals: { author: author })).to eq "john"

author.stub(:name) { "jane" }

expect(render(template, locals: { author: author })).to eq "john"
end

it "gives an error on incomplete blocks" do
expect do
render("{{#hello?}}")
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def render(source, options = {}, &block)
template = ActionView::Template.new(source, identifier, handler, details)
view = ActionView::Base.new
view.lookup_context.stub(:find_template) { source }
view.stub(:view_cache_dependencies) { [] }
view.controller = ActionView::TestCase::TestController.new
view.controller.perform_caching = true

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

0 comments on commit fe414b3

Please sign in to comment.