From 20723ca49873076d8fc8c2bf0729568373e31738 Mon Sep 17 00:00:00 2001 From: Roberto Soares <roberto.tech@gmail.com> Date: Fri, 23 Nov 2012 16:13:08 -0300 Subject: `assert_template` fails with empty string when a template has been rendered For instance, it prevents false positive in this case: file = nil get :index assert_template("#{file}") --- actionpack/CHANGELOG.md | 4 ++++ actionpack/lib/action_controller/test_case.rb | 12 ++++++++---- actionpack/test/controller/action_pack_assertions_test.rb | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 85a83ed7d9..409725ae90 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* `assert_template` is no more passing with empty string when some template has been rendered. + + *Roberto Soares* + * Allow setting a symbol as path in scope on routes. This is now allowed: scope :api do diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index be8055955d..fd3a261a72 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -94,10 +94,14 @@ module ActionController matches_template = case options when String - rendered.any? do |t, num| - options_splited = options.split(File::SEPARATOR) - t_splited = t.split(File::SEPARATOR) - t_splited.last(options_splited.size) == options_splited + if options.empty? + rendered.blank? + else + rendered.any? do |t, num| + options_splited = options.split(File::SEPARATOR) + t_splited = t.split(File::SEPARATOR) + t_splited.last(options_splited.size) == options_splited + end end when Regexp rendered.any? { |t,num| t.match(options) } diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index ca542eb7e2..c653f7e756 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -447,6 +447,13 @@ class AssertTemplateTest < ActionController::TestCase end end + def test_with_empty_string_fails_when_template_rendered + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template "" + end + end + def test_passes_with_correct_string get :hello_world assert_template 'hello_world' -- cgit v1.2.3 From 2d6c4ec731861225779f3106f038effb17a27b21 Mon Sep 17 00:00:00 2001 From: Roberto Soares <roberto.tech@gmail.com> Date: Fri, 23 Nov 2012 18:10:18 -0300 Subject: `assert_template` fails with empty string. --- actionpack/CHANGELOG.md | 2 +- actionpack/lib/action_controller/test_case.rb | 12 ++++-------- actionpack/test/controller/action_pack_assertions_test.rb | 7 +++++++ 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 409725ae90..60af09083d 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,6 +1,6 @@ ## Rails 4.0.0 (unreleased) ## -* `assert_template` is no more passing with empty string when some template has been rendered. +* `assert_template` is no more passing with empty string. *Roberto Soares* diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index fd3a261a72..586dd3cdf9 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -94,14 +94,10 @@ module ActionController matches_template = case options when String - if options.empty? - rendered.blank? - else - rendered.any? do |t, num| - options_splited = options.split(File::SEPARATOR) - t_splited = t.split(File::SEPARATOR) - t_splited.last(options_splited.size) == options_splited - end + !options.empty? && rendered.any? do |t, num| + options_splited = options.split(File::SEPARATOR) + t_splited = t.split(File::SEPARATOR) + t_splited.last(options_splited.size) == options_splited end when Regexp rendered.any? { |t,num| t.match(options) } diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index c653f7e756..5f559e5b00 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -454,6 +454,13 @@ class AssertTemplateTest < ActionController::TestCase end end + def test_with_empty_string_fails_when_no_template_rendered + get :nothing + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template "" + end + end + def test_passes_with_correct_string get :hello_world assert_template 'hello_world' -- cgit v1.2.3