@@ -321,6 +321,106 @@ class Bar < ApplicationRecord
321321 CONTENT
322322 end
323323
324+ test "returns main association on has_many :through association" do
325+ expected_response = {
326+ location : "#{ dummy_root } /app/models/user.rb:2" ,
327+ name : "User" ,
328+ }
329+ RunnerClient . any_instance . stubs ( association_target : expected_response )
330+
331+ response = hover_on_source ( <<~RUBY , { line : 4 , character : 12 } )
332+ # typed: false
333+
334+ class Organization < ActiveRecord::Base
335+ has_many :memberships
336+ has_many :users, through: :memberships
337+ end
338+ RUBY
339+
340+ assert_equal ( <<~CONTENT . chomp , response . contents . value )
341+ ```ruby
342+ User
343+ ```
344+
345+ **Definitions**: [fake.rb](file:///fake.rb#L2,1-2,4)
346+ CONTENT
347+ end
348+
349+ test "returns main association on has_one :through association" do
350+ expected_response = {
351+ location : "#{ dummy_root } /app/models/flag.rb:2" ,
352+ name : "Flag" ,
353+ }
354+ RunnerClient . any_instance . stubs ( association_target : expected_response )
355+
356+ response = hover_on_source ( <<~RUBY , { line : 4 , character : 19 } )
357+ # typed: false
358+
359+ class User < ActiveRecord::Base
360+ belongs_to :location, class_name: "Country"
361+ has_one :country_flag, through: :location, source: :flag
362+ end
363+ RUBY
364+
365+ assert_equal ( <<~CONTENT . chomp , response . contents . value )
366+ ```ruby
367+ Flag
368+ ```
369+
370+ **Definitions**: [fake.rb](file:///fake.rb#L2,1-2,4)
371+ CONTENT
372+ end
373+
374+ test "returns through association on has_many :through association" do
375+ expected_response = {
376+ location : "#{ dummy_root } /app/models/membership.rb:3" ,
377+ name : "Membership" ,
378+ }
379+ RunnerClient . any_instance . stubs ( association_target : expected_response )
380+
381+ response = hover_on_source ( <<~RUBY , { line : 4 , character : 29 } )
382+ # typed: false
383+
384+ class Organization < ActiveRecord::Base
385+ has_many :memberships
386+ has_many :users, through: :memberships
387+ end
388+ RUBY
389+
390+ assert_equal ( <<~CONTENT . chomp , response . contents . value )
391+ ```ruby
392+ Membership
393+ ```
394+
395+ **Definitions**: [fake.rb](file:///fake.rb#L3,1-3,4)
396+ CONTENT
397+ end
398+
399+ test "returns through association on has_one :through association" do
400+ expected_response = {
401+ location : "#{ dummy_root } /app/models/country.rb:2" ,
402+ name : "Country" ,
403+ }
404+ RunnerClient . any_instance . stubs ( association_target : expected_response )
405+
406+ response = hover_on_source ( <<~RUBY , { line : 4 , character : 35 } )
407+ # typed: false
408+
409+ class User < ActiveRecord::Base
410+ belongs_to :location, class_name: "Country"
411+ has_one :country_flag, through: :location, source: :flag
412+ end
413+ RUBY
414+
415+ assert_equal ( <<~CONTENT . chomp , response . contents . value )
416+ ```ruby
417+ Country
418+ ```
419+
420+ **Definitions**: [fake.rb](file:///fake.rb#L2,1-2,4)
421+ CONTENT
422+ end
423+
324424 private
325425
326426 def hover_on_source ( source , position )
0 commit comments