8000 get rid of deprecated *_filter support (#6960) · activeadmin/activeadmin@a9547ef · GitHub
[go: up one dir, main page]

Skip to content

Commit a9547ef

Browse files
get rid of deprecated *_filter support (#6960)
`*_filter` methods were removed in Rails 5.1, see rails/rails@d7be30e. Should've been done as a part of cdfea4c, so this is just a leftover addressed. BTW `skip_action` added in fc87605 never existed in Rails. `skip_filter` was renamed to `skip_action_callback` in Rails 4.2 rails/rails@6c5f43b and then deprecated in Rails 5.1 rails/rails@6976e1d. Basically this commit reverts the implementation to 2010, similar to 83c1f22 but more complete and up-to-date.
1 parent 03a2f62 commit a9547ef

File tree

4 files changed

+28
-49
lines changed

4 files changed

+28
-49
lines changed

lib/active_admin/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ def routes(rails_router)
145145

146146
# Adds before, around and after filters to all controllers.
147147
# Example usage:
148-
# ActiveAdmin.before_filter :authenticate_admin!
148+
# ActiveAdmin.before_action :authenticate_admin!
149149
#
150150
AbstractController::Callbacks::ClassMethods.public_instance_methods.
151-
select { |m| m.match(/(filter|action)/) }.each do |name|
151+
select { |m| m.match(/_action\z/) }.each do |name|
152152
define_method name do |*args, &block|
153153
controllers_for_filters.each do |controller|
154154
controller.public_send name, *args, &block

lib/active_admin/resource_dsl.rb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,9 @@ def decorate_with(decorator_class)
191191
delegate :before_save, :after_save, to: :controller
192192
delegate :before_destroy, :after_destroy, to: :controller
193193

194-
# This code defines both *_filter and *_action for Rails 5.0 and *_action for Rails >= 5.1
195-
phases = [
196-
:before, :skip_before,
197-
:after, :skip_after,
198-
:around, :skip
199-
]
200-
keywords = if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1
201-
[:action]
202-
else
203-
[:action, :filter]
204-
end
205-
206-
keywords.each do |name|
207-
phases.each do |action|
208-
define_method "#{action}_#{name}" do |*args, &block|
209-
controller.public_send "#{action}_action", *args, &block
210-
end
211-
end
212-
end
194+
standard_rails_filters =
195+
AbstractController::Callbacks::ClassMethods.public_instance_methods.select { |m| m.match(/_action\z/) }
196+
delegate *standard_rails_filters, to: :controller
213197

214198
# Specify which actions to create in the controller
215199
#

spec/unit/controller_filters_spec.rb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,16 @@
1313
]
1414
end
1515

16-
expected_actions = (
17-
prefixes = %w(skip append prepend) << nil
18-
positions = %w(before around after)
19-
suffixes = %w(action)
20-
base = %w()
21-
22-
prefixes.each_with_object(base) do |prefix, stack|
23-
positions.each do |position|
24-
suffixes.each do |suffix|
25-
stack << [prefix, position, suffix].compact.join("_").to_sym
26-
end
27-
end
28-
end
29-
)
30-
31-
expected_actions.each do |action|
32-
it action do
16+
%w[
17+
skip_before_action skip_around_action skip_after_action
18+
append_before_action append_around_action append_after_action
19+
prepend_before_action prepend_around_action prepend_after_action
20+
before_action around_action after_action
21+
].each do |filter|
22+
it filter do
3323
args = [:my_filter, { only: :show }]
34-
controllers.each { |c| expect(c).to receive(action).with(args) }
35-
application.public_send action, args
24+
controllers.each { |c| expect(c).to receive(filter).with(args) }
25+
application.public_send filter, args
3626
end
3727
end
3828
end

spec/unit/resource_spec.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,20 @@ def method_missing(name, *args, &block)
324324
expect(resource).to receive(:controller).and_return(controller)
325325
end
326326

327-
context "actions" do
328-
[
329-
:before_action, :skip_before_action,
330-
:after_action, :skip_after_action,
331-
:around_action, :skip_action
332-
].each do |method|
333-
it "delegates #{method}" do
334-
expect(resource.send(method)).to eq "called #{method}"
335-
end
327+
%w[
328+
before_build after_build
329+
before_create after_create
330+
before_update after_update
331+
before_save after_save
332+
before_destroy after_destroy
333+
skip_before_action skip_around_action skip_after_action
334+
append_before_action append_around_action append_after_action
335+
prepend_before_action prepend_around_action prepend_after_action
336+
before_action around_action after_action
337+
actions
338+
].each do |method|
339+
it "delegates #{method}" do
340+
expect(resource.send(method)).to eq "called #{method}"
336341
end
337342
end
338343
end

0 commit comments

Comments
 (0)
0