amistad 0.9.2 → 0.10.0
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 +7 -0
- data/Gemfile.lock +81 -68
- data/README.markdown +1 -1
- data/amistad.gemspec +6 -6
- data/lib/amistad/active_record_friend_model.rb +7 -25
- data/lib/amistad/mongo_mapper_friend_model.rb +0 -11
- data/lib/amistad/mongoid_friend_model.rb +0 -10
- data/lib/amistad/version.rb +1 -1
- data/spec/activerecord/activerecord_spec_helper.rb +0 -3
- data/spec/activerecord/friend_spec.rb +0 -3
- data/spec/support/activerecord/friendship_examples.rb +29 -29
- data/spec/support/friend_examples.rb +226 -226
- metadata +48 -84
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed824f9e11cab8950dd941dd080bc73304d86411
|
4
|
+
data.tar.gz: 6e2ca13bb345b5e8a3ecfb220e565cbd39a8fd99
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15245fd8370230189b7837512b19c2c1468140d385993057f5325151c1768f3ec6a91804a7fd4baf06af510b900e3b8e7db0124d6b6c8db80337aa11bc96917f
|
7
|
+
data.tar.gz: c29d4ed8fa6228e31ca7d7dbebef793aa3d40635456c5123ac1883ab0c3516fb790ce5465c68cfd257cb276ef5d2b9561c2cd8b63d1c4e3f8e71c42a11fa14eb
|
data/Gemfile.lock
CHANGED
@@ -1,79 +1,92 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
amistad (0.
|
4
|
+
amistad (0.10.0)
|
5
5
|
squeel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
builder (~> 3.
|
13
|
-
activerecord (
|
14
|
-
activemodel (=
|
15
|
-
activesupport (=
|
16
|
-
arel (~>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
rspec
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
10
|
+
activemodel (4.1.6)
|
11
|
+
activesupport (= 4.1.6)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activerecord (4.1.6)
|
14
|
+
activemodel (= 4.1.6)
|
15
|
+
activesupport (= 4.1.6)
|
16
|
+
arel (~> 5.0.0)
|
17
|
+
activesupport (4.1.6)
|
18
|
+
i18n (~> 0.6, >= 0.6.9)
|
19
|
+
json (~> 1.7, >= 1.7.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
thread_safe (~> 0.1)
|
22
|
+
tzinfo (~> 1.1)
|
23
|
+
arel (5.0.1.20140414130214)
|
24
|
+
awesome_print (1.2.0)
|
25
|
+
bson (2.2.0)
|
26
|
+
bson_ext (1.5.1)
|
27
|
+
builder (3.2.2)
|
28
|
+
connection_pool (2.0.0)
|
29
|
+
database_cleaner (1.3.0)
|
30
|
+
diff-lcs (1.2.5)
|
31
|
+
fuubar (2.0.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
ruby-progressbar (~> 1.4)
|
34
|
+
i18n (0.6.11)
|
35
|
+
jnunemaker-validatable (1.8.4)
|
36
|
+
activesupport (>= 2.3.4)
|
37
|
+
json (1.8.1)
|
38
|
+
minitest (5.4.1)
|
39
|
+
mongo (1.3.1)
|
40
|
+
bson (>= 1.3.1)
|
41
|
+
mongo_mapper (0.8.6)
|
42
|
+
activesupport (>= 2.3.4)
|
43
|
+
jnunemaker-validatable (~> 1.8.4)
|
44
|
+
plucky (~> 0.3.6)
|
45
|
+
mongoid (4.0.0)
|
46
|
+
activemodel (~> 4.0)
|
47
|
+
moped (~> 2.0.0)
|
48
|
+
origin (~> 2.1)
|
49
|
+
tzinfo (>= 0.3.37)
|
50
|
+
moped (2.0.0)
|
51
|
+
bson (~> 2.2)
|
52
|
+
connection_pool (~> 2.0)
|
53
|
+
optionable (~> 0.2.0)
|
54
|
+
mysql2 (0.3.16)
|
55
|
+
optionable (0.2.0)
|
56
|
+
origin (2.1.1)
|
57
|
+
pg (0.17.1)
|
58
|
+
plucky (0.3.8)
|
59
|
+
mongo (~> 1.3)
|
60
|
+
polyamorous (1.1.0)
|
61
|
+
activerecord (>= 3.0)
|
62
|
+
rake (10.3.2)
|
63
|
+
rspec (3.1.0)
|
64
|
+
rspec-core (~> 3.1.0)
|
65
|
+
rspec-expectations (~> 3.1.0)
|
66
|
+
rspec-mocks (~> 3.1.0)
|
67
|
+
rspec-core (3.1.4)
|
68
|
+
rspec-support (~> 3.1.0)
|
69
|
+
rspec-expectations (3.1.1)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.1.0)
|
72
|
+
rspec-mocks (3.1.1)
|
73
|
+
rspec-support (~> 3.1.0)
|
74
|
+
rspec-support (3.1.0)
|
75
|
+
ruby-progressbar (1.6.0)
|
76
|
+
sqlite3 (1.3.9)
|
77
|
+
squeel (1.2.1)
|
78
|
+
activerecord (>= 3.0)
|
79
|
+
activesupport (>= 3.0)
|
80
|
+
polyamorous (~> 1.1.0)
|
81
|
+
thread_safe (0.3.4)
|
82
|
+
tzinfo (1.2.2)
|
83
|
+
thread_safe (~> 0.1)
|
71
84
|
|
72
85
|
PLATFORMS
|
73
86
|
ruby
|
74
87
|
|
75
88
|
DEPENDENCIES
|
76
|
-
activerecord
|
89
|
+
activerecord (>= 4.0.0)
|
77
90
|
amistad!
|
78
91
|
awesome_print
|
79
92
|
bson_ext
|
@@ -81,9 +94,9 @@ DEPENDENCIES
|
|
81
94
|
database_cleaner
|
82
95
|
fuubar
|
83
96
|
mongo_mapper
|
84
|
-
mongoid
|
85
|
-
mysql2
|
86
|
-
pg
|
97
|
+
mongoid (>= 4.0.0)
|
98
|
+
mysql2 (>= 0.3.16)
|
99
|
+
pg (>= 0.17.1)
|
87
100
|
rake
|
88
|
-
rspec
|
89
|
-
sqlite3
|
101
|
+
rspec (~> 3.1.0)
|
102
|
+
sqlite3 (>= 1.3.9)
|
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# amistad #
|
2
2
|
|
3
|
-
Amistad adds friendships management into a rails
|
3
|
+
Amistad adds friendships management into a rails application. it supports ActiveRecord, Mongoid and MongoMapper.
|
4
4
|
|
5
5
|
## Installation ##
|
6
6
|
|
data/amistad.gemspec
CHANGED
@@ -18,13 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency "bundler"
|
20
20
|
s.add_development_dependency "rake"
|
21
|
-
s.add_development_dependency "rspec"
|
22
|
-
s.add_development_dependency "activerecord"
|
23
|
-
s.add_development_dependency "mysql2"
|
24
|
-
s.add_development_dependency "pg"
|
21
|
+
s.add_development_dependency "rspec", "~> 3.1.0"
|
22
|
+
s.add_development_dependency "activerecord", ">= 4.0.0"
|
23
|
+
s.add_development_dependency "mysql2", ">= 0.3.16"
|
24
|
+
s.add_development_dependency "pg", ">= 0.17.1"
|
25
25
|
s.add_development_dependency "database_cleaner"
|
26
|
-
s.add_development_dependency "sqlite3"
|
27
|
-
s.add_development_dependency "mongoid"
|
26
|
+
s.add_development_dependency "sqlite3", ">= 1.3.9"
|
27
|
+
s.add_development_dependency "mongoid", ">= 4.0.0"
|
28
28
|
s.add_development_dependency "bson_ext"
|
29
29
|
s.add_development_dependency "fuubar"
|
30
30
|
s.add_development_dependency "awesome_print"
|
@@ -12,15 +12,9 @@ module Amistad
|
|
12
12
|
:class_name => "Amistad::Friendships::#{Amistad.friendship_model}",
|
13
13
|
:foreign_key => "friendable_id"
|
14
14
|
|
15
|
-
has_many :pending_invited,
|
16
|
-
:through => :friendships,
|
17
|
-
:source => :friend,
|
18
|
-
:conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
|
19
15
|
|
20
|
-
has_many :
|
21
|
-
|
22
|
-
:source => :friend,
|
23
|
-
:conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
|
16
|
+
has_many :pending_invited, -> { where(:'friendships.pending' => true, :'friendships.blocker_id' => nil) }, :through => :friendships, :source => :friend
|
17
|
+
has_many :invited, -> { where(:'friendships.pending' => false, :'friendships.blocker_id' => nil) }, :through => :friendships, :source => :friend
|
24
18
|
|
25
19
|
#####################################################################################
|
26
20
|
# inverse friendships
|
@@ -29,15 +23,8 @@ module Amistad
|
|
29
23
|
:class_name => "Amistad::Friendships::#{Amistad.friendship_model}",
|
30
24
|
:foreign_key => "friend_id"
|
31
25
|
|
32
|
-
has_many :pending_invited_by,
|
33
|
-
|
34
|
-
:source => :friendable,
|
35
|
-
:conditions => { :'friendships.pending' => true, :'friendships.blocker_id' => nil }
|
36
|
-
|
37
|
-
has_many :invited_by,
|
38
|
-
:through => :inverse_friendships,
|
39
|
-
:source => :friendable,
|
40
|
-
:conditions => { :'friendships.pending' => false, :'friendships.blocker_id' => nil }
|
26
|
+
has_many :pending_invited_by, -> { where(:'friendships.pending' => true, :'friendships.blocker_id' => nil) }, :through => :inverse_friendships, :source => :friendable
|
27
|
+
has_many :invited_by, -> { where(:'friendships.pending' => false, :'friendships.blocker_id' => nil) }, :through => :inverse_friendships, :source => :friendable
|
41
28
|
|
42
29
|
#####################################################################################
|
43
30
|
# blocked friendships
|
@@ -46,15 +33,9 @@ module Amistad
|
|
46
33
|
:class_name => "Amistad::Friendships::#{Amistad.friendship_model}",
|
47
34
|
:foreign_key => "blocker_id"
|
48
35
|
|
49
|
-
has_many :blockades,
|
50
|
-
|
51
|
-
:source => :friend,
|
52
|
-
:conditions => "friend_id <> blocker_id"
|
36
|
+
has_many :blockades, -> {where("friend_id <> blocker_id")}, :through => :blocked_friendships, :source => :friend
|
37
|
+
has_many :blockades_by, -> {where("friendable_id <> blocker_id")} , :through => :blocked_friendships, :source => :friendable
|
53
38
|
|
54
|
-
has_many :blockades_by,
|
55
|
-
:through => :blocked_friendships,
|
56
|
-
:source => :friendable,
|
57
|
-
:conditions => "friendable_id <> blocker_id"
|
58
39
|
end
|
59
40
|
|
60
41
|
# suggest a user to become a friend. If the operation succeeds, the method returns true, else false
|
@@ -76,6 +57,7 @@ module Amistad
|
|
76
57
|
return false if friendship.nil?
|
77
58
|
friendship.destroy
|
78
59
|
self.reload && user.reload if friendship.destroyed?
|
60
|
+
true
|
79
61
|
end
|
80
62
|
|
81
63
|
# returns the list of approved friends
|
@@ -35,17 +35,6 @@ module Amistad
|
|
35
35
|
Array,
|
36
36
|
:default => []
|
37
37
|
|
38
|
-
attr_accessible(
|
39
|
-
:friend_ids,
|
40
|
-
:inverse_friend_ids,
|
41
|
-
:pending_friend_ids,
|
42
|
-
:pending_inverse_friend_ids,
|
43
|
-
:blocked_friend_ids,
|
44
|
-
:blocked_inverse_friend_ids,
|
45
|
-
:blocked_pending_friend_ids,
|
46
|
-
:blocked_pending_inverse_friend_ids,
|
47
|
-
)
|
48
|
-
|
49
38
|
%w(friend_ids inverse_friend_ids pending_friend_ids pending_inverse_friend_ids blocked_friend_ids blocked_inverse_friend_ids blocked_pending_friend_ids blocked_pending_inverse_friend_ids).each do |attribute|
|
50
39
|
define_method(attribute.to_sym) do
|
51
40
|
value = read_attribute(attribute)
|
@@ -35,16 +35,6 @@ module Amistad
|
|
35
35
|
:type => Array,
|
36
36
|
:default => []
|
37
37
|
|
38
|
-
attr_accessible(
|
39
|
-
:friend_ids,
|
40
|
-
:inverse_friend_ids,
|
41
|
-
:pending_friend_ids,
|
42
|
-
:pending_inverse_friend_ids,
|
43
|
-
:blocked_friend_ids,
|
44
|
-
:blocked_inverse_friend_ids,
|
45
|
-
:blocked_pending_friend_ids,
|
46
|
-
:blocked_pending_inverse_friend_ids,
|
47
|
-
)
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
data/lib/amistad/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
shared_examples_for "the friendship model" do
|
2
2
|
it "should validate presence of the user's id and the friend's id" do
|
3
3
|
friendship = Amistad.friendship_class.new
|
4
|
-
friendship.valid
|
5
|
-
friendship.errors.
|
6
|
-
friendship.errors.
|
7
|
-
friendship.errors.size.
|
4
|
+
expect(friendship.valid?).to eq(false)
|
5
|
+
expect(friendship.errors).to include(:friendable_id)
|
6
|
+
expect(friendship.errors).to include(:friend_id)
|
7
|
+
expect(friendship.errors.size).to eq(2)
|
8
8
|
end
|
9
9
|
|
10
10
|
context "when creating friendship" do
|
@@ -14,29 +14,29 @@ shared_examples_for "the friendship model" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should be pending" do
|
17
|
-
@friendship.pending
|
17
|
+
expect(@friendship.pending?).to eq(true)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should not be approved" do
|
21
|
-
@friendship.approved
|
21
|
+
expect(@friendship.approved?).to eq(false)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be active" do
|
25
|
-
@friendship.active
|
25
|
+
expect(@friendship.active?).to eq(true)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should not be blocked" do
|
29
|
-
@friendship.blocked
|
29
|
+
expect(@friendship.blocked?).to eq(false)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be available to block only by invited user" do
|
33
|
-
@friendship.can_block?(@david).
|
34
|
-
@friendship.can_block?(@jane).
|
33
|
+
expect(@friendship.can_block?(@david)).to eq(true)
|
34
|
+
expect(@friendship.can_block?(@jane)).to eq(false)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should not be available to unblock" do
|
38
|
-
@friendship.can_unblock?(@jane).
|
39
|
-
@friendship.can_unblock?(@david).
|
38
|
+
expect(@friendship.can_unblock?(@jane)).to eq(false)
|
39
|
+
expect(@friendship.can_unblock?(@david)).to eq(false)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -48,29 +48,29 @@ shared_examples_for "the friendship model" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should be approved" do
|
51
|
-
@friendship.approved
|
51
|
+
expect(@friendship.approved?).to eq(true)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not be pending" do
|
55
|
-
@friendship.pending
|
55
|
+
expect(@friendship.pending?).to eq(false)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should be active" do
|
59
|
-
@friendship.active
|
59
|
+
expect(@friendship.active?).to eq(true)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should not be blocked" do
|
63
|
-
@friendship.blocked
|
63
|
+
expect(@friendship.blocked?).to eq(false)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should be available to block by both users" do
|
67
|
-
@friendship.can_block?(@jane).
|
68
|
-
@friendship.can_block?(@david).
|
67
|
+
expect(@friendship.can_block?(@jane)).to eq(true)
|
68
|
+
expect(@friendship.can_block?(@david)).to eq(true)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should not be availabel to unblock" do
|
72
|
-
@friendship.can_unblock?(@jane).
|
73
|
-
@friendship.can_unblock?(@david).
|
72
|
+
expect(@friendship.can_unblock?(@jane)).to eq(false)
|
73
|
+
expect(@friendship.can_unblock?(@david)).to eq(false)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -82,29 +82,29 @@ shared_examples_for "the friendship model" do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should not be approved" do
|
85
|
-
@friendship.approved
|
85
|
+
expect(@friendship.approved?).to eq(false)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should be pending" do
|
89
|
-
@friendship.pending
|
89
|
+
expect(@friendship.pending?).to eq(true)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should not be active" do
|
93
|
-
@friendship.active
|
93
|
+
expect(@friendship.active?).to eq(false)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should be blocked" do
|
97
|
-
@friendship.blocked
|
97
|
+
expect(@friendship.blocked?).to eq(true)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should not be available to block" do
|
101
|
-
@friendship.can_block?(@jane).
|
102
|
-
@friendship.can_block?(@david).
|
101
|
+
expect(@friendship.can_block?(@jane)).to eq(false)
|
102
|
+
expect(@friendship.can_block?(@david)).to eq(false)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should be available to unblock only by user who blocked it" do
|
106
|
-
@friendship.can_unblock?(@david).
|
107
|
-
@friendship.can_unblock?(@jane).
|
106
|
+
expect(@friendship.can_unblock?(@david)).to eq(true)
|
107
|
+
expect(@friendship.can_unblock?(@jane)).to eq(false)
|
108
108
|
end
|
109
109
|
end
|
110
|
-
end
|
110
|
+
end
|