Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix assert_template :layout => nil assertion

  • Loading branch information...
commit 4bd05a7bdc5003c9ebb090dcb0dc4949e4fb8ad3 1 parent df36c5f
Alexey Vakhov avakhov authored
7 actionpack/lib/action_controller/test_case.rb
View
@@ -20,7 +20,9 @@ def setup_subscriptions
ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout]
- @layouts[path] += 1
+ if path
+ @layouts[path] += 1
+ end
end
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
@@ -90,7 +92,8 @@ def assert_template(options = {}, message = nil)
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)
12 actionpack/test/controller/action_pack_assertions_test.rb
View
@@ -478,6 +478,13 @@ def test_fails_with_wrong_layout
end
end
+ def test_fails_expecting_no_layout
+ get :render_with_layout
+ assert_raise(ActiveSupport::TestCase::Assertion) do
+ assert_template :layout => nil
+ end
+ end
+
def test_passes_with_correct_layout
get :render_with_layout
assert_template :layout => "layouts/standard"
@@ -488,6 +495,11 @@ def test_passes_with_layout_and_partial
assert_template :layout => "layouts/standard"
end
+ def test_passed_with_no_layout
+ get :hello_world
+ assert_template :layout => nil
+ end
+
def test_assert_template_reset_between_requests
get :hello_world
assert_template 'test/hello_world'
Please sign in to comment.
Something went wrong with that request. Please try again.