Skip to content

Commit

Permalink
Improve assert_template layout checking
Browse files Browse the repository at this point in the history
  • Loading branch information
avakhov committed May 4, 2012
1 parent 4bd05a7 commit 0d19a08
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
18 changes: 15 additions & 3 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -22,6 +22,9 @@ def setup_subscriptions
path = payload[:layout]
if path
@layouts[path] += 1
if path =~ /^layouts\/(.*)/
@layouts[$1] += 1
end
end
end

Expand Down Expand Up @@ -61,6 +64,15 @@ def process(*args)
# # assert that the exact template "admin/posts/new" was rendered
# assert_template %r{\Aadmin/posts/new\Z}
#
# # assert that the layout 'admin' was rendered
# assert_template :layout => 'admin'
# assert_template :layout => 'layouts/admin'
# assert_template :layout => :admin
#
# # assert that no layout was rendered
# assert_template :layout => nil
# assert_template :layout => false
#
# # assert that the "_customer" partial was rendered twice
# assert_template :partial => '_customer', :count => 2
#
Expand Down Expand Up @@ -98,11 +110,11 @@ def assert_template(options = {}, message = nil)
expected_layout, @layouts.keys)

case expected_layout
when String
assert_includes @layouts.keys, expected_layout, msg
when String, Symbol
assert_includes @layouts.keys, expected_layout.to_s, msg
when Regexp
assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
when nil
when nil, false
assert(@layouts.empty?, msg)
end
end
Expand Down
15 changes: 15 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -500,6 +500,21 @@ def test_passed_with_no_layout
assert_template :layout => nil
end

def test_passed_with_no_layout_false
get :hello_world
assert_template :layout => false
end

def test_passes_with_correct_layout_without_layouts_prefix
get :render_with_layout
assert_template :layout => "standard"
end

def test_passes_with_correct_layout_symbol
get :render_with_layout
assert_template :layout => :standard
end

def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
Expand Down

0 comments on commit 0d19a08

Please sign in to comment.