Participate stream query uses participations

This commit is contained in:
Dennis Collinson 2012-02-09 16:42:26 -08:00
parent 14b9f5dc5b
commit 5e26a7e6bb
3 changed files with 60 additions and 5 deletions

View file

@ -44,7 +44,7 @@ class Person < ActiveRecord::Base
has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts
has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos
has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments
has_many :participations, :through => :posts, :foreign_key => :author_id, :dependent => :destroy has_many :participations, :foreign_key => :author_id, :dependent => :destroy
belongs_to :owner, :class_name => 'User' belongs_to :owner, :class_name => 'User'

View file

@ -17,10 +17,7 @@ module EvilQuery
end end
def posts def posts
# Post.joins(:participations).where(:participations => {:author_id => @user.id}).order("posts.interacted_at DESC") Post.joins(:participations).where(:participations => {:author_id => @user.person.id}).order("posts.interacted_at DESC")
liked_post_ids = fetch_ids!(LikedPosts.new(@user).posts, "posts.id")
commented_post_ids = fetch_ids!(CommentedPosts.new(@user).posts, "posts.id")
Post.where(:id => liked_post_ids + commented_post_ids).order("posts.interacted_at DESC")
end end
end end

View file

@ -1,12 +1,70 @@
require "spec_helper" require "spec_helper"
describe User::SocialActions do describe User::SocialActions do
before do
@bobs_aspect = bob.aspects.where(:name => "generic").first
@status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id)
end
describe 'User#comment!' do
it "sets the comment text" do
alice.comment!(@status, "unicorn_mountain").text.should == "unicorn_mountain"
end
it "creates a partcipation" do
lambda{ alice.comment!(@status, "bro") }.should change(Participation, :count).by(1)
alice.participations.last.target.should == @status
end
it "creates the like" do
lambda{ alice.comment!(@status, "bro") }.should change(Comment, :count).by(1)
end
it "federates" do
Participation::Generator.any_instance.stub(:create!)
Postzord::Dispatcher.should_receive(:defer_build_and_post)
alice.comment!(@status, "omg")
end
end
describe 'User#like!' do
it "creates a partcipation" do
lambda{ alice.like!(@status) }.should change(Participation, :count).by(1)
alice.participations.last.target.should == @status
end
it "creates the like" do
lambda{ alice.like!(@status) }.should change(Like, :count).by(1)
end
it "federates" do
#participation and like
Participation::Generator.any_instance.stub(:create!)
Postzord::Dispatcher.should_receive(:defer_build_and_post)
alice.like!(@status)
end
end
describe 'User#like!' do describe 'User#like!' do
before do before do
@bobs_aspect = bob.aspects.where(:name => "generic").first @bobs_aspect = bob.aspects.where(:name => "generic").first
@status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id) @status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id)
end end
it "creates a partcipation" do
lambda{ alice.like!(@status) }.should change(Participation, :count).by(1)
end
it "creates the like" do
lambda{ alice.like!(@status) }.should change(Like, :count).by(1)
end
it "federates" do
#participation and like
Postzord::Dispatcher.should_receive(:defer_build_and_post).twice
alice.like!(@status)
end
it "should be able to like on one's own status" do it "should be able to like on one's own status" do
like = alice.like!(@status) like = alice.like!(@status)
@status.reload.likes.first.should == like @status.reload.likes.first.should == like