diff options
author | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-04-05 11:02:18 -0700 |
---|---|---|
committer | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-04-06 13:30:49 -0700 |
commit | 8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7 (patch) | |
tree | 3861031bf9ef8792cac28604dd8e9319aef5bda9 | |
parent | c45939ea2c7b42030afa2bce2de0681aba0777b6 (diff) | |
download | rails-8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7.tar.gz rails-8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7.tar.bz2 rails-8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7.zip |
Fix setup of adding _flash_types test.
Adding flash types to a controller within any of the tests will result
in a global state change of the controller under test.
This patch will prevent state leaks and allow us to run the test in random order.
-rw-r--r-- | actionpack/test/controller/flash_test.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 25a4857eba..ff5587d768 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -210,20 +210,29 @@ class FlashTest < ActionController::TestCase end def test_redirect_to_with_adding_flash_types - @controller.class.add_flash_types :foo + original_controller = @controller + test_controller_with_flash_type_foo = Class.new(TestController) do + add_flash_types :foo + end + @controller = test_controller_with_flash_type_foo.new get :redirect_with_foo_flash assert_equal "for great justice", @controller.send(:flash)[:foo] + ensure + @controller = original_controller end - class SubclassesTestController < TestController; end - def test_add_flash_type_to_subclasses - TestController.add_flash_types :foo - assert SubclassesTestController._flash_types.include?(:foo) + test_controller_with_flash_type_foo = Class.new(TestController) do + add_flash_types :foo + end + subclass_controller_with_no_flash_type = Class.new(test_controller_with_flash_type_foo) + assert subclass_controller_with_no_flash_type._flash_types.include?(:foo) end def test_do_not_add_flash_type_to_parent_class - SubclassesTestController.add_flash_types :bar + subclass_controller_with_flash_type_bar = Class.new(TestController) do + add_flash_types :bar + end assert_not TestController._flash_types.include?(:bar) end end |