DG MS; person specs are now passing. retraction on unfriend is now uncommented
This commit is contained in:
parent
42c0b82068
commit
4827953bec
3 changed files with 20 additions and 37 deletions
|
|
@ -14,11 +14,11 @@ class Person
|
|||
key :key_fingerprint, String
|
||||
|
||||
key :owner_id, ObjectId
|
||||
key :user_refs, Integer, :default => 0
|
||||
|
||||
belongs_to :owner, :class_name => 'User'
|
||||
one :profile, :class_name => 'Profile'
|
||||
|
||||
many :users, :class_name => 'User'
|
||||
many :posts, :class_name => 'Post', :foreign_key => :person_id
|
||||
many :albums, :class_name => 'Album', :foreign_key => :person_id
|
||||
|
||||
|
|
@ -49,9 +49,6 @@ class Person
|
|||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
######## Posting ########
|
||||
def post(class_name, options = {})
|
||||
options[:person] = self
|
||||
|
|
|
|||
|
|
@ -4,15 +4,17 @@ class User
|
|||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
#before_validation_on_create :assign_key
|
||||
|
||||
before_validation :do_bad_things
|
||||
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
|
||||
key :friend_ids, Array
|
||||
key :pending_friend_ids, Array
|
||||
|
||||
many :friends, :class_name => 'Person'
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
many :friends, :in => :friend_ids, :class_name => 'Person'
|
||||
|
||||
#before_validation_on_create :assign_key
|
||||
before_validation :do_bad_things
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def pending_friends
|
||||
|
|
@ -24,8 +26,6 @@ class User
|
|||
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
######### Friend Requesting
|
||||
|
|
@ -71,26 +71,13 @@ class User
|
|||
def unfriend(friend_id)
|
||||
bad_friend = Person.first(:_id => friend_id)
|
||||
|
||||
|
||||
puts bad_friend.users.count
|
||||
puts self.friends.inspect
|
||||
|
||||
self.friends.delete( friend_id )
|
||||
self.friend_ids.delete( friend_id )
|
||||
self.save
|
||||
|
||||
bad_friend.users.delete( self.id )
|
||||
|
||||
|
||||
puts bad_friend.users.inspect
|
||||
|
||||
|
||||
|
||||
puts bad_friend.users.count
|
||||
|
||||
if bad_friend
|
||||
puts bad_friend.url
|
||||
#Retraction.for(self).push_to_url(bad_friend.url)
|
||||
bad_friend.destroy if bad_friend.users.count == 0
|
||||
Retraction.for(self).push_to_url(bad_friend.url)
|
||||
bad_friend.update_attributes(:user_refs => bad_friend.user_refs - 1)
|
||||
bad_friend.destroy if bad_friend.user_refs == 0
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -49,8 +49,9 @@ describe Person do
|
|||
|
||||
person = Factory.create(:person)
|
||||
|
||||
person.users << user
|
||||
user.friends << person
|
||||
person.user_refs += 1
|
||||
person.save
|
||||
|
||||
Person.all.count.should == 2
|
||||
user.friends.count.should == 1
|
||||
|
|
@ -68,16 +69,14 @@ describe Person do
|
|||
|
||||
person = Factory.create(:person)
|
||||
|
||||
|
||||
person.users << user_one
|
||||
person.users << user_two
|
||||
person.save
|
||||
|
||||
user_one.friends << person
|
||||
user_two.friends << person
|
||||
user_one.save
|
||||
user_two.save
|
||||
|
||||
person.user_refs += 2
|
||||
person.save
|
||||
|
||||
Person.all.count.should == 3
|
||||
user_one.friends.count.should == 1
|
||||
user_two.friends.count.should == 1
|
||||
|
|
@ -87,7 +86,7 @@ describe Person do
|
|||
user_one.friends.count.should == 0
|
||||
user_two.friends.count.should == 1
|
||||
|
||||
Person.all.count.should == 2
|
||||
Person.all.count.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue