Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider fca6121c rédigé par cmrd Senya's avatar cmrd Senya
Parcourir les fichiers

Exporter::PostsWithActivity class

This class allows to query posts where a person made any activity (submitted comments,
likes, participations or poll participations).
parent 7db4f825
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -19,6 +19,7 @@ class StatusMessage < Post ...@@ -19,6 +19,7 @@ class StatusMessage < Post
has_one :location has_one :location
has_one :poll, autosave: true has_one :poll, autosave: true
has_many :poll_participations, through: :poll
attr_accessor :oembed_url attr_accessor :oembed_url
attr_accessor :open_graph_url attr_accessor :open_graph_url
......
module Diaspora
class Exporter
# This class allows to query posts where a person made any activity (submitted comments,
# likes, participations or poll participations).
class PostsWithActivity
# TODO: docs
def initialize(user)
@user = user
end
# TODO: docs
def query
Post.from("(#{sql_union_all_activities}) AS posts")
end
private
attr_reader :user
def person
user.person
end
def sql_union_all_activities
all_activities.map(&:to_sql).join(" UNION ")
end
def all_activities
[comments_activity, likes_activity, subscriptions, polls_activity].compact
end
def likes_activity
other_people_posts.liked_by(person)
end
def comments_activity
other_people_posts.commented_by(person)
end
def subscriptions
other_people_posts.subscribed_by(user)
end
def polls_activity
StatusMessage.where.not(author_id: person.id).joins(:poll_participations)
.where(poll_participations: {author_id: person.id})
end
def other_people_posts
Post.where.not(author_id: person.id)
end
end
end
end
describe Diaspora::Exporter::PostsWithActivity do
let(:user) { FactoryGirl.create(:user) }
let(:instance) { Diaspora::Exporter::PostsWithActivity.new(user) }
describe "#query" do
let(:activity) {
[
user.person.likes.first.target,
user.person.comments.first.parent,
user.person.poll_participations.first.parent.status_message,
user.person.participations.first.target
]
}
before do
DataGenerator.create(user, %i[activity participation])
end
it "returns all posts with person's activity" do
expect(instance.query).to match_array(activity)
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter