Skip to content

Commit

Permalink
Merge pull request #16027 from tgxworld/template_assertions
Browse files Browse the repository at this point in the history
Fixes to ActionController::TemplateAssertions
  • Loading branch information
senny committed Aug 14, 2014
2 parents 43ce6e2 + b1ba333 commit 9c91c16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Fix `assert_template` not being able to assert that no files were rendered.

*Guo Xiang Tan*

* Extract source code for the entire exception stack trace for
better debugging and diagnosis.

Expand Down
9 changes: 9 additions & 0 deletions actionpack/lib/action_controller/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def reset_template_assertion
# # assert that no partials were rendered
# assert_template partial: false
#
# # assert that a file was rendered
# assert_template file: "README.rdoc"
#
# # assert that no file was rendered
# assert_template file: nil
# assert_template file: false
#
# In a view test case, you can also assert that specific locals are passed
# to partials:
#
Expand Down Expand Up @@ -140,6 +147,8 @@ def assert_template(options = {}, message = nil)

if options[:file]
assert_includes @_files.keys, options[:file]
elsif options.key?(:file)
assert @_files.blank?, "expected no files but #{@_files.keys} was rendered"
end

if expected_partial = options[:partial]
Expand Down
23 changes: 23 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ def test_with_file_failure
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template :file => 'test/hello_world'
end

get :render_file_absolute_path
assert_raise(ActiveSupport::TestCase::Assertion) do
assert_template file: nil
end
end

def test_with_nil_passes_when_no_template_rendered
Expand Down Expand Up @@ -612,6 +617,24 @@ def test_assert_template_reset_between_requests

get :nothing
assert_template nil

get :partial
assert_template partial: 'test/_partial'

get :nothing
assert_template partial: nil

get :render_with_layout
assert_template layout: 'layouts/standard'

get :nothing
assert_template layout: nil

get :render_file_relative_path
assert_template file: 'README.rdoc'

get :nothing
assert_template file: nil
end
end

Expand Down

0 comments on commit 9c91c16

Please sign in to comment.