From 8fddb4ecf5837f6c787558d81535612c6c437c9b Mon Sep 17 00:00:00 2001
From: ilya <ilya@laptop.(none)>
Date: Wed, 20 Oct 2010 13:19:32 -0700
Subject: [PATCH] MS IZ added test concerning people in multiple aspects

---
 lib/diaspora/user/querying.rb               |  3 +--
 spec/controllers/aspects_controller_spec.rb | 17 ++++++++++---
 spec/models/aspect_spec.rb                  | 27 +++++++++++++++------
 spec/models/user/posting_spec.rb            |  5 +++-
 4 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb
index eae34862b7..63cbfba171 100644
--- a/lib/diaspora/user/querying.rb
+++ b/lib/diaspora/user/querying.rb
@@ -44,8 +44,7 @@ module Diaspora
       end
 
       def aspects_with_person person
-        id = person.id.to_id
-        aspects.select { |g| g.person_ids.include? id}
+        aspects.all(:person_ids => person.id)
       end
 
       def people_in_aspects aspects
diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb
index 81571fb547..f6d08e42bc 100644
--- a/spec/controllers/aspects_controller_spec.rb
+++ b/spec/controllers/aspects_controller_spec.rb
@@ -8,11 +8,11 @@ describe AspectsController do
   render_views
 
   before do
-    @user = Factory.create(:user)
-    @user.aspect(:name => "lame-os")
-    @person = Factory.create(:person)
+    @user    = Factory.create(:user)
+    @aspect  = @user.aspect(:name => "lame-os")
+    @person  = Factory.create(:person)
     sign_in :user, @user
-  end
+end
 
   describe "#index" do
     it "assigns @friends to all the user's friends" do
@@ -46,4 +46,13 @@ describe AspectsController do
       end
     end
   end
+
+  describe "#move_friend" do
+    let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}}
+    it 'calls the move_friend_method' do
+      pending "need to figure out how to stub current_user to return our test @user"
+      @user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id")
+      post :move_friend, opts
+    end
+  end
 end
diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb
index 9e6d01200c..e52a42e7df 100644
--- a/spec/models/aspect_spec.rb
+++ b/spec/models/aspect_spec.rb
@@ -79,13 +79,26 @@ describe Aspect do
       aspect.people.size.should == 2
     end
 
-    it 'should be accessible through the user' do
-      aspects = user.aspects_with_person(friend)
-      aspects.size.should == 1
-      aspects.first.id.should == aspect.id
-      aspects.first.people.size.should == 2
-      aspects.first.people.include?(friend).should be true
-      aspects.first.people.include?(user2.person).should be true
+    describe '#aspects_with_person' do
+      let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")}
+      it 'should return the aspects with given friend' do
+        aspects = user.aspects_with_person(friend)
+        aspects.size.should == 1
+        aspects.first.id.should == aspect.id
+        aspects.first.people.size.should == 2
+        aspects.first.people.include?(friend).should be true
+        aspects.first.people.include?(user2.person).should be true
+      end
+
+      it 'returns multiple aspects if the person is there' do
+        user.reload
+        user.add_person_to_aspect(friend.id, aspect1.id)
+        aspects = user.aspects_with_person(friend)
+        aspects.count.should == 2
+        aspects.each{ |asp| asp.people.include?(friend) }
+        aspects.should_not include aspect_without_friend
+      end
+
     end
   end
 
diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb
index 7b6913c0cb..70438bbece 100644
--- a/spec/models/user/posting_spec.rb
+++ b/spec/models/user/posting_spec.rb
@@ -72,6 +72,8 @@ describe User do
       friend_users(user, aspect, user2, aspect2)
       friend_users(user, aspect, user3, aspect3)
       friend_users(user, aspect1, user4, aspect4)
+      user.add_person_to_aspect(user2.person.id, aspect1.id)
+      user.reload
     end
 
     describe '#push_to_aspects' do
@@ -80,7 +82,7 @@ describe User do
         user.push_to_aspects(post, aspect.id)
       end
 
-      it 'should push a post to all aspects' do
+      it 'should push a post to friends in all aspects' do
         user.should_receive(:push_to_person).exactly(3).times
         user.push_to_aspects(post, :all)
       end
@@ -92,5 +94,6 @@ describe User do
         user.push_to_people(post, [user2.person, user3.person])
       end
     end
+
   end
 end
-- 
GitLab