aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2014-07-25 17:14:53 +0930
committerMatthew Draper <matthew@trebex.net>2014-07-25 17:14:53 +0930
commit75eddfbca98bb17ae7569ec30a3094ae1c50cdd3 (patch)
tree876622201b76437f3e364227772c486c0096be38
parent3f4e97f807eb475ac8c311e5baf138249a8a1ab2 (diff)
parente6f2d4f68577643b15883b94ead417f75967d2d6 (diff)
downloadrails-75eddfbca98bb17ae7569ec30a3094ae1c50cdd3.tar.gz
rails-75eddfbca98bb17ae7569ec30a3094ae1c50cdd3.tar.bz2
rails-75eddfbca98bb17ae7569ec30a3094ae1c50cdd3.zip
Merge pull request #16272 from tgxworld/fix_template_assertion_when_opening_a_session
Fix template assertion when opening a session.
-rw-r--r--actionpack/lib/action_controller/test_case.rb14
-rw-r--r--actionpack/test/dispatch/template_assertions_test.rb48
2 files changed, 53 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 657924a16c..71cb224f22 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -12,8 +12,13 @@ module ActionController
teardown :teardown_subscriptions
end
+ RENDER_TEMPLATE_INSTANCE_VARIABLES = %w{partials templates layouts files}.freeze
+
def setup_subscriptions
- reset_template_assertion
+ RENDER_TEMPLATE_INSTANCE_VARIABLES.each do |instance_variable|
+ instance_variable_set("@_#{instance_variable}", Hash.new(0))
+ end
+
@_subscribers = []
@_subscribers << ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload|
@@ -58,10 +63,9 @@ module ActionController
end
def reset_template_assertion
- @_partials = Hash.new(0)
- @_templates = Hash.new(0)
- @_layouts = Hash.new(0)
- @_files = Hash.new(0)
+ RENDER_TEMPLATE_INSTANCE_VARIABLES.each do |instance_variable|
+ instance_variable_get("@_#{instance_variable}").clear
+ end
end
# Asserts that the request was rendered with the appropriate template file or partials.
diff --git a/actionpack/test/dispatch/template_assertions_test.rb b/actionpack/test/dispatch/template_assertions_test.rb
index b8bc8e22d4..3c393f937b 100644
--- a/actionpack/test/dispatch/template_assertions_test.rb
+++ b/actionpack/test/dispatch/template_assertions_test.rb
@@ -24,7 +24,7 @@ class AssertTemplateController < ActionController::Base
end
class AssertTemplateControllerTest < ActionDispatch::IntegrationTest
- def test_assert_template_reset_between_requests
+ def test_template_reset_between_requests
get '/assert_template/render_with_template'
assert_template 'test/hello_world'
@@ -32,7 +32,7 @@ class AssertTemplateControllerTest < ActionDispatch::IntegrationTest
assert_template nil
end
- def test_assert_partial_reset_between_requests
+ def test_partial_reset_between_requests
get '/assert_template/render_with_partial'
assert_template partial: 'test/_partial'
@@ -40,7 +40,7 @@ class AssertTemplateControllerTest < ActionDispatch::IntegrationTest
assert_template partial: nil
end
- def test_assert_layout_reset_between_requests
+ def test_layout_reset_between_requests
get '/assert_template/render_with_layout'
assert_template layout: 'layouts/standard'
@@ -48,11 +48,51 @@ class AssertTemplateControllerTest < ActionDispatch::IntegrationTest
assert_template layout: nil
end
- def test_assert_file_reset_between_requests
+ def test_file_reset_between_requests
get '/assert_template/render_with_file'
assert_template file: 'README.rdoc'
get '/assert_template/render_nothing'
assert_template file: nil
end
+
+ def test_template_reset_between_requests_when_opening_a_session
+ open_session do |session|
+ session.get '/assert_template/render_with_template'
+ session.assert_template 'test/hello_world'
+
+ session.get '/assert_template/render_nothing'
+ session.assert_template nil
+ end
+ end
+
+ def test_partial_reset_between_requests_when_opening_a_session
+ open_session do |session|
+ session.get '/assert_template/render_with_partial'
+ session.assert_template partial: 'test/_partial'
+
+ session.get '/assert_template/render_nothing'
+ session.assert_template partial: nil
+ end
+ end
+
+ def test_layout_reset_between_requests_when_opening_a_session
+ open_session do |session|
+ session.get '/assert_template/render_with_layout'
+ session.assert_template layout: 'layouts/standard'
+
+ session.get '/assert_template/render_nothing'
+ session.assert_template layout: nil
+ end
+ end
+
+ def test_file_reset_between_requests_when_opening_a_session
+ open_session do |session|
+ session.get '/assert_template/render_with_file'
+ session.assert_template file: 'README.rdoc'
+
+ session.get '/assert_template/render_nothing'
+ session.assert_template file: nil
+ end
+ end
end