Permalink
Browse files

Page count

* Added `following_page_count(id, page_size = Amico.page_size)` and `followers_page_count(id, page_size = Amico.page_size)` methods and specs
  • Loading branch information...
1 parent de6552c commit 2198d800558a26c145754f83ee79f1b66d7e535a @czarneckid czarneckid committed Jan 11, 2012
Showing with 31 additions and 1 deletion.
  1. +2 −0 README.md
  2. +9 −1 lib/amico/friendships.rb
  3. +20 −0 spec/amico/friendships_spec.rb
View
@@ -78,6 +78,8 @@ Amico.follower?(1, 11)
Amico.following(1)
=> ["11"]
```
+
+You can pass `:page => 1` and `:page_size => 25` options into the `following` and `followers` methods. Set the values as appropriate.
## Contributing to amico
View
@@ -2,7 +2,7 @@ module Amico
module Friendships
def follow(from_id, to_id)
return if from_id == to_id
-
+
Amico.redis.multi do
Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{from_id}", Time.now.to_i, to_id)
Amico.redis.zadd("#{Amico.namespace}:#{Amico.followers_key}:#{to_id}", Time.now.to_i, from_id)
@@ -40,6 +40,14 @@ def followers(id, options = default_options)
members("#{Amico.namespace}:#{Amico.followers_key}:#{id}", options)
end
+ def following_page_count(id, page_size = Amico.page_size)
+ total_pages("#{Amico.namespace}:#{Amico.following_key}:#{id}", page_size)
+ end
+
+ def followers_page_count(id, page_size = Amico.page_size)
+ total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{id}", page_size)
+ end
+
private
def default_options
@@ -101,6 +101,26 @@
end
end
+ describe '#following_page_count' do
+ it 'should return the correct count' do
+ add_reciprocal_followers
+
+ Amico.following_page_count(1).should be(1)
+ Amico.following_page_count(1, 10).should be(3)
+ Amico.following_page_count(1, 5).should be(5)
+ end
+ end
+
+ describe '#followers_page_count' do
+ it 'should return the correct count' do
+ add_reciprocal_followers
+
+ Amico.followers_page_count(1).should be(1)
+ Amico.followers_page_count(1, 10).should be(3)
+ Amico.followers_page_count(1, 5).should be(5)
+ end
+ end
+
private
def add_reciprocal_followers(count = 26)

0 comments on commit 2198d80

Please sign in to comment.