Skip to content

Commit

Permalink
tests for use_in_file_templates! and a little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Mizerany committed Mar 28, 2008
1 parent e0c7f97 commit 5e85712
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,7 @@ def render(renderer, template, options={})
def determine_layout(renderer, template, options)
return if options[:layout] == false
layout_from_options = options[:layout] || :layout
layout = templates[layout_from_options]
layout ||= resolve_template(renderer, layout_from_options, options, false)
layout
resolve_template(renderer, layout_from_options, options, false)
end

private
Expand Down
48 changes: 48 additions & 0 deletions test/use_in_file_templates_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require File.dirname(__FILE__) + '/helper'

context "Rendering in file templates" do

setup do
Sinatra.application = nil
use_in_file_templates!
end

specify "should set template" do
assert Sinatra.application.templates[:foo]
end

specify "should set layout" do
assert Sinatra.application.templates[:layout]
end

specify "should render without layout if specified" do
get '/' do
haml :foo, :layout => false
end

get_it '/'
assert_equal "this is foo\n", body
end

specify "should render with layout if specified" do
get '/' do
haml :foo
end

get_it '/'
assert_equal "X\nthis is foo\nX\n", body
end


end

__END__

## foo
this is foo

## layout
X
= yield
X

0 comments on commit 5e85712

Please sign in to comment.