activity_feed 1.1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +4 -0
- data/README.markdown +52 -1
- data/lib/activity_feed.rb +27 -2
- data/lib/activity_feed/active_record/item.rb +1 -1
- data/lib/activity_feed/feed.rb +10 -7
- data/lib/activity_feed/memory/item.rb +5 -1
- data/lib/activity_feed/mongo_mapper/item.rb +1 -1
- data/lib/activity_feed/ohm/item.rb +1 -1
- data/lib/activity_feed/version.rb +1 -1
- data/spec/activity_feed/custom/item.rb +5 -1
- data/spec/activity_feed_spec.rb +36 -16
- data/spec/feed_spec.rb +16 -0
- data/spec/item_spec.rb +11 -5
- data/spec/version_spec.rb +1 -1
- metadata +146 -133
data/CHANGELOG.markdown
CHANGED
data/README.markdown
CHANGED
@@ -24,6 +24,8 @@ ActivityFeed.redis = Redis.new(:host => '127.0.0.1', :port => 6379)
|
|
24
24
|
ActivityFeed.namespace = 'activity'
|
25
25
|
ActivityFeed.key = 'feed'
|
26
26
|
ActivityFeed.persistence = :memory # (or :active_record or :mongo_mapper or :ohm)
|
27
|
+
ActivityFeed.aggregate = true
|
28
|
+
ActivityFeed.aggregate_key = 'aggregate'
|
27
29
|
```
|
28
30
|
|
29
31
|
## Usage
|
@@ -167,7 +169,7 @@ ruby-1.9.2-p290 :012 > feed.page(1)
|
|
167
169
|
ruby-1.9.2-p290 :013 >
|
168
170
|
```
|
169
171
|
|
170
|
-
### Ohm
|
172
|
+
### Ohm persistence
|
171
173
|
|
172
174
|
ActivityFeed can also use Ohm to persist the items in Redis. You can set this using:
|
173
175
|
|
@@ -216,6 +218,55 @@ ActivityFeed::Foo::Item
|
|
216
218
|
The custom class should implement a find(item_or_item_id) method that does "the right thing".
|
217
219
|
Consult the specs to see this working if you have questions.
|
218
220
|
|
221
|
+
### Feeds and Aggregation Feeds
|
222
|
+
|
223
|
+
activity_feed uses the following key in adding the item to Redis: `ActivityFeed.namespace:ActivityFeed.key:self.user_id`. By default, activity_feed in the `create_item` call will
|
224
|
+
also add the item in Redis to an aggregate feed using the key: `ActivityFeed.namespace:ActivityFeed.key:ActivityFeed.aggregate_key:self.user_id`.
|
225
|
+
|
226
|
+
You can control aggregation globally by setting the ActivityFeed.aggregate property to either `true` or `false`. You can override the global aggregation setting on the
|
227
|
+
`create_item` call by passing either `true` or `false` as the 2nd argument.
|
228
|
+
|
229
|
+
Below is an example of an aggregate feed:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
ruby-1.9.2-p290 :001 > require 'activity_feed'
|
233
|
+
=> true
|
234
|
+
ruby-1.9.2-p290 :002 > require 'pp'
|
235
|
+
=> true
|
236
|
+
ruby-1.9.2-p290 :003 >
|
237
|
+
ruby-1.9.2-p290 :004 > $redis = Redis.new(:host => '127.0.0.1', :port => 6379)
|
238
|
+
=> #<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.4.4)>
|
239
|
+
ruby-1.9.2-p290 :005 > ActivityFeed.redis = $redis
|
240
|
+
=> #<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.4.4)>
|
241
|
+
ruby-1.9.2-p290 :006 > ActivityFeed.persistence = :ohm
|
242
|
+
=> :ohm
|
243
|
+
ruby-1.9.2-p290 :007 >
|
244
|
+
ruby-1.9.2-p290 :008 > 1.upto(5) do |index|
|
245
|
+
ruby-1.9.2-p290 :009 > item = ActivityFeed.create_item(:user_id => 1, :nickname => 'nickname_1', :text => "text_#{index}")
|
246
|
+
ruby-1.9.2-p290 :010?> sleep(1)
|
247
|
+
ruby-1.9.2-p290 :011?> another_item = ActivityFeed.create_item(:user_id => 2, :nickname => 'nickname_2', :text => "test_nickname2_#{index}")
|
248
|
+
ruby-1.9.2-p290 :012?> sleep(1)
|
249
|
+
ruby-1.9.2-p290 :013?> ActivityFeed.aggregate_item(another_item, 1)
|
250
|
+
ruby-1.9.2-p290 :014?> end
|
251
|
+
=> 1
|
252
|
+
ruby-1.9.2-p290 :015 >
|
253
|
+
ruby-1.9.2-p290 :016 > feed = ActivityFeed::Feed.new(1)
|
254
|
+
=> #<ActivityFeed::Feed:0x000001014b9298 @feederboard=#<Leaderboard:0x000001014b91a8 @leaderboard_name="activity:feed:1", @page_size=25, @redis_connection=#<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.4.4)>>, @feederboard_aggregate=#<Leaderboard:0x000001014b9090 @leaderboard_name="activity:feed:aggregate:1", @page_size=25, @redis_connection=#<Redis client v2.2.2 connected to redis://127.0.0.1:6379/0 (Redis v2.4.4)>>>
|
255
|
+
ruby-1.9.2-p290 :017 > pp feed.page(1, true)
|
256
|
+
[#<ActivityFeed::Ohm::Item:10 created_at="2011-11-29 21:18:40 UTC" updated_at="2011-11-29 21:18:40 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_5" url=nil icon=nil sticky=nil>,
|
257
|
+
#<ActivityFeed::Ohm::Item:9 created_at="2011-11-29 21:18:39 UTC" updated_at="2011-11-29 21:18:39 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_5" url=nil icon=nil sticky=nil>,
|
258
|
+
#<ActivityFeed::Ohm::Item:8 created_at="2011-11-29 21:18:38 UTC" updated_at="2011-11-29 21:18:38 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_4" url=nil icon=nil sticky=nil>,
|
259
|
+
#<ActivityFeed::Ohm::Item:7 created_at="2011-11-29 21:18:37 UTC" updated_at="2011-11-29 21:18:37 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_4" url=nil icon=nil sticky=nil>,
|
260
|
+
#<ActivityFeed::Ohm::Item:6 created_at="2011-11-29 21:18:36 UTC" updated_at="2011-11-29 21:18:36 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_3" url=nil icon=nil sticky=nil>,
|
261
|
+
#<ActivityFeed::Ohm::Item:5 created_at="2011-11-29 21:18:35 UTC" updated_at="2011-11-29 21:18:35 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_3" url=nil icon=nil sticky=nil>,
|
262
|
+
#<ActivityFeed::Ohm::Item:4 created_at="2011-11-29 21:18:34 UTC" updated_at="2011-11-29 21:18:34 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_2" url=nil icon=nil sticky=nil>,
|
263
|
+
#<ActivityFeed::Ohm::Item:3 created_at="2011-11-29 21:18:33 UTC" updated_at="2011-11-29 21:18:33 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_2" url=nil icon=nil sticky=nil>,
|
264
|
+
#<ActivityFeed::Ohm::Item:2 created_at="2011-11-29 21:18:32 UTC" updated_at="2011-11-29 21:18:32 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_1" url=nil icon=nil sticky=nil>,
|
265
|
+
#<ActivityFeed::Ohm::Item:1 created_at="2011-11-29 21:18:31 UTC" updated_at="2011-11-29 21:18:31 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_1" url=nil icon=nil sticky=nil>]
|
266
|
+
=> [#<ActivityFeed::Ohm::Item:10 created_at="2011-11-29 21:18:40 UTC" updated_at="2011-11-29 21:18:40 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_5" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:9 created_at="2011-11-29 21:18:39 UTC" updated_at="2011-11-29 21:18:39 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_5" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:8 created_at="2011-11-29 21:18:38 UTC" updated_at="2011-11-29 21:18:38 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_4" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:7 created_at="2011-11-29 21:18:37 UTC" updated_at="2011-11-29 21:18:37 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_4" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:6 created_at="2011-11-29 21:18:36 UTC" updated_at="2011-11-29 21:18:36 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_3" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:5 created_at="2011-11-29 21:18:35 UTC" updated_at="2011-11-29 21:18:35 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_3" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:4 created_at="2011-11-29 21:18:34 UTC" updated_at="2011-11-29 21:18:34 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_2" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:3 created_at="2011-11-29 21:18:33 UTC" updated_at="2011-11-29 21:18:33 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_2" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:2 created_at="2011-11-29 21:18:32 UTC" updated_at="2011-11-29 21:18:32 UTC" user_id="2" nickname="nickname_2" type=nil title=nil text="test_nickname2_1" url=nil icon=nil sticky=nil>, #<ActivityFeed::Ohm::Item:1 created_at="2011-11-29 21:18:31 UTC" updated_at="2011-11-29 21:18:31 UTC" user_id="1" nickname="nickname_1" type=nil title=nil text="text_1" url=nil icon=nil sticky=nil>]
|
267
|
+
ruby-1.9.2-p290 :018 >
|
268
|
+
```
|
269
|
+
|
219
270
|
## Contributing to Activity Feed
|
220
271
|
|
221
272
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/lib/activity_feed.rb
CHANGED
@@ -10,6 +10,8 @@ module ActivityFeed
|
|
10
10
|
mattr_accessor :namespace
|
11
11
|
mattr_accessor :key
|
12
12
|
mattr_accessor :persistence
|
13
|
+
mattr_accessor :aggregate_key
|
14
|
+
mattr_accessor :aggregate
|
13
15
|
|
14
16
|
def self.persistence=(type = :memory)
|
15
17
|
@@persistence_type = type
|
@@ -34,12 +36,25 @@ module ActivityFeed
|
|
34
36
|
@@persistence = klazz
|
35
37
|
end
|
36
38
|
|
37
|
-
def self.create_item(attributes)
|
39
|
+
def self.create_item(attributes, aggregate = ActivityFeed.aggregate)
|
38
40
|
item = @@persistence.new(attributes)
|
39
41
|
item.save
|
40
|
-
item
|
42
|
+
ActivityFeed.aggregate_item(item) if aggregate
|
43
|
+
item
|
41
44
|
end
|
42
45
|
|
46
|
+
def self.aggregate_item(item, user_id = nil)
|
47
|
+
user_id_for_aggregate = user_id.nil? ? item.user_id : user_id
|
48
|
+
case @@persistence_type
|
49
|
+
when :active_record, :mongo_mapper
|
50
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(user_id_for_aggregate, true), item.created_at.to_i, item.id)
|
51
|
+
when :ohm
|
52
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(user_id_for_aggregate, true), DateTime.parse(item.created_at).to_i, item.id)
|
53
|
+
else
|
54
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(user_id_for_aggregate, true), DateTime.now.to_i, item.attributes.to_json)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
43
58
|
def self.load_item(item_or_item_id)
|
44
59
|
case @@persistence_type
|
45
60
|
when :active_record
|
@@ -55,7 +70,17 @@ module ActivityFeed
|
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
73
|
+
def self.feed_key(user_id, aggregate = false)
|
74
|
+
if aggregate
|
75
|
+
"#{ActivityFeed.namespace}:#{ActivityFeed.key}:#{ActivityFeed.aggregate_key}:#{user_id}"
|
76
|
+
else
|
77
|
+
"#{ActivityFeed.namespace}:#{ActivityFeed.key}:#{user_id}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
58
81
|
self.namespace = 'activity'
|
59
82
|
self.key = 'feed'
|
83
|
+
self.aggregate_key = 'aggregate'
|
84
|
+
self.aggregate = true
|
60
85
|
self.persistence = :memory
|
61
86
|
end
|
@@ -10,7 +10,7 @@ module ActivityFeed
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def update_redis
|
13
|
-
ActivityFeed.redis.zadd(
|
13
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), self.created_at.to_i, self.id)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/activity_feed/feed.rb
CHANGED
@@ -3,24 +3,27 @@ require 'leaderboard'
|
|
3
3
|
module ActivityFeed
|
4
4
|
class Feed
|
5
5
|
def initialize(user_id)
|
6
|
-
@feederboard = Leaderboard.new(
|
6
|
+
@feederboard = Leaderboard.new(ActivityFeed.feed_key(user_id), Leaderboard::DEFAULT_OPTIONS, {:redis_connection => ActivityFeed.redis})
|
7
|
+
@feederboard_aggregate = Leaderboard.new(ActivityFeed.feed_key(user_id, true), Leaderboard::DEFAULT_OPTIONS, {:redis_connection => ActivityFeed.redis})
|
7
8
|
end
|
8
9
|
|
9
|
-
def page(page)
|
10
|
+
def page(page, aggregate = false)
|
10
11
|
feed_items = []
|
11
|
-
|
12
|
+
|
13
|
+
feed = aggregate ? @feederboard_aggregate : @feederboard
|
14
|
+
feed.leaders(page).each do |feed_item|
|
12
15
|
feed_items << ActivityFeed.load_item(feed_item[:member])
|
13
16
|
end
|
14
17
|
|
15
18
|
feed_items
|
16
19
|
end
|
17
20
|
|
18
|
-
def total_pages
|
19
|
-
@feederboard.total_pages
|
21
|
+
def total_pages(aggregate = false)
|
22
|
+
aggregate ? @feederboard_aggregate.total_pages : @feederboard.total_pages
|
20
23
|
end
|
21
24
|
|
22
|
-
def total_items
|
23
|
-
@feederboard.total_members
|
25
|
+
def total_items(aggregate = false)
|
26
|
+
aggregate ? @feederboard_aggregate.total_members : @feederboard.total_members
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -21,11 +21,15 @@ module ActivityFeed
|
|
21
21
|
self.send("#{key}=", value)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def attributes
|
26
|
+
@attributes
|
27
|
+
end
|
24
28
|
|
25
29
|
def save
|
26
30
|
raise 'user_id MUST be defined in the attributes' if user_id.blank?
|
27
31
|
|
28
|
-
ActivityFeed.redis.zadd(
|
32
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), DateTime.now.to_i, @attributes.to_json)
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -23,7 +23,7 @@ module ActivityFeed
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def update_redis
|
26
|
-
ActivityFeed.redis.zadd(
|
26
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), self.created_at.to_i, self.id)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -21,7 +21,7 @@ module ActivityFeed
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def update_redis
|
24
|
-
ActivityFeed.redis.zadd(
|
24
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), DateTime.parse(self.created_at).to_i, self.id)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -17,6 +17,10 @@ module ActivityFeed
|
|
17
17
|
self.send("#{key}=", value)
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def attributes
|
22
|
+
@attributes
|
23
|
+
end
|
20
24
|
|
21
25
|
def self.find(item)
|
22
26
|
JSON.parse(item)
|
@@ -25,7 +29,7 @@ module ActivityFeed
|
|
25
29
|
def save
|
26
30
|
raise 'user_id MUST be defined in the attributes' if user_id.blank?
|
27
31
|
|
28
|
-
ActivityFeed.redis.zadd(
|
32
|
+
ActivityFeed.redis.zadd(ActivityFeed.feed_key(self.user_id), DateTime.now.to_i, @attributes.to_json)
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
data/spec/activity_feed_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActivityFeed do
|
4
|
-
it 'should have defaults set
|
4
|
+
it 'should have defaults set' do
|
5
5
|
ActivityFeed.namespace.should eql('activity')
|
6
6
|
ActivityFeed.key.should eql('feed')
|
7
7
|
ActivityFeed.persistence = :memory
|
8
8
|
ActivityFeed.persistence.should be(ActivityFeed::Memory::Item)
|
9
|
+
ActivityFeed.aggregate_key.should eql('aggregate')
|
10
|
+
ActivityFeed.aggregate.should be(true)
|
9
11
|
end
|
10
12
|
|
11
13
|
describe 'creating' do
|
@@ -13,9 +15,10 @@ describe ActivityFeed do
|
|
13
15
|
user_id = 1
|
14
16
|
ActivityFeed.persistence = :memory
|
15
17
|
|
16
|
-
ActivityFeed.redis.zcard(
|
17
|
-
ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
18
|
-
ActivityFeed.redis.zcard(
|
18
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
19
|
+
activity_feed_item = ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
20
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
21
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(1)
|
19
22
|
end
|
20
23
|
|
21
24
|
it 'should allow you to create a new item using :mongo_mapper' do
|
@@ -23,9 +26,10 @@ describe ActivityFeed do
|
|
23
26
|
ActivityFeed.persistence = :mongo_mapper
|
24
27
|
|
25
28
|
ActivityFeed::MongoMapper::Item.count.should be(0)
|
26
|
-
ActivityFeed.redis.zcard(
|
27
|
-
ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
28
|
-
ActivityFeed.redis.zcard(
|
29
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
30
|
+
activity_feed_item = ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
31
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
32
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(1)
|
29
33
|
ActivityFeed::MongoMapper::Item.count.should be(1)
|
30
34
|
end
|
31
35
|
|
@@ -34,9 +38,10 @@ describe ActivityFeed do
|
|
34
38
|
ActivityFeed.persistence = :active_record
|
35
39
|
|
36
40
|
ActivityFeed::ActiveRecord::Item.count.should be(0)
|
37
|
-
ActivityFeed.redis.zcard(
|
38
|
-
ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
39
|
-
ActivityFeed.redis.zcard(
|
41
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
42
|
+
activity_feed_item = ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
43
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
44
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(1)
|
40
45
|
ActivityFeed::ActiveRecord::Item.count.should be(1)
|
41
46
|
end
|
42
47
|
|
@@ -45,9 +50,22 @@ describe ActivityFeed do
|
|
45
50
|
ActivityFeed.persistence = :ohm
|
46
51
|
|
47
52
|
ActivityFeed::Ohm::Item.all.count.should be(0)
|
48
|
-
ActivityFeed.redis.zcard(
|
49
|
-
ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
50
|
-
ActivityFeed.redis.zcard(
|
53
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
54
|
+
activity_feed_item = ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
55
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
56
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(1)
|
57
|
+
ActivityFeed::Ohm::Item.all.count.should be(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should allow you to create a new item and not aggregate the item' do
|
61
|
+
user_id = 1
|
62
|
+
ActivityFeed.persistence = :ohm
|
63
|
+
|
64
|
+
ActivityFeed::Ohm::Item.all.count.should be(0)
|
65
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
66
|
+
activity_feed_item = ActivityFeed.create_item({:user_id => user_id, :text => 'This is text for my activity feed'}, false)
|
67
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
68
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(0)
|
51
69
|
ActivityFeed::Ohm::Item.all.count.should be(1)
|
52
70
|
end
|
53
71
|
end
|
@@ -99,9 +117,11 @@ describe ActivityFeed do
|
|
99
117
|
user_id = 1
|
100
118
|
ActivityFeed.persistence = :custom
|
101
119
|
|
102
|
-
ActivityFeed.redis.zcard(
|
103
|
-
ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
104
|
-
ActivityFeed.redis.zcard(
|
120
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(0)
|
121
|
+
activity_feed_item = ActivityFeed.create_item(:user_id => user_id, :text => 'This is text for my activity feed')
|
122
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
|
123
|
+
ActivityFeed.aggregate_item(activity_feed_item)
|
124
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id, true)).should be(1)
|
105
125
|
end
|
106
126
|
|
107
127
|
it 'should allow you to load an item using a custom persistence handler class' do
|
data/spec/feed_spec.rb
CHANGED
@@ -64,6 +64,22 @@ describe ActivityFeed::Feed do
|
|
64
64
|
feed.total_pages.should be(2)
|
65
65
|
end
|
66
66
|
|
67
|
+
describe 'feed aggregation' do
|
68
|
+
it 'should pull up the correct list of items from an aggregated activity feed' do
|
69
|
+
ActivityFeed.persistence = :ohm
|
70
|
+
1.upto(5) do |index|
|
71
|
+
item = ActivityFeed.create_item(:user_id => 1, :nickname => 'nickname_1', :text => "text_#{index}")
|
72
|
+
another_item = ActivityFeed.create_item(:user_id => 2, :nickname => 'nickname_2', :text => "test_another_item_#{index}")
|
73
|
+
ActivityFeed.aggregate_item(another_item, 1)
|
74
|
+
end
|
75
|
+
|
76
|
+
feed = ActivityFeed::Feed.new(1)
|
77
|
+
feed.total_pages(true).should be(1)
|
78
|
+
feed.total_items(true).should be(10)
|
79
|
+
feed.page(1, true).size.should be(10)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
67
83
|
describe 'custom persistence' do
|
68
84
|
it 'should allow you to pull up the correct list of ActivityFeed::Custom::Item when calling #page using :custom' do
|
69
85
|
ActivityFeed.persistence = :custom
|
data/spec/item_spec.rb
CHANGED
@@ -14,9 +14,11 @@ describe 'ActivityFeed::Item' do
|
|
14
14
|
it 'should add the feed item ID to redis' do
|
15
15
|
item = Fabricate.build(ActivityFeed.persistence)
|
16
16
|
|
17
|
-
ActivityFeed.redis.zcard(
|
17
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(0)
|
18
18
|
item.save
|
19
|
-
ActivityFeed.redis.zcard(
|
19
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
|
20
|
+
ActivityFeed.aggregate_item(item)
|
21
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should have default attributes for .title .url .icon and .sticky' do
|
@@ -31,12 +33,16 @@ describe 'ActivityFeed::Item' do
|
|
31
33
|
it 'should not create a new item in Redis after saving, only on create' do
|
32
34
|
item = Fabricate.build(ActivityFeed::Memory::Item)
|
33
35
|
|
34
|
-
ActivityFeed.redis.zcard(
|
36
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(0)
|
35
37
|
item.save
|
36
|
-
ActivityFeed.redis.zcard(
|
38
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
|
39
|
+
ActivityFeed.aggregate_item(item)
|
40
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
|
37
41
|
|
38
42
|
item.text = 'updated text'
|
39
43
|
item.save
|
40
|
-
ActivityFeed.redis.zcard(
|
44
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id)).should be(1)
|
45
|
+
ActivityFeed.aggregate_item(item)
|
46
|
+
ActivityFeed.redis.zcard(ActivityFeed.feed_key(item.user_id, true)).should be(1)
|
41
47
|
end
|
42
48
|
end
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,199 +1,203 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: activity_feed
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: "1.2"
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- David Czarnecki
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-11-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake
|
16
|
-
requirement: &
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
26
27
|
name: rspec
|
27
|
-
requirement: &
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version:
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
37
38
|
name: database_cleaner
|
38
|
-
requirement: &
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
44
45
|
type: :development
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
48
49
|
name: fabrication
|
49
|
-
requirement: &
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
55
56
|
type: :development
|
56
57
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
-
- !ruby/object:Gem::Dependency
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
59
60
|
name: mongo_mapper
|
60
|
-
requirement: &
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
61
62
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version:
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
66
67
|
type: :development
|
67
68
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
70
71
|
name: mongo_ext
|
71
|
-
requirement: &
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
72
73
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version:
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
77
78
|
type: :development
|
78
79
|
prerelease: false
|
79
|
-
version_requirements: *
|
80
|
-
- !ruby/object:Gem::Dependency
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
81
82
|
name: bson_ext
|
82
|
-
requirement: &
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
83
84
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
88
89
|
type: :development
|
89
90
|
prerelease: false
|
90
|
-
version_requirements: *
|
91
|
-
- !ruby/object:Gem::Dependency
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
92
93
|
name: activerecord
|
93
|
-
requirement: &
|
94
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
94
95
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version:
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
99
100
|
type: :development
|
100
101
|
prerelease: false
|
101
|
-
version_requirements: *
|
102
|
-
- !ruby/object:Gem::Dependency
|
102
|
+
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
103
104
|
name: sqlite3
|
104
|
-
requirement: &
|
105
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
105
106
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version:
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
110
111
|
type: :development
|
111
112
|
prerelease: false
|
112
|
-
version_requirements: *
|
113
|
-
- !ruby/object:Gem::Dependency
|
113
|
+
version_requirements: *id009
|
114
|
+
- !ruby/object:Gem::Dependency
|
114
115
|
name: ohm
|
115
|
-
requirement: &
|
116
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
116
117
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version:
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
121
122
|
type: :development
|
122
123
|
prerelease: false
|
123
|
-
version_requirements: *
|
124
|
-
- !ruby/object:Gem::Dependency
|
124
|
+
version_requirements: *id010
|
125
|
+
- !ruby/object:Gem::Dependency
|
125
126
|
name: ohm-contrib
|
126
|
-
requirement: &
|
127
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
127
128
|
none: false
|
128
|
-
requirements:
|
129
|
-
- -
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version:
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: "0"
|
132
133
|
type: :development
|
133
134
|
prerelease: false
|
134
|
-
version_requirements: *
|
135
|
-
- !ruby/object:Gem::Dependency
|
135
|
+
version_requirements: *id011
|
136
|
+
- !ruby/object:Gem::Dependency
|
136
137
|
name: activesupport
|
137
|
-
requirement: &
|
138
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
138
139
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
version:
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: "0"
|
143
144
|
type: :runtime
|
144
145
|
prerelease: false
|
145
|
-
version_requirements: *
|
146
|
-
- !ruby/object:Gem::Dependency
|
146
|
+
version_requirements: *id012
|
147
|
+
- !ruby/object:Gem::Dependency
|
147
148
|
name: i18n
|
148
|
-
requirement: &
|
149
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
149
150
|
none: false
|
150
|
-
requirements:
|
151
|
-
- -
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version:
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: "0"
|
154
155
|
type: :runtime
|
155
156
|
prerelease: false
|
156
|
-
version_requirements: *
|
157
|
-
- !ruby/object:Gem::Dependency
|
157
|
+
version_requirements: *id013
|
158
|
+
- !ruby/object:Gem::Dependency
|
158
159
|
name: json
|
159
|
-
requirement: &
|
160
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
160
161
|
none: false
|
161
|
-
requirements:
|
162
|
-
- -
|
163
|
-
- !ruby/object:Gem::Version
|
164
|
-
version:
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: "0"
|
165
166
|
type: :runtime
|
166
167
|
prerelease: false
|
167
|
-
version_requirements: *
|
168
|
-
- !ruby/object:Gem::Dependency
|
168
|
+
version_requirements: *id014
|
169
|
+
- !ruby/object:Gem::Dependency
|
169
170
|
name: redis
|
170
|
-
requirement: &
|
171
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
171
172
|
none: false
|
172
|
-
requirements:
|
173
|
-
- -
|
174
|
-
- !ruby/object:Gem::Version
|
175
|
-
version:
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: "0"
|
176
177
|
type: :runtime
|
177
178
|
prerelease: false
|
178
|
-
version_requirements: *
|
179
|
-
- !ruby/object:Gem::Dependency
|
179
|
+
version_requirements: *id015
|
180
|
+
- !ruby/object:Gem::Dependency
|
180
181
|
name: leaderboard
|
181
|
-
requirement: &
|
182
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
182
183
|
none: false
|
183
|
-
requirements:
|
184
|
-
- -
|
185
|
-
- !ruby/object:Gem::Version
|
186
|
-
version:
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: "0"
|
187
188
|
type: :runtime
|
188
189
|
prerelease: false
|
189
|
-
version_requirements: *
|
190
|
+
version_requirements: *id016
|
190
191
|
description: Activity feeds backed by Redis
|
191
|
-
email:
|
192
|
+
email:
|
192
193
|
- dczarnecki@agoragames.com
|
193
194
|
executables: []
|
195
|
+
|
194
196
|
extensions: []
|
197
|
+
|
195
198
|
extra_rdoc_files: []
|
196
|
-
|
199
|
+
|
200
|
+
files:
|
197
201
|
- .gitignore
|
198
202
|
- .rvmrc
|
199
203
|
- CHANGELOG.markdown
|
@@ -218,29 +222,38 @@ files:
|
|
218
222
|
- spec/version_spec.rb
|
219
223
|
homepage: https://github.com/agoragames/activity_feed
|
220
224
|
licenses: []
|
225
|
+
|
221
226
|
post_install_message:
|
222
227
|
rdoc_options: []
|
223
|
-
|
228
|
+
|
229
|
+
require_paths:
|
224
230
|
- lib
|
225
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
231
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
226
232
|
none: false
|
227
|
-
requirements:
|
228
|
-
- -
|
229
|
-
- !ruby/object:Gem::Version
|
230
|
-
|
231
|
-
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
hash: 2506402929405040614
|
237
|
+
segments:
|
238
|
+
- 0
|
239
|
+
version: "0"
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
241
|
none: false
|
233
|
-
requirements:
|
234
|
-
- -
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
hash: 2506402929405040614
|
246
|
+
segments:
|
247
|
+
- 0
|
248
|
+
version: "0"
|
237
249
|
requirements: []
|
250
|
+
|
238
251
|
rubyforge_project: activity_feed
|
239
|
-
rubygems_version: 1.8.
|
252
|
+
rubygems_version: 1.8.11
|
240
253
|
signing_key:
|
241
254
|
specification_version: 3
|
242
255
|
summary: Activity feeds backed by Redis
|
243
|
-
test_files:
|
256
|
+
test_files:
|
244
257
|
- spec/activity_feed/custom/item.rb
|
245
258
|
- spec/activity_feed_spec.rb
|
246
259
|
- spec/fabricators/item_fabricator.rb
|