amico 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --format nested
2
+ --format nested
3
+ --order random
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.3.2 (2013-01-04)
4
+
5
+ * Fixed an issue where the call to `reciprocated?` in the internal method `add_following_followers_reciprocated` was not passing along the scope.
6
+
3
7
  ## 2.3.1 (2012-09-13)
4
8
 
5
9
  * Wrapped a few operations in Redis multi/exec blocks to be consistent with the rest of the library.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 David Czarnecki
1
+ Copyright (c) 2012-2013 David Czarnecki
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -605,5 +605,5 @@ user-defined in the future to allow for some specific ordering.
605
605
 
606
606
  ## Copyright
607
607
 
608
- Copyright (c) 2012 David Czarnecki. See LICENSE.txt for further details.
608
+ Copyright (c) 2012-2013 David Czarnecki. See LICENSE.txt for further details.
609
609
 
@@ -1,9 +1,9 @@
1
1
  module Amico
2
2
  module Relationships
3
- # Establish a follow relationship between two IDs. After adding the follow
4
- # relationship, it checks to see if the relationship is reciprocated and establishes that
3
+ # Establish a follow relationship between two IDs. After adding the follow
4
+ # relationship, it checks to see if the relationship is reciprocated and establishes that
5
5
  # relationship if so.
6
- #
6
+ #
7
7
  # @param from_id [String] The ID of the individual establishing the follow relationship.
8
8
  # @param to_id [String] The ID of the individual to be followed.
9
9
  # @param scope [String] Scope for the call.
@@ -16,24 +16,24 @@ module Amico
16
16
  return if blocked?(to_id, from_id, scope)
17
17
  return if Amico.pending_follow && pending?(from_id, to_id, scope)
18
18
 
19
- unless Amico.pending_follow
20
- add_following_followers_reciprocated(from_id, to_id, scope)
21
- else
22
- Amico.redis.multi do
23
- Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
24
- Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
19
+ if Amico.pending_follow
20
+ Amico.redis.multi do |transaction|
21
+ transaction.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
22
+ transaction.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
25
23
  end
24
+ else
25
+ add_following_followers_reciprocated(from_id, to_id, scope)
26
26
  end
27
27
  end
28
28
 
29
- # Remove a follow relationship between two IDs. After removing the follow
30
- # relationship, if a reciprocated relationship was established, it is
29
+ # Remove a follow relationship between two IDs. After removing the follow
30
+ # relationship, if a reciprocated relationship was established, it is
31
31
  # also removed.
32
32
  #
33
33
  # @param from_id [String] The ID of the individual removing the follow relationship.
34
34
  # @param to_id [String] The ID of the individual to be unfollowed.
35
35
  # @param scope [String] Scope for the call.
36
- #
36
+ #
37
37
  # Examples
38
38
  #
39
39
  # Amico.follow(1, 11)
@@ -49,10 +49,10 @@ module Amico
49
49
  Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
50
50
  Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
51
51
  end
52
- end
52
+ end
53
53
 
54
- # Block a relationship between two IDs. This method also has the side effect
55
- # of removing any follower or following relationship between the two IDs.
54
+ # Block a relationship between two IDs. This method also has the side effect
55
+ # of removing any follower or following relationship between the two IDs.
56
56
  #
57
57
  # @param from_id [String] The ID of the individual blocking the relationship.
58
58
  # @param to_id [String] The ID of the individual being blocked.
@@ -83,9 +83,9 @@ module Amico
83
83
  # @param from_id [String] The ID of the individual unblocking the relationship.
84
84
  # @param to_id [String] The ID of the blocked individual.
85
85
  # @param scope [String] Scope for the call.
86
- #
86
+ #
87
87
  # Examples
88
- #
88
+ #
89
89
  # Amico.block(1, 11)
90
90
  # Amico.unblock(1, 11)
91
91
  def unblock(from_id, to_id, scope = Amico.default_scope_key)
@@ -117,11 +117,11 @@ module Amico
117
117
  end
118
118
 
119
119
  # Deny a relationship that is pending between two IDs.
120
- #
120
+ #
121
121
  # @param from_id [String] The ID of the individual denying the relationship.
122
122
  # @param to_id [String] The ID of the individual to be denied.
123
123
  # @param scope [String] Scope for the call.
124
- #
124
+ #
125
125
  # Example
126
126
  #
127
127
  # Amico.follow(1, 11)
@@ -140,12 +140,12 @@ module Amico
140
140
 
141
141
  # Clears all relationships (in either direction) stored for an individual.
142
142
  # Helpful to prevent orphaned associations when deleting users.
143
- #
143
+ #
144
144
  # @param id [String] ID of the individual to clear info for.
145
145
  # @param scope [String] Scope for the call.
146
- #
146
+ #
147
147
  # Examples
148
- #
148
+ #
149
149
  # Amico.follow(1, 11)
150
150
  # Amico.followers_count(11) => 1
151
151
  # Amico.clear(1)
@@ -167,9 +167,9 @@ module Amico
167
167
  #
168
168
  # @param id [String] ID of the individual to retrieve following count for.
169
169
  # @param scope [String] Scope for the call.
170
- #
170
+ #
171
171
  # Examples
172
- #
172
+ #
173
173
  # Amico.follow(1, 11)
174
174
  # Amico.following_count(1)
175
175
  #
@@ -187,7 +187,7 @@ module Amico
187
187
  #
188
188
  # Amico.follow(11, 1)
189
189
  # Amico.followers_count(1)
190
- #
190
+ #
191
191
  # @return the count of the number of individuals that are following someone.
192
192
  def followers_count(id, scope = Amico.default_scope_key)
193
193
  Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}")
@@ -197,7 +197,7 @@ module Amico
197
197
  #
198
198
  # @param id [String] ID of the individual to retrieve blocked count for.
199
199
  # @param scope [String] Scope for the call.
200
- #
200
+ #
201
201
  # Examples
202
202
  #
203
203
  # Amico.block(1, 11)
@@ -212,7 +212,7 @@ module Amico
212
212
  #
213
213
  # @param id [String] ID of the individual to retrieve blocked_by count for.
214
214
  # @param scope [String] Scope for the call.
215
- #
215
+ #
216
216
  # Examples
217
217
  #
218
218
  # Amico.block(1, 11)
@@ -227,9 +227,9 @@ module Amico
227
227
  #
228
228
  # @param id [String] ID of the individual to retrieve reciprocated following count for.
229
229
  # @param scope [String] Scope for the call.
230
- #
230
+ #
231
231
  # Examples
232
- #
232
+ #
233
233
  # Amico.follow(1, 11)
234
234
  # Amico.follow(11, 1)
235
235
  # Amico.reciprocated_count(1)
@@ -243,7 +243,7 @@ module Amico
243
243
  #
244
244
  # @param id [String] ID of the individual to retrieve pending count for.
245
245
  # @param scope [String] Scope for the call.
246
- #
246
+ #
247
247
  # Examples
248
248
  #
249
249
  # Amico.follow(11, 1)
@@ -259,7 +259,7 @@ module Amico
259
259
  #
260
260
  # @param id [String] ID of the individual to retrieve pending count for.
261
261
  # @param scope [String] Scope for the call.
262
- #
262
+ #
263
263
  # Examples
264
264
  #
265
265
  # Amico.follow(1, 11)
@@ -310,7 +310,7 @@ module Amico
310
310
  # @param scope [String] Scope for the call.
311
311
  #
312
312
  # Examples
313
- #
313
+ #
314
314
  # Amico.block(1, 11)
315
315
  # Amico.blocked?(1, 11)
316
316
  #
@@ -326,7 +326,7 @@ module Amico
326
326
  # @param scope [String] Scope for the call.
327
327
  #
328
328
  # Examples
329
- #
329
+ #
330
330
  # Amico.block(1, 11)
331
331
  # Amico.blocked_by?(11, 1)
332
332
  #
@@ -408,7 +408,7 @@ module Amico
408
408
  # @param scope [String] Scope for the call.
409
409
  #
410
410
  # Examples
411
- #
411
+ #
412
412
  # Amico.follow(11, 1)
413
413
  # Amico.follow(12, 1)
414
414
  # Amico.followers(1, :page => 1)
@@ -550,7 +550,7 @@ module Amico
550
550
  # Amico.block(1, 11)
551
551
  # Amico.block(1, 12)
552
552
  # Amico.blocked_page_count(1)
553
- #
553
+ #
554
554
  # @return the number of pages of blocked relationships for an individual.
555
555
  def blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
556
556
  total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
@@ -567,7 +567,7 @@ module Amico
567
567
  # Amico.block(11, 1)
568
568
  # Amico.block(12, 1)
569
569
  # Amico.blocked_by_page_count(1)
570
- #
570
+ #
571
571
  # @return the number of pages of blocked_by relationships for an individual.
572
572
  def blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
573
573
  total_pages("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_size)
@@ -586,7 +586,7 @@ module Amico
586
586
  # Amico.follow(11, 1)
587
587
  # Amico.follow(12, 1)
588
588
  # Amico.reciprocated_page_count(1)
589
- #
589
+ #
590
590
  # @return the number of pages of reciprocated relationships for an individual.
591
591
  def reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
592
592
  total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", page_size)
@@ -603,7 +603,7 @@ module Amico
603
603
  # Amico.follow(11, 1)
604
604
  # Amico.follow(12, 1)
605
605
  # Amico.pending_page_count(1) # 1
606
- #
606
+ #
607
607
  # @return the number of pages of pending relationships for an individual.
608
608
  def pending_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
609
609
  total_pages("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", page_size)
@@ -620,7 +620,7 @@ module Amico
620
620
  # Amico.follow(1, 11)
621
621
  # Amico.follow(1, 12)
622
622
  # Amico.pending_with_page_count(1) # 1
623
- #
623
+ #
624
624
  # @return the number of pages of individuals waiting to approve another individual.
625
625
  def pending_with_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
626
626
  total_pages("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{id}", page_size)
@@ -668,7 +668,7 @@ module Amico
668
668
  VALID_RELATIONSHIPS = [:following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with]
669
669
 
670
670
  # Ensure that a relationship type is valid.
671
- #
671
+ #
672
672
  # @param type [Symbol] One of :following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with.
673
673
  # @raise [StandardError] if the type is not included in VALID_RELATIONSHIPS
674
674
  def validate_relationship_type(type)
@@ -682,11 +682,11 @@ module Amico
682
682
  {:page_size => Amico.page_size, :page => 1}
683
683
  end
684
684
 
685
- # Add the following, followers and check for a reciprocated relationship. To be used from the
685
+ # Add the following, followers and check for a reciprocated relationship. To be used from the
686
686
  # +follow+ and +accept+ methods.
687
687
  #
688
688
  # @param from_id [String] The ID of the individual establishing the follow relationship.
689
- # @param to_id [String] The ID of the individual to be followed.
689
+ # @param to_id [String] The ID of the individual to be followed.
690
690
  def add_following_followers_reciprocated(from_id, to_id, scope)
691
691
  Amico.redis.multi do
692
692
  Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
@@ -695,12 +695,12 @@ module Amico
695
695
  Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
696
696
  end
697
697
 
698
- if reciprocated?(from_id, to_id)
698
+ if reciprocated?(from_id, to_id, scope)
699
699
  Amico.redis.multi do
700
700
  Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
701
701
  Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
702
702
  end
703
- end
703
+ end
704
704
  end
705
705
 
706
706
  # Removes references to an individual in sets that are named with other individual's keys.
@@ -1,3 +1,3 @@
1
1
  module Amico
2
- VERSION = '2.3.1'
2
+ VERSION = '2.3.2'
3
3
  end
@@ -138,6 +138,17 @@ describe Amico::Relationships do
138
138
  Amico.follow(1, 11)
139
139
  Amico.reciprocated?(1, 11).should be_false
140
140
  end
141
+
142
+ it 'should respect scope when checking if a relationship is reciprocated' do
143
+ Amico.follow(1, 11, 'another_scope')
144
+ Amico.follow(11, 1, 'another_scope')
145
+ Amico.follow(1, 11, 'another_scope')
146
+ Amico.reciprocated?(1, 11).should be_false
147
+ Amico.reciprocated?(1, 11, 'another_scope').should be_true
148
+ Amico.follow(1, 11)
149
+ Amico.follow(11, 1)
150
+ Amico.reciprocated?(1, 11).should be_true
151
+ end
141
152
  end
142
153
 
143
154
  describe '#following' do
@@ -388,9 +399,9 @@ describe Amico::Relationships do
388
399
  Amico.follow(1, 11)
389
400
  Amico.pending?(1, 11).should be_true
390
401
  Amico.pending_with?(11, 1).should be_true
391
-
402
+
392
403
  Amico.deny(1, 11)
393
-
404
+
394
405
  Amico.following?(1, 11).should be_false
395
406
  Amico.pending?(1, 11).should be_false
396
407
  Amico.pending_with?(11, 1).should be_false
@@ -630,16 +641,16 @@ describe Amico::Relationships do
630
641
  it 'should remove follower/following relationships' do
631
642
  Amico.follow(1, 11)
632
643
  Amico.follow(11, 1)
633
-
644
+
634
645
  Amico.following_count(1).should be(1)
635
646
  Amico.followers_count(1).should be(1)
636
647
  Amico.reciprocated_count(1).should be(1)
637
648
  Amico.following_count(11).should be(1)
638
649
  Amico.followers_count(11).should be(1)
639
650
  Amico.reciprocated_count(11).should be(1)
640
-
651
+
641
652
  Amico.clear(1)
642
-
653
+
643
654
  Amico.following_count(1).should be(0)
644
655
  Amico.followers_count(1).should be(0)
645
656
  Amico.reciprocated_count(1).should be(0)
@@ -657,7 +668,7 @@ describe Amico::Relationships do
657
668
  Amico.pending_count(11).should be(0)
658
669
  Amico.pending_follow = previous_pending_value
659
670
  end
660
-
671
+
661
672
  it 'should clear blocked/blocked_by relationships' do
662
673
  Amico.block(1, 11)
663
674
  Amico.blocked_count(1).should be(1)
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Amico::VERSION' do
4
4
  it 'should be the correct version' do
5
- Amico::VERSION.should == '2.3.1'
5
+ Amico::VERSION.should == '2.3.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amico
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -95,12 +95,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ segments:
99
+ - 0
100
+ hash: -1960830450408836272
98
101
  required_rubygems_version: !ruby/object:Gem::Requirement
99
102
  none: false
100
103
  requirements:
101
104
  - - ! '>='
102
105
  - !ruby/object:Gem::Version
103
106
  version: '0'
107
+ segments:
108
+ - 0
109
+ hash: -1960830450408836272
104
110
  requirements: []
105
111
  rubyforge_project: amico
106
112
  rubygems_version: 1.8.24