@@ -52,6 +52,32 @@ class Organization < ActiveRecord::Base
5252 assert_equal ( 2 , response [ 0 ] . range . end . line )
5353 end
5454
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+
5581 test "recognizes belongs_to model associations" do
5682 response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 14 } )
5783 # typed: false
@@ -90,6 +116,32 @@ class User < ActiveRecord::Base
90116 assert_equal ( 2 , response [ 0 ] . range . end . line )
91117 end
92118
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+
93145 test "recognizes has_and_belongs_to_many model associations" do
94146 response = generate_definitions_for_source ( <<~RUBY , { line : 3 , character : 27 } )
95147 # typed: false
0 commit comments