File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -384,8 +384,8 @@ def inherited(subclass)
384
384
@arel_table = nil
385
385
@predicate_builder = nil
386
386
@inspection_filter = nil
387
- @filter_attributes = nil
388
- @generated_association_methods = nil
387
+ @filter_attributes || = nil
388
+ @generated_association_methods || = nil
389
389
end
390
390
end
391
391
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "cases/helper"
4
+
5
+ module Inherited
6
+ # When running the test with `RAILS_STRICT_WARNINGS` enabled, the `belongs_to`
7
+ # call should not emit a warning that the constant `GeneratedAssociationMethods`
8
+ # is already defined.
9
+ class Person < ActiveRecord ::Base ; end
10
+
11
+ class Device < ActiveRecord ::Base
12
+ def self . inherited ( subclass )
13
+ subclass . belongs_to :person , inverse_of : subclass . name . demodulize . tableize . to_sym
14
+ subclass . filter_attributes = [ :secret_attribute , :"#{ subclass . name . demodulize . downcase } _key" ]
15
+ super
16
+ end
17
+ end
18
+
19
+ class Computer < Device ; end
20
+
21
+ class Vehicle < ActiveRecord ::Base
22
+ def self . inherited ( subclass )
23
+ super
24
+ subclass . belongs_to :person , inverse_of : subclass . name . demodulize . tableize . to_sym
25
+ subclass . filter_attributes = [ :secret_attribute , :"#{ subclass . name . demodulize . downcase } _key" ]
26
+ end
27
+ end
28
+
29
+ class Car < Vehicle ; end
30
+ end
31
+
32
+ class InheritedTest < ActiveRecord ::TestCase
33
+ def test_super_before_filter_attributes
34
+ assert_equal %i[ secret_attribute car_key ] , Inherited ::Car . filter_attributes
35
+ end
36
+
37
+ def test_super_after_filter_attributes
38
+ assert_equal %i[ secret_attribute computer_key ] , Inherited ::Computer . filter_attributes
39
+ end
40
+ end
You can’t perform that action at this time.
0 commit comments