diff options
author | José Valim <jose.valim@gmail.com> | 2012-05-04 12:39:51 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-05-04 12:39:51 -0700 |
commit | 2919fd8980dd753a72c4121c77768470e4aafd6b (patch) | |
tree | 26ab14ac12a5516c8663bec767d5f6a93ce95ea2 /actionpack/lib/action_controller/test_case.rb | |
parent | 9ce057d8ccc799eb4844494e3c6ee553969a66d3 (diff) | |
parent | 0d19a081ee12b46791d8709e5c0898429e2ef91f (diff) | |
download | rails-2919fd8980dd753a72c4121c77768470e4aafd6b.tar.gz rails-2919fd8980dd753a72c4121c77768470e4aafd6b.tar.bz2 rails-2919fd8980dd753a72c4121c77768470e4aafd6b.zip |
Merge pull request #5808 from avakhov/assert-template-layout-improve
Assert template layout improve
Diffstat (limited to 'actionpack/lib/action_controller/test_case.rb')
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 21997c4d79..ad02375f12 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -20,7 +20,12 @@ module ActionController ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload| path = payload[:layout] - @layouts[path] += 1 + if path + @layouts[path] += 1 + if path =~ /^layouts\/(.*)/ + @layouts[$1] += 1 + end + end end ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload| @@ -59,6 +64,15 @@ module ActionController # # 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 # @@ -90,16 +104,17 @@ module ActionController end end when Hash - if expected_layout = options[:layout] + if options.key?(:layout) + expected_layout = options[:layout] msg = message || sprintf("expecting layout <%s> but action rendered <%s>", 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 @@ -120,7 +135,7 @@ module ActionController options[:partial], @partials.keys) assert_includes @partials, expected_partial, msg end - else + elsif options.key?(:partial) assert @partials.empty?, "Expected no partials to be rendered" end |