Skip to content

Commit ee99633

Browse files
committed
Patch administrate to avoid incorrect deprecation
Previously I was seeing many instances of the following deprecation warning when running `spec/features/admin/schools_spec.rb` which was cluttering up the build output making it hard to see genuine problems: DEPRECATION WARNING: The option :class_name is deprecated. Administrate should detect it automatically. This was because when the automatic associations functionality [1] was added to administrate in v0.15.0, the `class_name` option on `Administrate::Field::Associative#associated_class_name` which is the superclass for `Administrate::Field::BelongsTo`. The latter is used on the `SchoolDashboard` with the `class_name` option [3]. However, in the v1.0.0.beta3 release of administrate [4], this deprecation was reversed [4]. So we could avoid the deprecation by upgrading administrate. However, since it's a major version bump, it's like to be a chunk of work. So instead I've patched this specific functionality to avoid the deprecation warning. The patch includes code which will fail fast once administrate is updated to v1.0.0.beta3 or later so that the patch can be removed. [1]: thoughtbot/administrate#1633 [2]: https://github.com/thoughtbot/administrate/blob/f7287410a93d07f222bd5d4fb5055c6937eace08/CHANGELOG.md#0150-february-26-2021 [3]: https://github.com/RaspberryPiFoundation/editor-api/blob/f397e870f2a33cce1f53b9104c52314f5233572c/app/dashboards/school_dashboard.rb#L14 [4]: thoughtbot/administrate#2697
1 parent 79f316c commit ee99633

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require 'administrate/field/associative'
4+
5+
module Administrate
6+
module Field
7+
class Associative < Base
8+
module Overrides
9+
def deprecated_option(name)
10+
name == :class_name ? options.fetch(name) : super
11+
end
12+
end
13+
end
14+
end
15+
end
16+
17+
# Ref: https://github.com/thoughtbot/administrate/commit/f9c5f1af0bd27dbe8e98d43b2074b96004689ad5
18+
patch_no_longer_required = Gem::Version.new(Administrate::VERSION) >= Gem::Version.new('1.0.0.beta3')
19+
raise 'Administrate::Field::Associative::Overrides patch is no longer required' if patch_no_longer_required
20+
21+
Administrate::Field::Associative.prepend(Administrate::Field::Associative::Overrides)

0 commit comments

Comments
 (0)