lib/popular/popular.rb in popular-0.7.3 vs lib/popular/popular.rb in popular-0.7.4

- old
+ new

@@ -46,11 +46,11 @@ # user.befriend other_user # # user.friends_with? other_user #=> true def befriend new_friend run_callbacks :befriend do - friendships.create friend: new_friend + friendships.create friend_id: new_friend.id, friend_type: new_friend.class.name end end # Adds a friend to an instance's friend's list # Similar to .befriend, but will raise an error if the operation is not successful @@ -63,11 +63,11 @@ # user.befriend! other_user # # user.friends_with? other_user # => true def befriend! new_friend run_callbacks :befriend do - friendships.create! friend: new_friend + friendships.create! friend_id: new_friend.id, friend_type: new_friend.class.name end end # Removes a friend from an instance's friend's list # @@ -80,10 +80,13 @@ # user.unfriend other_user # # user.friends_with? other_user # => false def unfriend friend run_callbacks :unfriend do - friendships.where( friend: friend ).first.destroy + friendships + .where( friend_type: friend.class.name ) + .where( friend_id: friend.id ) + .first.destroy end end # Helper method for determining whether instances are mutual friends #