Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit ca50043a7ad95825b3830d97294b14b665a7d698 2 parents 0729cc8 + 1413ee9
@rafaelfranca rafaelfranca authored
View
7 actionpack/CHANGELOG.md
@@ -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.
View
2  actionpack/lib/action_controller/metal/flash.rb
@@ -37,7 +37,7 @@ def add_flash_types(*types)
end
helper_method type
- _flash_types << type
+ self._flash_types += [type]
end
end
end
View
12 actionpack/test/controller/flash_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.