Skip to content
This repository
Browse code

Improve assert_template layout checking

  • Loading branch information...
commit 0d19a081ee12b46791d8709e5c0898429e2ef91f 1 parent 4bd05a7
Alexey Vakhov avakhov authored
18 actionpack/lib/action_controller/test_case.rb
@@ -22,6 +22,9 @@ def setup_subscriptions
22 22 path = payload[:layout]
23 23 if path
24 24 @layouts[path] += 1
  25 + if path =~ /^layouts\/(.*)/
  26 + @layouts[$1] += 1
  27 + end
25 28 end
26 29 end
27 30
@@ -61,6 +64,15 @@ def process(*args)
61 64 # # assert that the exact template "admin/posts/new" was rendered
62 65 # assert_template %r{\Aadmin/posts/new\Z}
63 66 #
  67 + # # assert that the layout 'admin' was rendered
  68 + # assert_template :layout => 'admin'
  69 + # assert_template :layout => 'layouts/admin'
  70 + # assert_template :layout => :admin
  71 + #
  72 + # # assert that no layout was rendered
  73 + # assert_template :layout => nil
  74 + # assert_template :layout => false
  75 + #
64 76 # # assert that the "_customer" partial was rendered twice
65 77 # assert_template :partial => '_customer', :count => 2
66 78 #
@@ -98,11 +110,11 @@ def assert_template(options = {}, message = nil)
98 110 expected_layout, @layouts.keys)
99 111
100 112 case expected_layout
101   - when String
102   - assert_includes @layouts.keys, expected_layout, msg
  113 + when String, Symbol
  114 + assert_includes @layouts.keys, expected_layout.to_s, msg
103 115 when Regexp
104 116 assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg)
105   - when nil
  117 + when nil, false
106 118 assert(@layouts.empty?, msg)
107 119 end
108 120 end
15 actionpack/test/controller/action_pack_assertions_test.rb
@@ -500,6 +500,21 @@ def test_passed_with_no_layout
500 500 assert_template :layout => nil
501 501 end
502 502
  503 + def test_passed_with_no_layout_false
  504 + get :hello_world
  505 + assert_template :layout => false
  506 + end
  507 +
  508 + def test_passes_with_correct_layout_without_layouts_prefix
  509 + get :render_with_layout
  510 + assert_template :layout => "standard"
  511 + end
  512 +
  513 + def test_passes_with_correct_layout_symbol
  514 + get :render_with_layout
  515 + assert_template :layout => :standard
  516 + end
  517 +
503 518 def test_assert_template_reset_between_requests
504 519 get :hello_world
505 520 assert_template 'test/hello_world'

0 comments on commit 0d19a08

Please sign in to comment.
Something went wrong with that request. Please try again.