diff --git a/lib/evil_query.rb b/lib/evil_query.rb index 728bc6595..78599ead1 100644 --- a/lib/evil_query.rb +++ b/lib/evil_query.rb @@ -24,6 +24,7 @@ module EvilQuery "participations.target_type = 'Post'") .where(::Participation.arel_table[:author_id].eq(author_id).or(Post.arel_table[:author_id].eq(author_id))) .order("posts.interacted_at DESC") + .distinct end end diff --git a/spec/lib/evil_query_spec.rb b/spec/lib/evil_query_spec.rb index 731c94979..744877034 100644 --- a/spec/lib/evil_query_spec.rb +++ b/spec/lib/evil_query_spec.rb @@ -90,7 +90,6 @@ describe EvilQuery::Participation do describe "multiple participations" do before do - @status_message = FactoryGirl.create(:status_message, author: bob.person) @like = alice.like!(@status_message) @comment = alice.comment!(@status_message, "party") end @@ -101,6 +100,16 @@ describe EvilQuery::Participation do expect(posts.map(&:id)).to eq([@status_message.id]) end + it "includes Posts with multiple participations only once" do + eve.like!(@status_message) + expect(posts.count).to be(1) + end + + it "includes Posts with multiple participations only once for the post author" do + eve.like!(@status_message) + expect(EvilQuery::Participation.new(bob).posts.count).to eq(1) + end + it "includes Posts with multiple participation after removing one participation" do @like.destroy expect(posts.map(&:id)).to eq([@status_message.id])