这是我的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测试(它失败了)。有没有办法为上面写一个测试?我可以将其转换为实例方法并对其进行测试,但是试图让它具有has_many
范围。
it { should have_many(:managed_athletes).class_name "Athlete" }