@@ -8,7 +8,7 @@ module Rails
8
8
class IndexingEnhancementTest < ActiveSupport ::TestCase
9
9
class << self
10
10
# For these tests, it's convenient to have the index fully populated with Rails information, but we don't have
11
- # to reindex on every single example or that will be too slow
11
+ # to re-index on every single example or that will be too slow
12
12
def populated_index
13
13
@index ||= begin
14
14
index = RubyIndexer ::Index . new
@@ -20,22 +20,77 @@ def populated_index
20
20
21
21
def setup
22
22
@index = self . class . populated_index
23
+ @indexable_path = RubyIndexer ::IndexablePath . new ( nil , "/fake.rb" )
24
+ end
25
+
26
+ def teardown
27
+ # Prevent state leaking between tests
28
+ @index . delete ( @indexable_path )
29
+ @index . instance_variable_set ( :@ancestors , { } )
23
30
end
24
31
25
32
test "ClassMethods module inside concerns are automatically extended" do
26
- @index . index_single ( RubyIndexer ::IndexablePath . new ( nil , "/fake.rb" ) , <<~RUBY )
27
- class Post < ActiveRecord::Base
33
+ @index . index_single ( @indexable_path , <<~RUBY )
34
+ module Verifiable
35
+ extend ActiveSupport::Concern
36
+
37
+ module ClassMethods
38
+ def all_verified; end
39
+ end
40
+ end
41
+
42
+ class Post
43
+ include Verifiable
28
44
end
29
45
RUBY
30
46
31
47
ancestors = @index . linearized_ancestors_of ( "Post::<Class:Post>" )
32
- assert_includes ( ancestors , "ActiveRecord::Associations::ClassMethods" )
33
- assert_includes ( ancestors , "ActiveRecord::Store::ClassMethods" )
34
- assert_includes ( ancestors , "ActiveRecord::AttributeMethods::ClassMethods" )
48
+
49
+ assert_includes ( ancestors , "Verifiable::ClassMethods" )
50
+ refute_nil ( @index . resolve_method ( "all_verified" , "Post::<Class:Post>" ) )
51
+ end
52
+
53
+ test "class_methods blocks inside concerns are automatically extended via a ClassMethods module" do
54
+ @index . index_single ( @indexable_path , <<~RUBY )
55
+ module Verifiable
56
+ extend ActiveSupport::Concern
57
+
58
+ class_methods do
59
+ def all_verified; end
60
+ end
61
+ end
62
+
63
+ class Post
64
+ include Verifiable
65
+ end
66
+ RUBY
67
+
68
+ ancestors = @index . linearized_ancestors_of ( "Post::<Class:Post>" )
69
+
70
+ assert_includes ( ancestors , "Verifiable::ClassMethods" )
71
+ refute_nil ( @index . resolve_method ( "all_verified" , "Post::<Class:Post>" ) )
72
+ end
73
+
74
+ test "ignores `class_methods` calls without a block" do
75
+ @index . index_single ( @indexable_path , <<~RUBY )
76
+ module Verifiable
77
+ extend ActiveSupport::Concern
78
+
79
+ class_methods
80
+ end
81
+
82
+ class Post
83
+ include Verifiable
84
+ end
85
+ RUBY
86
+
87
+ ancestors = @index . linearized_ancestors_of ( "Post::<Class:Post>" )
88
+
89
+ refute_includes ( ancestors , "Verifiable::ClassMethods" )
35
90
end
36
91
37
92
test "associations" do
38
- @index . index_single ( RubyIndexer :: IndexablePath . new ( nil , "/fake.rb" ) , <<~RUBY )
93
+ @index . index_single ( @indexable_path , <<~RUBY )
39
94
class Post < ActiveRecord::Base
40
95
has_one :content
41
96
belongs_to :author
0 commit comments