has_friends_ti2 0.0.23 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/has_friends_ti2/has_friends.rb +10 -3
- data/lib/has_friends_ti2/version.rb +1 -1
- data/spec/has_friends_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46134091af111bbafba408d096988dd9a37be990
|
|
4
|
+
data.tar.gz: 8c19c445256cbce567ba0ad6fee9d0766390f2ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: edffd028a77abd74a63f49557f2afdb5c848024782d00809e6a3448a2ebab7dee961c49340cd0940f589ca6e76e1113f71112477b9fc45477814f51fcfb4249c
|
|
7
|
+
data.tar.gz: 8a327c4e363b35a04465c916df7d837b4dc9afffa313ea952db601edcf9e4672e948b6afa5771d849c6e27660a921e3ae20dca69a00b4f62222dbf1aa5aa3dd3
|
|
@@ -2,11 +2,12 @@ module HasFriends
|
|
|
2
2
|
|
|
3
3
|
module Friends
|
|
4
4
|
def self.included(receiver)
|
|
5
|
-
receiver.extend
|
|
5
|
+
receiver.extend ClassMethods
|
|
6
|
+
receiver.send :include, InstanceMethods
|
|
6
7
|
end
|
|
8
|
+
|
|
7
9
|
module ClassMethods
|
|
8
10
|
def has_friends
|
|
9
|
-
include HasFriends::Friends::InstanceMethods
|
|
10
11
|
has_many :friendships
|
|
11
12
|
has_many :friends, :through => :friendships, :source => :friend#,-> { where( status: 'accepted')} #"friendships.status = 'accepted'"
|
|
12
13
|
after_destroy :destroy_all_friendships
|
|
@@ -14,6 +15,7 @@ module HasFriends
|
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
module InstanceMethods
|
|
18
|
+
|
|
17
19
|
def be_friends_with friend
|
|
18
20
|
# no user object
|
|
19
21
|
return nil, Friendship::STATUS_FRIEND_IS_REQUIRED unless friend
|
|
@@ -50,11 +52,14 @@ module HasFriends
|
|
|
50
52
|
return friendship, Friendship::STATUS_REQUESTED
|
|
51
53
|
end
|
|
52
54
|
|
|
53
|
-
|
|
54
55
|
def friends?(friend)
|
|
55
56
|
friendship = friendship_for(friend)
|
|
56
57
|
friendship && friendship.accepted?
|
|
57
58
|
end
|
|
59
|
+
def are_friends?(friend)
|
|
60
|
+
friendship = friendship_for(friend)
|
|
61
|
+
friendship && friendship.accepted?
|
|
62
|
+
end
|
|
58
63
|
|
|
59
64
|
def friendship_for(friend)
|
|
60
65
|
friendships.where(:friend_id => friend.id).first
|
|
@@ -70,6 +75,8 @@ module HasFriends
|
|
|
70
75
|
Friendship.delete_all({:friend_id => id})
|
|
71
76
|
end
|
|
72
77
|
end
|
|
78
|
+
|
|
79
|
+
|
|
73
80
|
end
|
|
74
81
|
|
|
75
82
|
end
|
data/spec/has_friends_spec.rb
CHANGED
|
@@ -31,6 +31,10 @@ describe 'has_friends' do
|
|
|
31
31
|
it "should respond to friends? method" do
|
|
32
32
|
expect( @vader ).to respond_to :friends?
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
it "should respond to are friends? method" do
|
|
36
|
+
expect( @vader ).to respond_to :are_friends?
|
|
37
|
+
end
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
describe "friends" do
|