diff --git a/app/models/person.rb b/app/models/person.rb index a2fa97ec0..48b768f08 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -44,7 +44,7 @@ class Person < ActiveRecord::Base 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 :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' diff --git a/lib/evil_query.rb b/lib/evil_query.rb index 0b91d6793..113890c3b 100644 --- a/lib/evil_query.rb +++ b/lib/evil_query.rb @@ -17,10 +17,7 @@ module EvilQuery end def posts -# Post.joins(:participations).where(:participations => {:author_id => @user.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") + Post.joins(:participations).where(:participations => {:author_id => @user.person.id}).order("posts.interacted_at DESC") end end diff --git a/spec/models/user/social_actions_spec.rb b/spec/models/user/social_actions_spec.rb index d300a14c7..a9a88078b 100644 --- a/spec/models/user/social_actions_spec.rb +++ b/spec/models/user/social_actions_spec.rb @@ -1,12 +1,70 @@ require "spec_helper" 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 before do @bobs_aspect = bob.aspects.where(:name => "generic").first @status = bob.post(:status_message, :text => "hello", :to => @bobs_aspect.id) 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 like = alice.like!(@status) @status.reload.likes.first.should == like