@@ -52,6 +52,32 @@ class Organization < ActiveRecord::Base
52
52
assert_equal ( 2 , response [ 0 ] . range . end . line )
53
53
end
54
54
55
+ test "recognizes has_many :through model associations" do
56
+ response = generate_definitions_for_source ( <<~RUBY , { line : 4 , character : 29 } )
57
+ # typed: false
58
+
59
+ class Organization < ActiveRecord::Base
60
+ has_many :memberships
61
+ has_many :users, through: :memberships
62
+ end
63
+ RUBY
64
+
65
+ assert_equal ( 2 , response . size )
66
+
67
+ assert_equal (
68
+ URI ::Generic . from_path ( path : File . join ( dummy_root , "app" , "models" , "user.rb" ) ) . to_s ,
69
+ response [ 0 ] . uri ,
70
+ )
71
+ assert_equal (
72
+ URI ::Generic . from_path ( path : File . join ( dummy_root , "app" , "models" , "membership.rb" ) ) . to_s ,
73
+ response [ 1 ] . uri ,
74
+ )
75
+ assert_equal ( 2 , response [ 0 ] . range . start . line )
76
+ assert_equal ( 2 , response [ 0 ] . range . end . line )
77
+ assert_equal ( 2 , response [ 1 ] . range . start . line )
78
+ assert_equal ( 2 , response [ 1 ] . range . end . line )
79
+ end
80
+
55
81
test "recognizes belongs_to model associations" do
56
82
response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 14 } )
57
83
# typed: false
@@ -90,6 +116,32 @@ class User < ActiveRecord::Base
90
116
assert_equal ( 2 , response [ 0 ] . range . end . line )
91
117
end
92
118
119
+ test "recognizes has_one :through model associations" do
120
+ response = generate_definitions_for_source ( <<~RUBY , { line : 4 , character : 35 } )
121
+ # typed: false
122
+
123
+ class User < ActiveRecord::Base
124
+ belongs_to :location, class_name: "Country"
125
+ has_one :country_flag, through: :location, source: :flag
126
+ end
127
+ RUBY
128
+
129
+ assert_equal ( 2 , response . size )
130
+
131
+ assert_equal (
132
+ URI ::Generic . from_path ( path : File . join ( dummy_root , "app" , "models" , "flag.rb" ) ) . to_s ,
133
+ response [ 0 ] . uri ,
134
+ )
135
+ assert_equal (
136
+ URI ::Generic . from_path ( path : File . join ( dummy_root , "app" , "models" , "country.rb" ) ) . to_s ,
137
+ response [ 1 ] . uri ,
138
+ )
139
+ assert_equal ( 2 , response [ 0 ] . range . start . line )
140
+ assert_equal ( 2 , response [ 0 ] . range . end . line )
141
+ assert_equal ( 2 , response [ 1 ] . range . start . line )
142
+ assert_equal ( 2 , response [ 1 ] . range . end . line )
143
+ end
144
+
93
145
test "recognizes has_and_belongs_to_many model associations" do
94
146
response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 27 } )
95
147
# typed: false
@@ -110,11 +162,11 @@ class Profile < ActiveRecord::Base
110
162
end
111
163
112
164
test "handles class_name argument for associations" do
113
- response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 11 } )
165
+ response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 14 } )
114
166
# typed: false
115
167
116
168
class User < ActiveRecord::Base
117
- has_one :location, class_name: "Country"
169
+ belongs_to :location, class_name: "Country"
118
170
end
119
171
RUBY
120
172
0 commit comments