1

这是我的has_many声明:

  has_many :managed_athletes, class_name: "Athlete",
            finder_sql: ->(record) do
              record = self if record.nil?
              "SELECT DISTINCT users.* FROM users INNER JOIN contributorships
              ON users.id = contributorships.athlete_id 
              INNER JOIN invitations
              ON users.id = invitations.sender_id
              WHERE users.type IN ('Athlete') AND contributorships.user_id = #{record.id} 
              AND invitations.requester_id = #{record.id}
              AND (invitations.current_state = 'accepted')"
            end

这是我的 Rspec 测试(失败了)。有没有办法为上述编写测试?我可以把它变成一个实例方法并对其进行测试,但试图让 this 有一个has_many范围。

it { should have_many(:managed_athletes).class_name "Athlete" }
4

0 回答 0