Fix duplicate activity stream posts

This commit is contained in:
Steffen van Bergerem 2016-08-07 02:07:05 +02:00
parent f91734028c
commit ba26175421
No known key found for this signature in database
GPG key ID: 2F08F75F9525C7E0
2 changed files with 11 additions and 1 deletions

View file

@ -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

View file

@ -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])