activity_feed 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/CHANGELOG.markdown CHANGED
@@ -1,9 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.0
4
+
5
+ * `ActivityFeed.update_item(user_id, item_id, timestamp, aggregate = false)` allows for updating an activity feed item in the personal or aggregate feed
6
+ * `ActivityFeed.delete_item(user_id, item_id, aggregate = false)` allows for removing an activity feed item from the personal or aggregate feed
7
+
8
+ ## 1.2.2
9
+
10
+ * `ActivityFeed.create_item(attributes, aggregate)` can take an array of user_ids as its 2nd parameter if you want to fan out to the aggregation on create
11
+
3
12
  ## 1.2.1
4
13
 
5
- * ActivityFeed.feed(user_id) will now return an instance of ActivityFeed::Feed
6
- * ActivityFeed::Ohm::Item will now return all of its attributes when calling to_json
14
+ * `ActivityFeed.feed(user_id)` will now return an instance of ActivityFeed::Feed
15
+ * `ActivityFeed::Ohm::Item` will now return all of its attributes when calling `to_json`
7
16
 
8
17
  ## 1.2
9
18
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 David Czarnecki
1
+ Copyright (c) 2011-2012 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.markdown CHANGED
@@ -279,6 +279,19 @@ ruby-1.9.2-p290 :017 > pp feed.page(1, true)
279
279
  ruby-1.9.2-p290 :018 >
280
280
  ```
281
281
 
282
+ ### Updating and Removing Activity Feed Items
283
+
284
+ You can use the following methods to update and removing activity feed items, respectively:
285
+
286
+ ```ruby
287
+ ActivityFeed.update_item(user_id, item_id, timestamp, aggregate = false)
288
+ ActivityFeed.delete_item(user_id, item_id, aggregate = false)
289
+ ```
290
+
291
+ ## Future Plans
292
+
293
+ * Suggestions?
294
+
282
295
  ## Contributing to Activity Feed
283
296
 
284
297
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -291,4 +304,4 @@ ruby-1.9.2-p290 :018 >
291
304
 
292
305
  ## Copyright
293
306
 
294
- Copyright (c) 2011 David Czarnecki. See LICENSE.txt for further details.
307
+ Copyright (c) 2011-2012 David Czarnecki. See LICENSE.txt for further details.
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
33
33
 
34
34
  s.add_development_dependency('ohm')
35
35
  s.add_development_dependency('ohm-contrib')
36
+
37
+ s.add_development_dependency('timecop')
36
38
 
37
39
  s.add_dependency('activesupport')
38
40
  s.add_dependency('i18n')
@@ -1,3 +1,3 @@
1
1
  module ActivityFeed
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/activity_feed.rb CHANGED
@@ -39,7 +39,11 @@ module ActivityFeed
39
39
  def self.create_item(attributes, aggregate = ActivityFeed.aggregate)
40
40
  item = @@persistence.new(attributes)
41
41
  item.save
42
- ActivityFeed.aggregate_item(item) if aggregate
42
+ if aggregate
43
+ ([item.user_id] | Array(aggregate)).each do |aggregation_id|
44
+ ActivityFeed.aggregate_item(item, aggregation_id)
45
+ end
46
+ end
43
47
  item
44
48
  end
45
49
 
@@ -69,7 +73,21 @@ module ActivityFeed
69
73
  @@persistence.find(item_or_item_id)
70
74
  end
71
75
  end
72
-
76
+
77
+ def self.update_item(user_id, item_id, timestamp, aggregate = false)
78
+ unless @@persistence_type == :memory
79
+ key = feed_key(user_id, aggregate)
80
+ ActivityFeed.redis.zadd(key, timestamp, item_id)
81
+ end
82
+ end
83
+
84
+ def self.delete_item(user_id, item_id, aggregate = false)
85
+ unless @@persistence_type == :memory
86
+ key = feed_key(user_id, aggregate)
87
+ ActivityFeed.redis.zrem(key, item_id)
88
+ end
89
+ end
90
+
73
91
  def self.feed_key(user_id, aggregate = false)
74
92
  if aggregate
75
93
  "#{ActivityFeed.namespace}:#{ActivityFeed.key}:#{ActivityFeed.aggregate_key}:#{user_id}"
@@ -85,6 +103,6 @@ module ActivityFeed
85
103
  self.namespace = 'activity'
86
104
  self.key = 'feed'
87
105
  self.aggregate_key = 'aggregate'
88
- self.aggregate = true
106
+ self.aggregate = []
89
107
  self.persistence = :memory
90
108
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'timecop'
2
3
 
3
4
  describe ActivityFeed do
4
5
  it 'should have defaults set' do
@@ -7,7 +8,7 @@ describe ActivityFeed do
7
8
  ActivityFeed.persistence = :memory
8
9
  ActivityFeed.persistence.should be(ActivityFeed::Memory::Item)
9
10
  ActivityFeed.aggregate_key.should eql('aggregate')
10
- ActivityFeed.aggregate.should be(true)
11
+ ActivityFeed.aggregate.should == []
11
12
  end
12
13
 
13
14
  describe 'creating' do
@@ -145,4 +146,111 @@ describe ActivityFeed do
145
146
  feed.total_items.should be(1)
146
147
  end
147
148
  end
149
+
150
+ describe "create_item" do
151
+ let(:user_id) { 1 }
152
+ let(:friend_ids) { [99, 1337] }
153
+ let(:item_attrs) {
154
+ { "user_id" => user_id, "text" => 'This is my happy activity' }
155
+ }
156
+
157
+ context "with no explicit aggregation set" do
158
+ it "just creates the item and saves it to the user's feed" do
159
+ ActivityFeed.create_item(item_attrs)
160
+ ActivityFeed.redis.zcard(ActivityFeed.feed_key(user_id)).should be(1)
161
+ feed = ActivityFeed::Feed.new(user_id)
162
+ feed.page(1).first.should == item_attrs
163
+ end
164
+ end
165
+
166
+ context "with the optional second parameter set to a falsy value" do
167
+ it "only creates the item--without adding it to the aggregation feed" do
168
+ ActivityFeed.create_item(item_attrs, false)
169
+ feed = ActivityFeed::Feed.new(user_id)
170
+ feed.page(1).size.should be(1) # user-only feed
171
+ feed.page(1, true).should be_empty # aggregation feed
172
+ end
173
+ end
174
+
175
+ context "with a list of aggregation ids as a second parameter" do
176
+ it "creates the item and aggregates it out to all the feeds" do
177
+ ActivityFeed.create_item(item_attrs, friend_ids)
178
+ ( friend_ids << user_id ).each do |id|
179
+ feed = ActivityFeed::Feed.new(id)
180
+ feed.page(1, true).first.should == item_attrs
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "delete_item" do
187
+ let(:user_id) { 1 }
188
+ let(:item_attrs) {
189
+ { "user_id" => user_id, "text" => 'This is my happy activity' }
190
+ }
191
+
192
+ context "non-memory backed persistence" do
193
+ before(:each) do
194
+ ActivityFeed.persistence = :ohm
195
+ @item = ActivityFeed.create_item(item_attrs, true)
196
+ end
197
+
198
+ it "should allow you to delete an item from the personal activity feed" do
199
+ feed = ActivityFeed::Feed.new(user_id)
200
+ feed.total_items.should == 1
201
+ ActivityFeed.delete_item(user_id, @item.id)
202
+ feed.total_items.should == 0
203
+ end
204
+
205
+ it "should allow you to delete an item from the personal aggregate feed" do
206
+ feed = ActivityFeed::Feed.new(user_id)
207
+ feed.total_items(true).should == 1
208
+ ActivityFeed.delete_item(user_id, @item.id, true)
209
+ feed.total_items(true).should == 0
210
+ end
211
+ end
212
+ end
213
+
214
+ describe "update_item" do
215
+ let(:user_id) { 1 }
216
+ let(:item_attrs) {
217
+ { "user_id" => user_id, "text" => 'This is my happy activity' }
218
+ }
219
+
220
+ it "should allow you to update an item from the personal activity feed" do
221
+ ActivityFeed.persistence = :ohm
222
+
223
+ item_1 = ActivityFeed.create_item(item_attrs, false)
224
+ Timecop.travel(DateTime.now + 10)
225
+ item_2 = ActivityFeed.create_item(item_attrs, false)
226
+ Timecop.travel(DateTime.now + 10)
227
+ item_3 = ActivityFeed.create_item(item_attrs, false)
228
+ Timecop.travel(DateTime.now + 10)
229
+
230
+ feed = ActivityFeed::Feed.new(user_id)
231
+ feed.page(1).first.id.should == '3'
232
+
233
+ ActivityFeed.update_item(user_id, 1, DateTime.now.to_i)
234
+ feed.page(1).first.id.should == '1'
235
+ Timecop.return
236
+ end
237
+
238
+ it "should allow you to update an item from the personal aggregate feed" do
239
+ ActivityFeed.persistence = :ohm
240
+
241
+ item_1 = ActivityFeed.create_item(item_attrs, true)
242
+ Timecop.travel(DateTime.now + 10)
243
+ item_2 = ActivityFeed.create_item(item_attrs, true)
244
+ Timecop.travel(DateTime.now + 10)
245
+ item_3 = ActivityFeed.create_item(item_attrs, true)
246
+ Timecop.travel(DateTime.now + 10)
247
+
248
+ feed = ActivityFeed::Feed.new(user_id)
249
+ feed.page(1, true).first.id.should == '3'
250
+
251
+ ActivityFeed.update_item(user_id, 1, DateTime.now.to_i, true)
252
+ feed.page(1, true).first.id.should == '1'
253
+ Timecop.return
254
+ end
255
+ end
148
256
  end
data/spec/item_spec.rb CHANGED
@@ -49,7 +49,7 @@ describe 'ActivityFeed::Item' do
49
49
  it 'should output all the attributes for an item for Ohm' do
50
50
  item = Fabricate.build(ActivityFeed::Ohm::Item)
51
51
 
52
- hash = JSON.parse(JSON.generate(item))
52
+ hash = JSON.parse(item.to_json)
53
53
  hash.keys.size.should be(8)
54
54
  end
55
55
  end
data/spec/spec_helper.rb CHANGED
@@ -46,6 +46,10 @@ require 'activity_feed'
46
46
 
47
47
  ActivityFeed.redis = $redis
48
48
 
49
+ require 'activity_feed/active_record/item'
50
+ require 'activity_feed/memory/item'
51
+ require 'activity_feed/mongo_mapper/item'
52
+ require 'activity_feed/ohm/item'
49
53
  require 'activity_feed/custom/item'
50
54
 
51
55
  RSpec.configure do |config|
data/spec/version_spec.rb CHANGED
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe ActivityFeed do
4
4
  it "should be the correct version" do
5
- ActivityFeed::VERSION.should == '1.2.1'
5
+ ActivityFeed::VERSION.should == '1.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-05 00:00:00.000000000 Z
12
+ date: 2012-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2160989100 !ruby/object:Gem::Requirement
16
+ requirement: &2152337140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2160989100
24
+ version_requirements: *2152337140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2160988660 !ruby/object:Gem::Requirement
27
+ requirement: &2152334740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2160988660
35
+ version_requirements: *2152334740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: database_cleaner
38
- requirement: &2160988200 !ruby/object:Gem::Requirement
38
+ requirement: &2152332900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160988200
46
+ version_requirements: *2152332900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fabrication
49
- requirement: &2160987760 !ruby/object:Gem::Requirement
49
+ requirement: &2152331820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160987760
57
+ version_requirements: *2152331820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mongo_mapper
60
- requirement: &2160987340 !ruby/object:Gem::Requirement
60
+ requirement: &2152352640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160987340
68
+ version_requirements: *2152352640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mongo_ext
71
- requirement: &2160986860 !ruby/object:Gem::Requirement
71
+ requirement: &2152350760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2160986860
79
+ version_requirements: *2152350760
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bson_ext
82
- requirement: &2160986440 !ruby/object:Gem::Requirement
82
+ requirement: &2152349740 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2160986440
90
+ version_requirements: *2152349740
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &2160985960 !ruby/object:Gem::Requirement
93
+ requirement: &2152348380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2160985960
101
+ version_requirements: *2152348380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sqlite3
104
- requirement: &2160846320 !ruby/object:Gem::Requirement
104
+ requirement: &2152346760 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2160846320
112
+ version_requirements: *2152346760
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: ohm
115
- requirement: &2160845880 !ruby/object:Gem::Requirement
115
+ requirement: &2152367940 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2160845880
123
+ version_requirements: *2152367940
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: ohm-contrib
126
- requirement: &2160845460 !ruby/object:Gem::Requirement
126
+ requirement: &2152367000 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,21 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2160845460
134
+ version_requirements: *2152367000
135
+ - !ruby/object:Gem::Dependency
136
+ name: timecop
137
+ requirement: &2152365760 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *2152365760
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: activesupport
137
- requirement: &2160845000 !ruby/object:Gem::Requirement
148
+ requirement: &2152364200 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,10 +153,10 @@ dependencies:
142
153
  version: '0'
143
154
  type: :runtime
144
155
  prerelease: false
145
- version_requirements: *2160845000
156
+ version_requirements: *2152364200
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: i18n
148
- requirement: &2160844520 !ruby/object:Gem::Requirement
159
+ requirement: &2152363160 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - ! '>='
@@ -153,10 +164,10 @@ dependencies:
153
164
  version: '0'
154
165
  type: :runtime
155
166
  prerelease: false
156
- version_requirements: *2160844520
167
+ version_requirements: *2152363160
157
168
  - !ruby/object:Gem::Dependency
158
169
  name: json
159
- requirement: &2160844000 !ruby/object:Gem::Requirement
170
+ requirement: &2152361640 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
173
  - - ! '>='
@@ -164,10 +175,10 @@ dependencies:
164
175
  version: '0'
165
176
  type: :runtime
166
177
  prerelease: false
167
- version_requirements: *2160844000
178
+ version_requirements: *2152361640
168
179
  - !ruby/object:Gem::Dependency
169
180
  name: redis
170
- requirement: &2160843300 !ruby/object:Gem::Requirement
181
+ requirement: &2152384420 !ruby/object:Gem::Requirement
171
182
  none: false
172
183
  requirements:
173
184
  - - ! '>='
@@ -175,10 +186,10 @@ dependencies:
175
186
  version: '0'
176
187
  type: :runtime
177
188
  prerelease: false
178
- version_requirements: *2160843300
189
+ version_requirements: *2152384420
179
190
  - !ruby/object:Gem::Dependency
180
191
  name: leaderboard
181
- requirement: &2160842220 !ruby/object:Gem::Requirement
192
+ requirement: &2152382940 !ruby/object:Gem::Requirement
182
193
  none: false
183
194
  requirements:
184
195
  - - ! '>='
@@ -186,7 +197,7 @@ dependencies:
186
197
  version: '0'
187
198
  type: :runtime
188
199
  prerelease: false
189
- version_requirements: *2160842220
200
+ version_requirements: *2152382940
190
201
  description: Activity feeds backed by Redis
191
202
  email:
192
203
  - dczarnecki@agoragames.com
@@ -195,6 +206,7 @@ extensions: []
195
206
  extra_rdoc_files: []
196
207
  files:
197
208
  - .gitignore
209
+ - .rspec
198
210
  - .rvmrc
199
211
  - CHANGELOG.markdown
200
212
  - Gemfile
@@ -230,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
242
  version: '0'
231
243
  segments:
232
244
  - 0
233
- hash: 680484865266501391
245
+ hash: 4587144125303236754
234
246
  required_rubygems_version: !ruby/object:Gem::Requirement
235
247
  none: false
236
248
  requirements:
@@ -239,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
251
  version: '0'
240
252
  segments:
241
253
  - 0
242
- hash: 680484865266501391
254
+ hash: 4587144125303236754
243
255
  requirements: []
244
256
  rubyforge_project: activity_feed
245
257
  rubygems_version: 1.8.10