Permalink
Browse files

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.
  • Loading branch information...
1 parent c45939e commit 8bbaa94c8125cf3efc0ec05cee5bf3193fbf5cf7 @tgxworld tgxworld committed Apr 5, 2014
Showing with 15 additions and 6 deletions.
  1. +15 −6 actionpack/test/controller/flash_test.rb
@@ -210,20 +210,29 @@ def test_redirect_to_with_other_flashes
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

0 comments on commit 8bbaa94

Please sign in to comment.