Skip to content

Commit

Permalink
Exclude added flash types from action_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodacious committed Jul 14, 2021
1 parent ac87404 commit 39ab101
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,16 @@
* Exclude additional flash types from `ActionController::Base.action_methods`.

Ensures that additional flash types defined on ActionController::Base subclasses
are not listed as actions on that controller.

class MyController < ApplicationController
add_flash_types :hype
end

MyController.action_methods.include?('hype') # => false

*Gavin Morrice*

* Deleting an item from the Middleware stack will raise if the item is not found

Previously, calling `config.middleware.delete(ItemNotInMiddleware)` would fail silently.
Expand Down
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/flash.rb
Expand Up @@ -41,6 +41,10 @@ def add_flash_types(*types)
self._flash_types += [type]
end
end

def action_methods #:nodoc:
@action_methods ||= super - _flash_types.map(&:to_s).to_set
end
end

private
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/flash_test.rb
Expand Up @@ -224,6 +224,13 @@ def test_redirect_to_with_adding_flash_types
@controller = original_controller
end

def test_additional_flash_types_are_not_listed_in_actions_set
test_controller_with_flash_type_foo = Class.new(TestController) do
add_flash_types :foo
end
assert_not_includes test_controller_with_flash_type_foo.action_methods, "foo"
end

def test_add_flash_type_to_subclasses
test_controller_with_flash_type_foo = Class.new(TestController) do
add_flash_types :foo
Expand Down

0 comments on commit 39ab101

Please sign in to comment.