public_activity 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,76 +6,75 @@ describe PublicActivity::Tracked do
6
6
  describe 'defining instance options' do
7
7
  subject { article.new }
8
8
  let :options do
9
- { :key => 'key',
10
- :params => {:a => 1},
11
- :owner => User.create,
12
- :recipient => User.create }
9
+ {
10
+ key: 'key',
11
+ params: { a: 1 },
12
+ owner: User.create,
13
+ recipient: User.create
14
+ }
13
15
  end
14
16
  before(:each) { subject.activity(options) }
15
- let(:activity){ subject.save; subject.activities.last }
17
+ let(:activity) { subject.save; subject.activities.last }
16
18
 
17
- specify { subject.activity_key.must_be_same_as options[:key] }
18
- specify { activity.key.must_equal options[:key] }
19
+ specify { assert_same subject.activity_key, options[:key] }
20
+ specify { assert_equal activity.key, options[:key] }
19
21
 
20
- specify { subject.activity_owner.must_be_same_as options[:owner] }
21
- specify { activity.owner.must_equal options[:owner] }
22
+ specify { assert_same subject.activity_owner, options[:owner] }
23
+ specify { assert_equal activity.owner, options[:owner] }
22
24
 
23
- specify { subject.activity_params.must_be_same_as options[:params] }
24
- specify { activity.parameters.must_equal options[:params] }
25
+ specify { assert_same subject.activity_params, options[:params] }
26
+ specify { assert_equal activity.parameters, options[:params] }
25
27
 
26
- specify { subject.activity_recipient.must_be_same_as options[:recipient] }
27
- specify { activity.recipient.must_equal options[:recipient] }
28
+ specify { assert_same subject.activity_recipient, options[:recipient] }
29
+ specify { assert_equal activity.recipient, options[:recipient] }
28
30
  end
29
31
 
30
32
  it 'can be tracked and be an activist at the same time' do
31
33
  case PublicActivity.config.orm
32
- when :mongoid
33
- class ActivistAndTrackedArticle
34
- include Mongoid::Document
35
- include Mongoid::Timestamps
36
- include PublicActivity::Model
37
-
38
- if ::Mongoid::VERSION.split('.')[0].to_i >= 7
39
- belongs_to :user, optional: true
40
- else
41
- belongs_to :user
42
- end
43
-
44
- field :name, type: String
45
- field :published, type: Boolean
46
- tracked
47
- activist
48
- end
49
- when :mongo_mapper
50
- class ActivistAndTrackedArticle
51
- include MongoMapper::Document
52
- include PublicActivity::Model
53
-
54
- belongs_to :user
55
-
56
- key :name, String
57
- key :published, Boolean
58
- tracked
59
- activist
60
- timestamps!
61
- end
62
- when :active_record
63
- class ActivistAndTrackedArticle < ActiveRecord::Base
64
- self.table_name = 'articles'
65
- include PublicActivity::Model
66
- tracked
67
- activist
68
-
69
- if ::ActiveRecord::VERSION::MAJOR < 4
70
- attr_accessible :name, :published, :user
71
- end
34
+ when :mongoid
35
+ class ActivistAndTrackedArticle
36
+ include Mongoid::Document
37
+ include Mongoid::Timestamps
38
+ include PublicActivity::Model
39
+
40
+ if ::Mongoid::VERSION.split('.')[0].to_i >= 7
41
+ belongs_to :user, optional: true
42
+ else
72
43
  belongs_to :user
73
44
  end
45
+
46
+ field :name, type: String
47
+ field :published, type: Boolean
48
+ tracked
49
+ activist
50
+ end
51
+ when :mongo_mapper
52
+ class ActivistAndTrackedArticle
53
+ include MongoMapper::Document
54
+ include PublicActivity::Model
55
+
56
+ belongs_to :user
57
+
58
+ key :name, String
59
+ key :published, Boolean
60
+ tracked
61
+ activist
62
+ timestamps!
63
+ end
64
+ when :active_record
65
+ class ActivistAndTrackedArticle < ActiveRecord::Base
66
+ self.table_name = 'articles'
67
+ include PublicActivity::Model
68
+ tracked
69
+ activist
70
+
71
+ belongs_to :user
72
+ end
74
73
  end
75
74
 
76
75
  art = ActivistAndTrackedArticle.new
77
76
  art.save
78
- art.activities.last.trackable_id.must_equal art.id
77
+ assert_equal art.activities.last.trackable_id, art.id
79
78
  assert_nil art.activities.last.owner_id
80
79
  end
81
80
 
@@ -84,13 +83,13 @@ describe PublicActivity::Tracked do
84
83
  it 'should resolve symbols' do
85
84
  a = article(nonstandard: :name).new(name: 'Symbol resolved')
86
85
  a.save
87
- a.activities.last.nonstandard.must_equal 'Symbol resolved'
86
+ assert_equal a.activities.last.nonstandard, 'Symbol resolved'
88
87
  end
89
88
 
90
89
  it 'should resolve procs' do
91
- a = article(nonstandard: proc {|_, model| model.name}).new(name: 'Proc resolved')
90
+ a = article(nonstandard: proc { |_, model| model.name }).new(name: 'Proc resolved')
92
91
  a.save
93
- a.activities.last.nonstandard.must_equal 'Proc resolved'
92
+ assert_equal a.activities.last.nonstandard, 'Proc resolved'
94
93
  end
95
94
  end
96
95
 
@@ -99,43 +98,43 @@ describe PublicActivity::Tracked do
99
98
  a = article.new(name: 'Symbol resolved')
100
99
  a.activity nonstandard: :name
101
100
  a.save
102
- a.activities.last.nonstandard.must_equal 'Symbol resolved'
101
+ assert_equal a.activities.last.nonstandard, 'Symbol resolved'
103
102
  end
104
103
 
105
104
  it 'should resolve procs' do
106
105
  a = article.new(name: 'Proc resolved')
107
- a.activity nonstandard: proc {|_, model| model.name}
106
+ a.activity nonstandard: proc { |_, model| model.name }
108
107
  a.save
109
- a.activities.last.nonstandard.must_equal 'Proc resolved'
108
+ assert_equal a.activities.last.nonstandard, 'Proc resolved'
110
109
  end
111
110
  end
112
111
  end
113
112
 
114
113
  it 'should reset instance options on successful create_activity' do
115
114
  a = article.new
116
- a.activity key: 'test', params: {test: 1}
115
+ a.activity key: 'test', params: { test: 1 }
117
116
  a.save
118
- a.activities.count.must_equal 1
119
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
120
- a.activity_params.must_be_empty
117
+ assert_equal a.activities.count, 1
118
+ assert_raises(PublicActivity::NoKeyProvided) { a.create_activity }
119
+ assert_empty a.activity_params
121
120
  a.activity key: 'asd'
122
121
  a.create_activity
123
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
122
+ assert_raises(PublicActivity::NoKeyProvided) { a.create_activity }
124
123
  end
125
124
 
126
125
  it 'should not accept global key option' do
127
126
  # this example tests the lack of presence of sth that should not be here
128
127
  a = article(key: 'asd').new
129
128
  a.save
130
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
131
- a.activities.count.must_equal 1
129
+ assert_raises(PublicActivity::NoKeyProvided) { a.create_activity }
130
+ assert_equal a.activities.count, 1
132
131
  end
133
132
 
134
133
  it 'should not change global custom fields' do
135
134
  a = article(nonstandard: 'global').new
136
135
  a.activity nonstandard: 'instance'
137
136
  a.save
138
- a.class.activity_custom_fields_global.must_equal nonstandard: 'global'
137
+ assert_equal a.class.activity_custom_fields_global, nonstandard: 'global'
139
138
  end
140
139
 
141
140
  describe 'disabling functionality' do
@@ -143,9 +142,9 @@ describe PublicActivity::Tracked do
143
142
  PublicActivity.enabled = false
144
143
  activity_count_before = PublicActivity::Activity.count
145
144
 
146
- @article = article().new
145
+ @article = article.new
147
146
  @article.save
148
- PublicActivity::Activity.count.must_equal activity_count_before
147
+ assert_equal PublicActivity::Activity.count, activity_count_before
149
148
 
150
149
  PublicActivity.enabled = true
151
150
  end
@@ -157,12 +156,12 @@ describe PublicActivity::Tracked do
157
156
  klass.public_activity_off
158
157
  @article = klass.new
159
158
  @article.save
160
- PublicActivity::Activity.count.must_equal activity_count_before
159
+ assert_equal PublicActivity::Activity.count, activity_count_before
161
160
 
162
161
  klass.public_activity_on
163
162
  @article.name = 'Changed Article'
164
163
  @article.save
165
- PublicActivity::Activity.count.must_be :>, activity_count_before
164
+ assert(PublicActivity::Activity.count > activity_count_before)
166
165
  end
167
166
  end
168
167
 
@@ -171,9 +170,10 @@ describe PublicActivity::Tracked do
171
170
  let(:options) { {} }
172
171
 
173
172
  it 'allows skipping the tracking on CRUD actions' do
174
- case PublicActivity.config.orm
173
+ art =
174
+ case PublicActivity.config.orm
175
175
  when :mongoid
176
- art = Class.new do
176
+ Class.new do
177
177
  include Mongoid::Document
178
178
  include Mongoid::Timestamps
179
179
  include PublicActivity::Model
@@ -182,10 +182,10 @@ describe PublicActivity::Tracked do
182
182
 
183
183
  field :name, type: String
184
184
  field :published, type: Boolean
185
- tracked :skip_defaults => true
185
+ tracked skip_defaults: true
186
186
  end
187
187
  when :mongo_mapper
188
- art = Class.new do
188
+ Class.new do
189
189
  include MongoMapper::Document
190
190
  include PublicActivity::Model
191
191
 
@@ -193,44 +193,57 @@ describe PublicActivity::Tracked do
193
193
 
194
194
  key :name, String
195
195
  key :published, Boolean
196
- tracked :skip_defaults => true
196
+ tracked skip_defaults: true
197
197
 
198
198
  timestamps!
199
199
  end
200
200
  when :active_record
201
- art = article(:skip_defaults => true)
202
- end
201
+ article(skip_defaults: true)
202
+ end
203
203
 
204
- art.must_include PublicActivity::Common
205
- art.wont_include PublicActivity::Creation
206
- art.wont_include PublicActivity::Update
207
- art.wont_include PublicActivity::Destruction
204
+ assert_includes art, PublicActivity::Common
205
+ refute_includes art, PublicActivity::Creation
206
+ refute_includes art, PublicActivity::Update
207
+ refute_includes art, PublicActivity::Destruction
208
208
  end
209
209
 
210
210
  describe 'default options' do
211
211
  subject { article }
212
212
 
213
- specify { subject.must_include PublicActivity::Creation }
214
- specify { subject.must_include PublicActivity::Destruction }
215
- specify { subject.must_include PublicActivity::Update }
213
+ specify { assert_includes subject, PublicActivity::Creation }
214
+ specify { assert_includes subject, PublicActivity::Destruction }
215
+ specify { assert_includes subject, PublicActivity::Update }
216
216
 
217
- specify { subject._create_callbacks.select do |c|
218
- c.kind.eql?(:after) && c.filter == :activity_on_create
219
- end.wont_be_empty }
217
+ specify do
218
+ callbacks = subject._create_callbacks.select do |c|
219
+ c.kind.eql?(:after) && c.filter == :activity_on_create
220
+ end
221
+
222
+ refute_empty callbacks
223
+ end
224
+
225
+ specify do
226
+ callbacks = subject._update_callbacks.select do |c|
227
+ c.kind.eql?(:after) && c.filter == :activity_on_update
228
+ end
229
+
230
+ refute_empty callbacks
231
+ end
220
232
 
221
- specify { subject._update_callbacks.select do |c|
222
- c.kind.eql?(:after) && c.filter == :activity_on_update
223
- end.wont_be_empty }
233
+ specify do
234
+ callbacks = subject._destroy_callbacks.select do |c|
235
+ c.kind.eql?(:before) && c.filter == :activity_on_destroy
236
+ end
224
237
 
225
- specify { subject._destroy_callbacks.select do |c|
226
- c.kind.eql?(:before) && c.filter == :activity_on_destroy
227
- end.wont_be_empty }
238
+ refute_empty callbacks
239
+ end
228
240
  end
229
241
 
230
242
  it 'accepts :except option' do
231
- case PublicActivity.config.orm
243
+ art =
244
+ case PublicActivity.config.orm
232
245
  when :mongoid
233
- art = Class.new do
246
+ Class.new do
234
247
  include Mongoid::Document
235
248
  include Mongoid::Timestamps
236
249
  include PublicActivity::Model
@@ -239,10 +252,10 @@ describe PublicActivity::Tracked do
239
252
 
240
253
  field :name, type: String
241
254
  field :published, type: Boolean
242
- tracked :except => [:create]
255
+ tracked except: [:create]
243
256
  end
244
257
  when :mongo_mapper
245
- art = Class.new do
258
+ Class.new do
246
259
  include MongoMapper::Document
247
260
  include PublicActivity::Model
248
261
 
@@ -250,23 +263,24 @@ describe PublicActivity::Tracked do
250
263
 
251
264
  key :name, String
252
265
  key :published, Boolean
253
- tracked :except => [:create]
266
+ tracked except: [:create]
254
267
 
255
268
  timestamps!
256
269
  end
257
270
  when :active_record
258
- art = article(:except => [:create])
259
- end
271
+ article(except: [:create])
272
+ end
260
273
 
261
- art.wont_include PublicActivity::Creation
262
- art.must_include PublicActivity::Update
263
- art.must_include PublicActivity::Destruction
274
+ refute_includes art, PublicActivity::Creation
275
+ assert_includes art, PublicActivity::Update
276
+ assert_includes art, PublicActivity::Destruction
264
277
  end
265
278
 
266
279
  it 'accepts :only option' do
267
- case PublicActivity.config.orm
280
+ art =
281
+ case PublicActivity.config.orm
268
282
  when :mongoid
269
- art = Class.new do
283
+ Class.new do
270
284
  include Mongoid::Document
271
285
  include Mongoid::Timestamps
272
286
  include PublicActivity::Model
@@ -276,10 +290,10 @@ describe PublicActivity::Tracked do
276
290
  field :name, type: String
277
291
  field :published, type: Boolean
278
292
 
279
- tracked :only => [:create, :update]
293
+ tracked only: %i[create update]
280
294
  end
281
295
  when :mongo_mapper
282
- art = Class.new do
296
+ Class.new do
283
297
  include MongoMapper::Document
284
298
  include PublicActivity::Model
285
299
 
@@ -288,61 +302,65 @@ describe PublicActivity::Tracked do
288
302
  key :name, String
289
303
  key :published, Boolean
290
304
 
291
- tracked :only => [:create, :update]
305
+ tracked only: %i[create update]
292
306
  end
293
307
  when :active_record
294
- art = article({:only => [:create, :update]})
295
- end
308
+ article(only: %I[create update])
309
+ end
296
310
 
297
- art.must_include PublicActivity::Creation
298
- art.wont_include PublicActivity::Destruction
299
- art.must_include PublicActivity::Update
311
+ assert_includes art, PublicActivity::Creation
312
+ refute_includes art, PublicActivity::Destruction
313
+ assert_includes art, PublicActivity::Update
300
314
  end
301
315
 
302
316
  it 'accepts :owner option' do
303
317
  owner = mock('owner')
304
- subject.tracked(:owner => owner)
305
- subject.activity_owner_global.must_equal owner
318
+ subject.tracked(owner: owner)
319
+ assert_equal subject.activity_owner_global, owner
306
320
  end
307
321
 
308
322
  it 'accepts :params option' do
309
- params = {:a => 1}
310
- subject.tracked(:params => params)
311
- subject.activity_params_global.must_equal params
323
+ params = { a: 1 }
324
+ subject.tracked(params: params)
325
+ assert_equal subject.activity_params_global, params
312
326
  end
313
327
 
314
328
  it 'accepts :on option' do
315
- on = {:a => lambda{}, :b => proc {}}
316
- subject.tracked(:on => on)
317
- subject.activity_hooks.must_equal on
329
+ on = { a: -> {}, b: proc {} }
330
+ subject.tracked(on: on)
331
+ assert_equal subject.activity_hooks, on
318
332
  end
319
333
 
320
334
  it 'accepts :on option with string keys' do
321
- on = {'a' => lambda {}}
322
- subject.tracked(:on => on)
323
- subject.activity_hooks.must_equal on.symbolize_keys
335
+ on = { 'a' => -> {} }
336
+ subject.tracked(on: on)
337
+ assert_equal subject.activity_hooks, on.symbolize_keys
324
338
  end
325
339
 
326
340
  it 'accepts :on values that are procs' do
327
- on = {:unpassable => 1, :proper => lambda {}, :proper_proc => proc {}}
328
- subject.tracked(:on => on)
329
- subject.activity_hooks.must_include :proper
330
- subject.activity_hooks.must_include :proper_proc
331
- subject.activity_hooks.wont_include :unpassable
341
+ on = { unpassable: 1, proper: -> {}, proper_proc: proc {} }
342
+ subject.tracked(on: on)
343
+ assert_includes subject.activity_hooks, :proper
344
+ assert_includes subject.activity_hooks, :proper_proc
345
+ refute_includes subject.activity_hooks, :unpassable
332
346
  end
333
347
 
334
348
  describe 'global options' do
335
- subject { article(recipient: :test, owner: :test2, params: {a: 'b'}) }
349
+ subject { article(recipient: :test, owner: :test2, params: { a: 'b' }) }
336
350
 
337
- specify { subject.activity_recipient_global.must_equal :test }
338
- specify { subject.activity_owner_global.must_equal :test2 }
339
- specify { subject.activity_params_global.must_equal(a: 'b') }
351
+ specify { assert_equal subject.activity_recipient_global, :test }
352
+ specify { assert_equal subject.activity_owner_global, :test2 }
353
+ specify { assert_equal subject.activity_params_global, a: 'b' }
340
354
  end
341
355
  end
342
356
 
343
357
  describe 'activity hooks' do
344
- subject { s = article; s.activity_hooks = {:test => hook}; s }
345
- let(:hook) { lambda {} }
358
+ subject do
359
+ s = article
360
+ s.activity_hooks = { test: hook }
361
+ s
362
+ end
363
+ let(:hook) { -> {} }
346
364
 
347
365
  it 'retrieves hooks' do
348
366
  assert_same hook, subject.get_hook(:test)
@@ -353,33 +371,37 @@ describe PublicActivity::Tracked do
353
371
  end
354
372
 
355
373
  it 'returns nil when no matching hook is present' do
356
- nil.must_be_same_as subject.get_hook(:nonexistent)
374
+ assert_same nil, subject.get_hook(:nonexistent)
357
375
  end
358
376
 
359
377
  it 'allows hooks to decide if activity should be created' do
360
378
  subject.tracked
361
- @article = subject.new(:name => 'Some Name')
379
+ @article = subject.new(name: 'Some Name')
362
380
  PublicActivity.set_controller(mock('controller'))
363
381
  pf = proc { |model, controller|
364
- controller.must_be_same_as PublicActivity.get_controller
365
- model.name.must_equal 'Some Name'
382
+ assert_same controller, PublicActivity.get_controller
383
+ assert_equal model.name, 'Some Name'
366
384
  false
367
385
  }
368
386
  pt = proc { |model, controller|
369
- controller.must_be_same_as PublicActivity.get_controller
370
- model.name.must_equal 'Other Name'
387
+ assert_same controller, PublicActivity.get_controller
388
+ assert_equal model.name, 'Other Name'
371
389
  true # this will save the activity with *.update key
372
390
  }
373
- @article.class.activity_hooks = {:create => pf, :update => pt, :destroy => pt}
391
+ @article.class.activity_hooks = { create: pf, update: pt, destroy: pt }
374
392
 
375
- @article.activities.to_a.must_be_empty
393
+ assert_empty @article.activities.to_a
376
394
  @article.save # create
377
395
  @article.name = 'Other Name'
378
396
  @article.save # update
379
397
  @article.destroy # destroy
380
398
 
381
- @article.activities.count.must_equal 2
382
- @article.activities.first.key.must_equal 'article.update'
399
+ assert_equal @article.activities.count, 2
400
+ assert_equal @article.activities.first.key, 'article.update'
383
401
  end
384
402
  end
403
+
404
+ def teardown
405
+ PublicActivity.set_controller(nil)
406
+ end
385
407
  end
@@ -24,14 +24,14 @@ describe 'ViewHelpers Rendering' do
24
24
  @view_flow.expects(:set).twice.with('name', ActiveSupport::SafeBuffer.new)
25
25
 
26
26
  single_content_for('name', 'content')
27
- @name.must_equal 'name'
28
- @content.must_equal 'content'
27
+ assert_equal @name, 'name'
28
+ assert_equal @content, 'content'
29
29
  single_content_for('name', 'content2')
30
- @name.must_equal 'name'
31
- @content.must_equal 'content2'
30
+ assert_equal @name, 'name'
31
+ assert_equal @content, 'content2'
32
32
  end
33
33
 
34
- def content_for(name, content, &block)
34
+ def content_for(name, content)
35
35
  @name = name
36
36
  @content = content
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotrek Okoński
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-08 00:00:00.000000000 Z
12
+ date: 2022-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -247,7 +247,6 @@ files:
247
247
  - test/migrations/002_create_articles.rb
248
248
  - test/migrations/003_create_users.rb
249
249
  - test/migrations/004_add_nonstandard_to_activities.rb
250
- - test/migrations_base.rb
251
250
  - test/mongo_mapper.yml
252
251
  - test/mongoid.yml
253
252
  - test/test_activist.rb
@@ -291,7 +290,6 @@ test_files:
291
290
  - test/migrations/002_create_articles.rb
292
291
  - test/migrations/003_create_users.rb
293
292
  - test/migrations/004_add_nonstandard_to_activities.rb
294
- - test/migrations_base.rb
295
293
  - test/mongo_mapper.yml
296
294
  - test/mongoid.yml
297
295
  - test/test_activist.rb
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- MigrationsBase = if ActiveRecord.version.release() < Gem::Version.new('5.1.0')
4
- ActiveRecord::Migration
5
- else
6
- ActiveRecord::Migration[5.1]
7
- end