Skip to content

Commit

Permalink
Fix assert_template :layout => nil assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
avakhov committed May 4, 2012
1 parent df36c5f commit 4bd05a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def setup_subscriptions


ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload| ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload|
path = payload[:layout] path = payload[:layout]
@layouts[path] += 1 if path
@layouts[path] += 1
end
end end


ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload| ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload|
Expand Down Expand Up @@ -90,7 +92,8 @@ def assert_template(options = {}, message = nil)
end end
end end
when Hash 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>", msg = message || sprintf("expecting layout <%s> but action rendered <%s>",
expected_layout, @layouts.keys) expected_layout, @layouts.keys)


Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ def test_fails_with_wrong_layout
end end
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 def test_passes_with_correct_layout
get :render_with_layout get :render_with_layout
assert_template :layout => "layouts/standard" assert_template :layout => "layouts/standard"
Expand All @@ -488,6 +495,11 @@ def test_passes_with_layout_and_partial
assert_template :layout => "layouts/standard" assert_template :layout => "layouts/standard"
end end


def test_passed_with_no_layout
get :hello_world
assert_template :layout => nil
end

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

0 comments on commit 4bd05a7

Please sign in to comment.