Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Add test for render with block
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Nov 2, 2010
1 parent a0c5782 commit e1fcca8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/brochure/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def h(html)
Rack::Utils.escape_html(html)
end

def render(logical_path, locals = {})
def render(logical_path, locals = {}, &block)
if partial = application.find_partial(logical_path, template.format_extension)
partial.render(env, locals)
partial.render(env, locals, &block)
else
raise TemplateNotFound, "no such template '#{logical_path}'"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/brochure/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def content_type
end
end

def render(env, locals = {})
template.render(app.context_for(self, env), locals)
def render(env, locals = {}, &block)
template.render(app.context_for(self, env), locals, &block)
end
end
end
9 changes: 9 additions & 0 deletions test/fixtures/default/templates/_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<%= yield %>
</body>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/default/templates/blog.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% render "layout", :title => "Blog" do %>
<h1>Latest</h1>
<% end %>
3 changes: 3 additions & 0 deletions test/fixtures/default/templates/blog/2010.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% render "layout", :title => "Blog - 2010" do %>
<h1>Posts from 2010</h1>
<% end %>
11 changes: 11 additions & 0 deletions test/test_brochure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ def test_missing_partial_raises_an_error
assert last_response.server_error?
end

def test_render_layout_with_block
get "/blog"
puts last_response.body
assert last_response.body["<title>Blog</title>"]
assert last_response.body["<h1>Latest</h1>"]

get "/blog/2010"
assert last_response.body["<title>Blog - 2010</title>"]
assert last_response.body["<h1>Posts from 2010</h1>"]
end

def test_using_other_tilt_template_types
get "/hello?name=Sam"
assert last_response.body["<p>Hello Sam</p>"]
Expand Down

0 comments on commit e1fcca8

Please sign in to comment.