Permalink
Browse files

Merge pull request #12222 from rcillo/fix-custom-flash

Custom flash should be defined only for the class that defines it and it's subclasses

Fixes #12057
  • Loading branch information...
2 parents 0729cc8 + 1413ee9 commit ca50043a7ad95825b3830d97294b14b665a7d698 @rafaelfranca rafaelfranca committed Sep 13, 2013
View
@@ -1,3 +1,10 @@
+* Fix custom flash type definition. Misusage of the `_flash_types` class variable
+ caused an error when reloading controllers with custom flash types.
+
+ Fixes #12057
+
+ *Ricardo de Cillo*
+
* Do not break params filtering on `nil` values.
Fixes #12149.
@@ -37,7 +37,7 @@ def add_flash_types(*types)
end
helper_method type
- _flash_types << type
+ self._flash_types += [type]
end
end
end
@@ -214,6 +214,18 @@ def test_redirect_to_with_adding_flash_types
get :redirect_with_foo_flash
assert_equal "for great justice", @controller.send(:flash)[:foo]
end
+
+ class SubclassesTestController < TestController; end
+
+ def test_add_flash_type_to_subclasses
+ TestController.add_flash_types :foo
+ assert SubclassesTestController._flash_types.include?(:foo)
+ end
+
+ def test_do_not_add_flash_type_to_parent_class
+ SubclassesTestController.add_flash_types :bar
+ assert_not TestController._flash_types.include?(:bar)
+ end
end
class FlashIntegrationTest < ActionDispatch::IntegrationTest

0 comments on commit ca50043

Please sign in to comment.