Skip to content

Commit 839ece3

Browse files
authored
Remove deprecated code (thoughtbot#2832)
Before going into v1.0, we should shed deprecated APIs that we have supported for back-compatibility: * Remove deprecated APIs * Remove specs of removed APIs * Remove docs on removed APIs
1 parent 46ad572 commit 839ece3

File tree

16 files changed

+20
-460
lines changed

16 files changed

+20
-460
lines changed

app/controllers/administrate/application_controller.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ def existing_action?(resource, action_name)
122122
end
123123
helper_method :existing_action?
124124

125-
# @deprecated Use {#existing_action} instead. Note that, in
126-
# {#existing_action}, the order of parameters is reversed and
127-
# there is no default value for the `resource` parameter.
128-
def valid_action?(action_name, resource = resource_class)
129-
Administrate.warn_of_deprecated_authorization_method(__method__)
130-
existing_action?(resource, action_name)
131-
end
132-
helper_method :valid_action?
133-
134125
def routes
135126
@routes ||= Namespace.new(namespace).routes.to_set
136127
end
@@ -265,14 +256,6 @@ def authorized_action?(_resource, _action_name)
265256
end
266257
helper_method :authorized_action?
267258

268-
# @deprecated Use {#authorized_action} instead. Note that the order of
269-
# parameters is reversed in {#authorized_action}.
270-
def show_action?(action, resource)
271-
Administrate.warn_of_deprecated_authorization_method(__method__)
272-
authorized_action?(resource, action)
273-
end
274-
helper_method :show_action?
275-
276259
def new_resource(params = {})
277260
resource_class.new(params)
278261
end

app/controllers/concerns/administrate/punditize.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,7 @@ def policy_scope!(user, scope)
4141
"Invalid #<#{policy_scope_class}> constructor is called")
4242
end
4343

44-
if policy_scope.respond_to? :resolve_admin
45-
Administrate.deprecator.warn(
46-
"Pundit policy scope `resolve_admin` method is deprecated. " \
47-
"Please use a namespaced pundit policy instead."
48-
)
49-
policy_scope.resolve_admin
50-
else
51-
policy_scope.resolve
52-
end
44+
policy_scope.resolve
5345
end
5446

5547
def pundit_model(record)

docs/customizing_dashboards.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ If neither is specified, sorting will be done using the foreign key.
115115

116116
`:class_name` - Specifies the name of the associated class.
117117

118-
`:primary_key` (deprecated) - Specifies the association's primary_key.
119-
120-
`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
121-
122118
**Field::HasMany**
123119

124120
`:collection_attributes` - Set the columns to display in the show view.
@@ -141,10 +137,6 @@ For `HasMany` associations, sorting is based on the count, so this option is not
141137

142138
`:class_name` - Specifies the name of the associated class.
143139

144-
`:primary_key` (deprecated) - Specifies object's primary_key.
145-
146-
`:foreign_key` (deprecated) - Specifies the name of the foreign key directly.
147-
148140
**Field::HasOne**
149141

150142
`:order` - Specifies the column used to order the records. It will apply both in

lib/administrate.rb

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,6 @@
22
require "administrate/version"
33

44
module Administrate
5-
def self.warn_of_missing_resource_class
6-
deprecator.warn(
7-
"Calling Field::Base.permitted_attribute without the option " \
8-
":resource_class is deprecated. If you are seeing this " \
9-
"message, you are probably using a custom field type that" \
10-
"does this. Please make sure to update it to a version that " \
11-
"does not use a deprecated API"
12-
)
13-
end
14-
15-
def self.warn_of_deprecated_option(name)
16-
deprecator.warn(
17-
"The option :#{name} is deprecated. " \
18-
"Administrate should detect it automatically. " \
19-
"Please file an issue at " \
20-
"https://github.com/thoughtbot/administrate/issues " \
21-
"if you think otherwise."
22-
)
23-
end
24-
25-
def self.warn_of_deprecated_method(klass, method)
26-
deprecator.warn(
27-
"The method #{klass}##{method} is deprecated. " \
28-
"If you are seeing this message you are probably " \
29-
"using a dashboard that depends explicitly on it. " \
30-
"Please make sure you update it to a version that " \
31-
"does not use a deprecated API"
32-
)
33-
end
34-
35-
def self.warn_of_deprecated_authorization_method(method)
36-
deprecator.warn(
37-
"The method `#{method}` is deprecated. " \
38-
"Please use `accessible_action?` instead, " \
39-
"or see the documentation for other options."
40-
)
41-
end
42-
435
def self.deprecator
446
@deprecator ||= ActiveSupport::Deprecation.new(VERSION, "Administrate")
457
end

lib/administrate/base_dashboard.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ def collection_includes
111111
attribute_includes(collection_attributes)
112112
end
113113

114-
def item_includes
115-
# Deprecated, internal usage has moved to #item_associations
116-
Administrate.warn_of_deprecated_method(self.class, :item_includes)
117-
attribute_includes(show_page_attributes)
118-
end
119-
120114
def item_associations
121115
attributes = if show_page_attributes.is_a?(Hash)
122116
show_page_attributes.values.flatten

lib/administrate/field/associative.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,17 @@ def associated_dashboard
5656
"#{associated_class_name}Dashboard".constantize.new
5757
end
5858

59-
def primary_key
60-
# Deprecated, renamed `association_primary_key`
61-
Administrate.warn_of_deprecated_method(self.class, :primary_key)
62-
association_primary_key
63-
end
64-
6559
def association_primary_key
66-
if option_given?(:primary_key)
67-
deprecated_option(:primary_key)
68-
else
69-
self.class.association_primary_key_for(resource.class, attribute)
70-
end
60+
self.class.association_primary_key_for(resource.class, attribute)
7161
end
7262

7363
def foreign_key
74-
if option_given?(:foreign_key)
75-
deprecated_option(:foreign_key)
76-
else
77-
self.class.foreign_key_for(resource.class, attribute)
78-
end
64+
self.class.foreign_key_for(resource.class, attribute)
7965
end
8066

8167
def option_given?(name)
8268
options.key?(name)
8369
end
84-
85-
def deprecated_option(name)
86-
Administrate.warn_of_deprecated_option(name)
87-
options.fetch(name)
88-
end
8970
end
9071
end
9172
end

lib/administrate/field/belongs_to.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ module Field
55
class BelongsTo < Associative
66
def self.permitted_attribute(attr, options = {})
77
resource_class = options[:resource_class]
8-
if resource_class
9-
foreign_key_for(resource_class, attr)
10-
else
11-
Administrate.warn_of_missing_resource_class
12-
:"#{attr}_id"
13-
end
8+
foreign_key_for(resource_class, attr)
149
end
1510

1611
def self.eager_load?

lib/administrate/field/deferred.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,16 @@ def searchable?
4141
end
4242
end
4343

44-
def searchable_field
45-
Administrate.deprecator.warn(
46-
"searchable_field is deprecated, use searchable_fields instead"
47-
)
48-
options.fetch(:searchable_field)
49-
end
50-
5144
def searchable_fields
52-
if options.key?(:searchable_field)
53-
[searchable_field]
54-
else
55-
options.fetch(:searchable_fields)
56-
end
45+
options.fetch(:searchable_fields)
5746
end
5847

5948
def sortable?
6049
options.fetch(:sortable, deferred_class.sortable?)
6150
end
6251

6352
def permitted_attribute(attr, opts = {})
64-
if options.key?(:foreign_key)
65-
Administrate.warn_of_deprecated_option(:foreign_key)
66-
options.fetch(:foreign_key)
67-
else
68-
deferred_class.permitted_attribute(attr, options.merge(opts))
69-
end
53+
deferred_class.permitted_attribute(attr, options.merge(opts))
7054
end
7155

7256
delegate :html_class, to: :deferred_class

lib/administrate/field/has_one.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@ def self.permitted_attribute(attr, options = {})
88
final_associated_class_name =
99
if options.key?(:class_name)
1010
options.fetch(:class_name)
11-
elsif resource_class
12-
associated_class_name(resource_class, attr)
1311
else
14-
Administrate.warn_of_missing_resource_class
15-
if options
16-
attr.to_s.singularize.camelcase
17-
else
18-
attr
19-
end
12+
associated_class_name(resource_class, attr)
2013
end
2114
related_dashboard_attributes =
2215
Administrate::ResourceResolver

spec/controllers/admin/application_controller_spec.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,4 @@ def authorized_action?(resource, _action)
100100
.to raise_error(Administrate::NotAuthorizedError)
101101
end
102102
end
103-
104-
describe "deprecated methods: show_action" do
105-
controller(Administrate::ApplicationController) do
106-
def index
107-
show_action?(:index, Order)
108-
end
109-
end
110-
111-
it "triggers a deprecation warning" do
112-
allow(Administrate.deprecator).to receive(:warn)
113-
get :index
114-
expect(Administrate.deprecator).to(
115-
have_received(:warn)
116-
.with(/`show_action\?` is deprecated/)
117-
)
118-
end
119-
end
120-
121-
describe "deprecated methods: valid_action" do
122-
controller(Administrate::ApplicationController) do
123-
def index
124-
valid_action?(:index, Order)
125-
end
126-
end
127-
128-
it "triggers a deprecation warning" do
129-
allow(Administrate.deprecator).to receive(:warn)
130-
get :index
131-
expect(Administrate.deprecator).to(
132-
have_received(:warn)
133-
.with(/`valid_action\?` is deprecated/)
134-
)
135-
end
136-
end
137103
end

0 commit comments

Comments
 (0)