From aa4d428ab78ac3be12c04f8bafb0afd655968a3a Mon Sep 17 00:00:00 2001
From: Raphael <raphael@joindiaspora.com>
Date: Tue, 10 Aug 2010 11:02:04 -0700
Subject: [PATCH] RS, DG; Groups can now include other users, the user's first
 group is displayed by default, never use many without :in =>

---
 app/controllers/application_controller.rb |  2 +-
 app/models/group.rb                       |  4 +++-
 db/seeds/tom.rb                           | 11 +++++++++++
 spec/models/group_spec.rb                 | 23 +++++++++++++++++++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c36ebc0b31..18e1280df3 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
       @groups = current_user.groups 
       @friends = current_user.friends
       @latest_status_message = StatusMessage.newest_for(current_user)
-      @group = params[:group] ? Group.first(:id => params[:group]) : Group.first
+      @group = params[:group] ? current_user.groups.first(:id => params[:group]) : current_user.groups.first 
     end
   end
 
diff --git a/app/models/group.rb b/app/models/group.rb
index 885e471ccd..5c228448dc 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -3,7 +3,9 @@ class Group
   
   key :name, String
 
-  many :people, :class_name => 'Person'
+  key :person_ids, Array
+
+  many :people, :in => :person_ids, :class_name => 'Person'
   belongs_to :user, :class_name => 'User'
 
   timestamps!
diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb
index 17b9375ca9..c716ad8fab 100644
--- a/db/seeds/tom.rb
+++ b/db/seeds/tom.rb
@@ -24,4 +24,15 @@ user2 = User.create( :email => "korth@tom.joindiaspora.com",
                                           :url => "http://tom.joindiaspora.com/", 
                                           :profile => Profile.new( :first_name => "Evan",
                                                                   :last_name => "Korth")))
+
 user2.person.save
+
+# friending users
+user.friends << user2.person
+user.group(:name => "other dudes", :people => [user2.person])
+user.save
+
+user2.friends << user.person
+user2.group(:name => "some dudes", :people => [user.person])
+user2.save
+
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index a40a9be118..1d0f400d5f 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -4,6 +4,8 @@ describe Group do
   before do
     @user = Factory.create(:user)
     @friend = Factory.create(:person)
+    @user2 = Factory.create(:user)
+    @friend_2 = Factory.create(:person)
   end
 
   describe 'creation' do
@@ -11,6 +13,27 @@ describe Group do
       group = @user.group(:name => 'losers')
       group.name.should == "losers"
     end
+
+    it 'should be able to have people' do
+      group = @user.group(:name => 'losers', :people => [@friend, @friend_2])
+      group.people.size.should == 2
+    end
+
+    it 'should be able to have other users' do
+      group = @user.group(:name => 'losers', :people => [@user2.person])
+      group.people.include?(@user.person).should be false
+      group.people.include?(@user2.person).should be true 
+      group.people.size.should == 1
+    end   
+
+    it 'should be able to have users and people' do
+      group = @user.group(:name => 'losers', :people => [@user2.person, @friend_2])
+      group.people.include?(@user.person).should be false
+      group.people.include?(@user2.person).should be true 
+      group.people.include?(@friend_2).should be true 
+      group.people.size.should == 2
+    end
+
   end
   
   describe 'querying' do
-- 
GitLab