public_activity 1.6.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +26 -28
  4. data/Rakefile +6 -5
  5. data/lib/generators/public_activity/migration/migration_generator.rb +3 -1
  6. data/lib/generators/public_activity/migration/templates/migration.rb +12 -10
  7. data/lib/generators/public_activity/migration_upgrade/migration_upgrade_generator.rb +4 -1
  8. data/lib/generators/public_activity/migration_upgrade/templates/upgrade.rb +4 -2
  9. data/lib/generators/public_activity.rb +2 -0
  10. data/lib/public_activity/actions/creation.rb +3 -1
  11. data/lib/public_activity/actions/destruction.rb +2 -0
  12. data/lib/public_activity/actions/update.rb +2 -0
  13. data/lib/public_activity/activity.rb +3 -1
  14. data/lib/public_activity/common.rb +16 -0
  15. data/lib/public_activity/config.rb +2 -0
  16. data/lib/public_activity/models/activist.rb +3 -1
  17. data/lib/public_activity/models/activity.rb +3 -1
  18. data/lib/public_activity/models/adapter.rb +3 -1
  19. data/lib/public_activity/models/trackable.rb +3 -1
  20. data/lib/public_activity/orm/active_record/activist.rb +2 -0
  21. data/lib/public_activity/orm/active_record/activity.rb +29 -11
  22. data/lib/public_activity/orm/active_record/adapter.rb +7 -0
  23. data/lib/public_activity/orm/active_record/trackable.rb +2 -0
  24. data/lib/public_activity/orm/active_record.rb +3 -1
  25. data/lib/public_activity/orm/mongo_mapper/activist.rb +2 -0
  26. data/lib/public_activity/orm/mongo_mapper/activity.rb +2 -0
  27. data/lib/public_activity/orm/mongo_mapper/adapter.rb +7 -0
  28. data/lib/public_activity/orm/mongo_mapper/trackable.rb +2 -0
  29. data/lib/public_activity/orm/mongo_mapper.rb +3 -1
  30. data/lib/public_activity/orm/mongoid/activist.rb +2 -0
  31. data/lib/public_activity/orm/mongoid/activity.rb +2 -0
  32. data/lib/public_activity/orm/mongoid/adapter.rb +7 -0
  33. data/lib/public_activity/orm/mongoid/trackable.rb +2 -0
  34. data/lib/public_activity/orm/mongoid.rb +3 -1
  35. data/lib/public_activity/renderable.rb +5 -2
  36. data/lib/public_activity/roles/deactivatable.rb +2 -0
  37. data/lib/public_activity/roles/tracked.rb +2 -0
  38. data/lib/public_activity/testing.rb +2 -0
  39. data/lib/public_activity/utility/store_controller.rb +2 -0
  40. data/lib/public_activity/utility/view_helpers.rb +2 -0
  41. data/lib/public_activity/version.rb +3 -1
  42. data/lib/public_activity.rb +2 -0
  43. data/test/migrations/001_create_activities.rb +1 -1
  44. data/test/migrations/002_create_articles.rb +2 -3
  45. data/test/migrations/003_create_users.rb +2 -2
  46. data/test/migrations/004_add_nonstandard_to_activities.rb +2 -2
  47. data/test/test_activist.rb +39 -36
  48. data/test/test_activity.rb +39 -38
  49. data/test/test_common.rb +66 -48
  50. data/test/test_controller_integration.rb +19 -11
  51. data/test/test_generators.rb +7 -17
  52. data/test/test_helper.rb +20 -24
  53. data/test/test_testing.rb +13 -10
  54. data/test/test_tracking.rb +171 -147
  55. data/test/test_view_helpers.rb +8 -6
  56. metadata +49 -40
  57. data/lib/generators/public_activity/activity/activity_generator.rb +0 -17
  58. data/lib/generators/public_activity/activity/templates/activity.rb +0 -3
  59. data/test/migrations_base.rb +0 -5
data/test/test_helper.rb CHANGED
@@ -1,14 +1,16 @@
1
- require "rubygems"
2
- require "bundler"
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
3
5
  Bundler.setup(:default, :test)
4
6
 
5
7
  if ENV['COV']
6
8
  require 'simplecov'
7
9
  SimpleCov.start do
8
- add_filter "/test/"
10
+ add_filter '/test/'
9
11
  end
10
12
  end
11
- $:.unshift File.expand_path('../../lib/', __FILE__)
13
+ $:.unshift File.expand_path('../lib', __dir__)
12
14
  require 'active_support/testing/setup_and_teardown'
13
15
  require 'public_activity'
14
16
  require 'public_activity/testing'
@@ -24,46 +26,40 @@ when :active_record
24
26
  require 'active_record/connection_adapters/sqlite3_adapter'
25
27
  require 'stringio' # silence the output
26
28
  $stdout = StringIO.new # from migrator
27
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
29
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
28
30
 
29
- migrations_path = File.expand_path('../migrations', __FILE__)
31
+ migrations_path = File.expand_path('migrations', __dir__)
32
+ active_record_version = ActiveRecord.version.release
30
33
 
31
- if ActiveRecord.version.release() < Gem::Version.new('5.2.0')
32
- ActiveRecord::Migrator.migrate(migrations_path)
33
- else
34
+ if active_record_version >= Gem::Version.new('6.0.0')
35
+ schema_path = File.expand_path('../tmp/schema.rb', File.dirname(__FILE__))
36
+ ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
37
+ elsif active_record_version >= Gem::Version.new('5.2.0')
34
38
  ActiveRecord::MigrationContext.new(migrations_path).migrate
39
+ else # active_record_version < Gem::Version.new('5.2.0')
40
+ ActiveRecord::Migrator.migrate(migrations_path)
35
41
  end
36
42
 
37
43
  $stdout = STDOUT
38
44
 
39
45
  def article(options = {})
40
- klass = Class.new(ActiveRecord::Base) do
46
+ Class.new(ActiveRecord::Base) do
41
47
  self.table_name = 'articles'
42
48
  include PublicActivity::Model
43
49
  tracked options
44
50
  belongs_to :user
45
51
 
46
52
  def self.name
47
- "Article"
48
- end
49
-
50
- if ::ActiveRecord::VERSION::MAJOR < 4
51
- attr_accessible :name, :published, :user
53
+ 'Article'
52
54
  end
53
55
  end
54
- klass
55
56
  end
56
- class User < ActiveRecord::Base; end
57
57
 
58
- if ::ActiveRecord::VERSION::MAJOR < 4
59
- PublicActivity::Activity.class_eval do
60
- attr_accessible :nonstandard
61
- end
62
- end
58
+ class User < ActiveRecord::Base; end
63
59
  when :mongoid
64
60
  require 'mongoid'
65
61
 
66
- Mongoid.load!(File.expand_path("test/mongoid.yml"), :test)
62
+ Mongoid.load!(File.expand_path('test/mongoid.yml'), :test)
67
63
 
68
64
  class User
69
65
  include Mongoid::Document
@@ -100,7 +96,7 @@ when :mongoid
100
96
  when :mongo_mapper
101
97
  require 'mongo_mapper'
102
98
 
103
- config = YAML.load(File.read("test/mongo_mapper.yml"))
99
+ config = YAML.load(File.read('test/mongo_mapper.yml'))
104
100
  MongoMapper.setup(config, :test)
105
101
 
106
102
  class User
data/test/test_testing.rb CHANGED
@@ -1,34 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
- describe PublicActivity do
3
4
 
4
- describe "self.with_tracking" do
5
+ describe PublicActivity do
6
+ describe 'self.with_tracking' do
5
7
  after do
6
8
  PublicActivity.enabled = true
7
9
  end
8
-
9
- it "enables tracking inside the block" do
10
+
11
+ it 'enables tracking inside the block' do
10
12
  PublicActivity.enabled = false
11
13
 
12
14
  PublicActivity.with_tracking do
13
- PublicActivity.enabled?.must_equal true
15
+ assert PublicActivity.enabled?
14
16
  end
15
17
  end
16
18
 
17
- it "restores previous `enabled` state" do
19
+ it 'restores previous `enabled` state' do
18
20
  PublicActivity.enabled = false
19
21
  PublicActivity.with_tracking do
20
22
  # something
21
23
  end
22
- PublicActivity.enabled?.must_equal false
24
+
25
+ assert_equal PublicActivity.enabled?, false
23
26
  end
24
27
  end
25
28
 
26
- describe "self.without_tracking" do
27
- it "disables tracking inside the block" do
29
+ describe 'self.without_tracking' do
30
+ it 'disables tracking inside the block' do
28
31
  PublicActivity.enabled = true
29
32
 
30
33
  PublicActivity.without_tracking do
31
- PublicActivity.enabled?.must_equal false
34
+ assert_equal PublicActivity.enabled?, false
32
35
  end
33
36
  end
34
37
  end
@@ -1,79 +1,80 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe PublicActivity::Tracked do
4
6
  describe 'defining instance options' do
5
7
  subject { article.new }
6
8
  let :options do
7
- { :key => 'key',
8
- :params => {:a => 1},
9
- :owner => User.create,
10
- :recipient => User.create }
9
+ {
10
+ key: 'key',
11
+ params: { a: 1 },
12
+ owner: User.create,
13
+ recipient: User.create
14
+ }
11
15
  end
12
16
  before(:each) { subject.activity(options) }
13
- let(:activity){ subject.save; subject.activities.last }
17
+ let(:activity) { subject.save; subject.activities.last }
14
18
 
15
- specify { subject.activity_key.must_be_same_as options[:key] }
16
- specify { activity.key.must_equal options[:key] }
19
+ specify { assert_same subject.activity_key, options[:key] }
20
+ specify { assert_equal activity.key, options[:key] }
17
21
 
18
- specify { subject.activity_owner.must_be_same_as options[:owner] }
19
- specify { activity.owner.must_equal options[:owner] }
22
+ specify { assert_same subject.activity_owner, options[:owner] }
23
+ specify { assert_equal activity.owner, options[:owner] }
20
24
 
21
- specify { subject.activity_params.must_be_same_as options[:params] }
22
- specify { activity.parameters.must_equal options[:params] }
25
+ specify { assert_same subject.activity_params, options[:params] }
26
+ specify { assert_equal activity.parameters, options[:params] }
23
27
 
24
- specify { subject.activity_recipient.must_be_same_as options[:recipient] }
25
- specify { activity.recipient.must_equal options[:recipient] }
28
+ specify { assert_same subject.activity_recipient, options[:recipient] }
29
+ specify { assert_equal activity.recipient, options[:recipient] }
26
30
  end
27
31
 
28
32
  it 'can be tracked and be an activist at the same time' do
29
33
  case PublicActivity.config.orm
30
- when :mongoid
31
- class ActivistAndTrackedArticle
32
- include Mongoid::Document
33
- include Mongoid::Timestamps
34
- include PublicActivity::Model
35
-
36
- if ::Mongoid::VERSION.split('.')[0].to_i >= 7
37
- belongs_to :user, optional: true
38
- else
39
- belongs_to :user
40
- end
41
-
42
- field :name, type: String
43
- field :published, type: Boolean
44
- tracked
45
- activist
46
- end
47
- when :mongo_mapper
48
- class ActivistAndTrackedArticle
49
- include MongoMapper::Document
50
- include PublicActivity::Model
51
-
52
- belongs_to :user
53
-
54
- key :name, String
55
- key :published, Boolean
56
- tracked
57
- activist
58
- timestamps!
59
- end
60
- when :active_record
61
- class ActivistAndTrackedArticle < ActiveRecord::Base
62
- self.table_name = 'articles'
63
- include PublicActivity::Model
64
- tracked
65
- activist
66
-
67
- if ::ActiveRecord::VERSION::MAJOR < 4
68
- attr_accessible :name, :published, :user
69
- 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
70
43
  belongs_to :user
71
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
72
73
  end
73
74
 
74
75
  art = ActivistAndTrackedArticle.new
75
76
  art.save
76
- art.activities.last.trackable_id.must_equal art.id
77
+ assert_equal art.activities.last.trackable_id, art.id
77
78
  assert_nil art.activities.last.owner_id
78
79
  end
79
80
 
@@ -82,13 +83,13 @@ describe PublicActivity::Tracked do
82
83
  it 'should resolve symbols' do
83
84
  a = article(nonstandard: :name).new(name: 'Symbol resolved')
84
85
  a.save
85
- a.activities.last.nonstandard.must_equal 'Symbol resolved'
86
+ assert_equal a.activities.last.nonstandard, 'Symbol resolved'
86
87
  end
87
88
 
88
89
  it 'should resolve procs' do
89
- a = article(nonstandard: proc {|_, model| model.name}).new(name: 'Proc resolved')
90
+ a = article(nonstandard: proc { |_, model| model.name }).new(name: 'Proc resolved')
90
91
  a.save
91
- a.activities.last.nonstandard.must_equal 'Proc resolved'
92
+ assert_equal a.activities.last.nonstandard, 'Proc resolved'
92
93
  end
93
94
  end
94
95
 
@@ -97,43 +98,43 @@ describe PublicActivity::Tracked do
97
98
  a = article.new(name: 'Symbol resolved')
98
99
  a.activity nonstandard: :name
99
100
  a.save
100
- a.activities.last.nonstandard.must_equal 'Symbol resolved'
101
+ assert_equal a.activities.last.nonstandard, 'Symbol resolved'
101
102
  end
102
103
 
103
104
  it 'should resolve procs' do
104
105
  a = article.new(name: 'Proc resolved')
105
- a.activity nonstandard: proc {|_, model| model.name}
106
+ a.activity nonstandard: proc { |_, model| model.name }
106
107
  a.save
107
- a.activities.last.nonstandard.must_equal 'Proc resolved'
108
+ assert_equal a.activities.last.nonstandard, 'Proc resolved'
108
109
  end
109
110
  end
110
111
  end
111
112
 
112
113
  it 'should reset instance options on successful create_activity' do
113
114
  a = article.new
114
- a.activity key: 'test', params: {test: 1}
115
+ a.activity key: 'test', params: { test: 1 }
115
116
  a.save
116
- a.activities.count.must_equal 1
117
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
118
- 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
119
120
  a.activity key: 'asd'
120
121
  a.create_activity
121
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
122
+ assert_raises(PublicActivity::NoKeyProvided) { a.create_activity }
122
123
  end
123
124
 
124
125
  it 'should not accept global key option' do
125
126
  # this example tests the lack of presence of sth that should not be here
126
127
  a = article(key: 'asd').new
127
128
  a.save
128
- ->{a.create_activity}.must_raise PublicActivity::NoKeyProvided
129
- a.activities.count.must_equal 1
129
+ assert_raises(PublicActivity::NoKeyProvided) { a.create_activity }
130
+ assert_equal a.activities.count, 1
130
131
  end
131
132
 
132
133
  it 'should not change global custom fields' do
133
134
  a = article(nonstandard: 'global').new
134
135
  a.activity nonstandard: 'instance'
135
136
  a.save
136
- a.class.activity_custom_fields_global.must_equal nonstandard: 'global'
137
+ assert_equal a.class.activity_custom_fields_global, nonstandard: 'global'
137
138
  end
138
139
 
139
140
  describe 'disabling functionality' do
@@ -141,9 +142,9 @@ describe PublicActivity::Tracked do
141
142
  PublicActivity.enabled = false
142
143
  activity_count_before = PublicActivity::Activity.count
143
144
 
144
- @article = article().new
145
+ @article = article.new
145
146
  @article.save
146
- PublicActivity::Activity.count.must_equal activity_count_before
147
+ assert_equal PublicActivity::Activity.count, activity_count_before
147
148
 
148
149
  PublicActivity.enabled = true
149
150
  end
@@ -155,12 +156,12 @@ describe PublicActivity::Tracked do
155
156
  klass.public_activity_off
156
157
  @article = klass.new
157
158
  @article.save
158
- PublicActivity::Activity.count.must_equal activity_count_before
159
+ assert_equal PublicActivity::Activity.count, activity_count_before
159
160
 
160
161
  klass.public_activity_on
161
162
  @article.name = 'Changed Article'
162
163
  @article.save
163
- PublicActivity::Activity.count.must_be :>, activity_count_before
164
+ assert(PublicActivity::Activity.count > activity_count_before)
164
165
  end
165
166
  end
166
167
 
@@ -169,9 +170,10 @@ describe PublicActivity::Tracked do
169
170
  let(:options) { {} }
170
171
 
171
172
  it 'allows skipping the tracking on CRUD actions' do
172
- case PublicActivity.config.orm
173
+ art =
174
+ case PublicActivity.config.orm
173
175
  when :mongoid
174
- art = Class.new do
176
+ Class.new do
175
177
  include Mongoid::Document
176
178
  include Mongoid::Timestamps
177
179
  include PublicActivity::Model
@@ -180,10 +182,10 @@ describe PublicActivity::Tracked do
180
182
 
181
183
  field :name, type: String
182
184
  field :published, type: Boolean
183
- tracked :skip_defaults => true
185
+ tracked skip_defaults: true
184
186
  end
185
187
  when :mongo_mapper
186
- art = Class.new do
188
+ Class.new do
187
189
  include MongoMapper::Document
188
190
  include PublicActivity::Model
189
191
 
@@ -191,44 +193,57 @@ describe PublicActivity::Tracked do
191
193
 
192
194
  key :name, String
193
195
  key :published, Boolean
194
- tracked :skip_defaults => true
196
+ tracked skip_defaults: true
195
197
 
196
198
  timestamps!
197
199
  end
198
200
  when :active_record
199
- art = article(:skip_defaults => true)
200
- end
201
+ article(skip_defaults: true)
202
+ end
201
203
 
202
- art.must_include PublicActivity::Common
203
- art.wont_include PublicActivity::Creation
204
- art.wont_include PublicActivity::Update
205
- 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
206
208
  end
207
209
 
208
210
  describe 'default options' do
209
211
  subject { article }
210
212
 
211
- specify { subject.must_include PublicActivity::Creation }
212
- specify { subject.must_include PublicActivity::Destruction }
213
- 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 }
214
216
 
215
- specify { subject._create_callbacks.select do |c|
216
- c.kind.eql?(:after) && c.filter == :activity_on_create
217
- 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
218
232
 
219
- specify { subject._update_callbacks.select do |c|
220
- c.kind.eql?(:after) && c.filter == :activity_on_update
221
- 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
222
237
 
223
- specify { subject._destroy_callbacks.select do |c|
224
- c.kind.eql?(:before) && c.filter == :activity_on_destroy
225
- end.wont_be_empty }
238
+ refute_empty callbacks
239
+ end
226
240
  end
227
241
 
228
242
  it 'accepts :except option' do
229
- case PublicActivity.config.orm
243
+ art =
244
+ case PublicActivity.config.orm
230
245
  when :mongoid
231
- art = Class.new do
246
+ Class.new do
232
247
  include Mongoid::Document
233
248
  include Mongoid::Timestamps
234
249
  include PublicActivity::Model
@@ -237,10 +252,10 @@ describe PublicActivity::Tracked do
237
252
 
238
253
  field :name, type: String
239
254
  field :published, type: Boolean
240
- tracked :except => [:create]
255
+ tracked except: [:create]
241
256
  end
242
257
  when :mongo_mapper
243
- art = Class.new do
258
+ Class.new do
244
259
  include MongoMapper::Document
245
260
  include PublicActivity::Model
246
261
 
@@ -248,23 +263,24 @@ describe PublicActivity::Tracked do
248
263
 
249
264
  key :name, String
250
265
  key :published, Boolean
251
- tracked :except => [:create]
266
+ tracked except: [:create]
252
267
 
253
268
  timestamps!
254
269
  end
255
270
  when :active_record
256
- art = article(:except => [:create])
257
- end
271
+ article(except: [:create])
272
+ end
258
273
 
259
- art.wont_include PublicActivity::Creation
260
- art.must_include PublicActivity::Update
261
- art.must_include PublicActivity::Destruction
274
+ refute_includes art, PublicActivity::Creation
275
+ assert_includes art, PublicActivity::Update
276
+ assert_includes art, PublicActivity::Destruction
262
277
  end
263
278
 
264
279
  it 'accepts :only option' do
265
- case PublicActivity.config.orm
280
+ art =
281
+ case PublicActivity.config.orm
266
282
  when :mongoid
267
- art = Class.new do
283
+ Class.new do
268
284
  include Mongoid::Document
269
285
  include Mongoid::Timestamps
270
286
  include PublicActivity::Model
@@ -274,10 +290,10 @@ describe PublicActivity::Tracked do
274
290
  field :name, type: String
275
291
  field :published, type: Boolean
276
292
 
277
- tracked :only => [:create, :update]
293
+ tracked only: %i[create update]
278
294
  end
279
295
  when :mongo_mapper
280
- art = Class.new do
296
+ Class.new do
281
297
  include MongoMapper::Document
282
298
  include PublicActivity::Model
283
299
 
@@ -286,61 +302,65 @@ describe PublicActivity::Tracked do
286
302
  key :name, String
287
303
  key :published, Boolean
288
304
 
289
- tracked :only => [:create, :update]
305
+ tracked only: %i[create update]
290
306
  end
291
307
  when :active_record
292
- art = article({:only => [:create, :update]})
293
- end
308
+ article(only: %I[create update])
309
+ end
294
310
 
295
- art.must_include PublicActivity::Creation
296
- art.wont_include PublicActivity::Destruction
297
- art.must_include PublicActivity::Update
311
+ assert_includes art, PublicActivity::Creation
312
+ refute_includes art, PublicActivity::Destruction
313
+ assert_includes art, PublicActivity::Update
298
314
  end
299
315
 
300
316
  it 'accepts :owner option' do
301
317
  owner = mock('owner')
302
- subject.tracked(:owner => owner)
303
- subject.activity_owner_global.must_equal owner
318
+ subject.tracked(owner: owner)
319
+ assert_equal subject.activity_owner_global, owner
304
320
  end
305
321
 
306
322
  it 'accepts :params option' do
307
- params = {:a => 1}
308
- subject.tracked(:params => params)
309
- subject.activity_params_global.must_equal params
323
+ params = { a: 1 }
324
+ subject.tracked(params: params)
325
+ assert_equal subject.activity_params_global, params
310
326
  end
311
327
 
312
328
  it 'accepts :on option' do
313
- on = {:a => lambda{}, :b => proc {}}
314
- subject.tracked(:on => on)
315
- subject.activity_hooks.must_equal on
329
+ on = { a: -> {}, b: proc {} }
330
+ subject.tracked(on: on)
331
+ assert_equal subject.activity_hooks, on
316
332
  end
317
333
 
318
334
  it 'accepts :on option with string keys' do
319
- on = {'a' => lambda {}}
320
- subject.tracked(:on => on)
321
- 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
322
338
  end
323
339
 
324
340
  it 'accepts :on values that are procs' do
325
- on = {:unpassable => 1, :proper => lambda {}, :proper_proc => proc {}}
326
- subject.tracked(:on => on)
327
- subject.activity_hooks.must_include :proper
328
- subject.activity_hooks.must_include :proper_proc
329
- 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
330
346
  end
331
347
 
332
348
  describe 'global options' do
333
- subject { article(recipient: :test, owner: :test2, params: {a: 'b'}) }
349
+ subject { article(recipient: :test, owner: :test2, params: { a: 'b' }) }
334
350
 
335
- specify { subject.activity_recipient_global.must_equal :test }
336
- specify { subject.activity_owner_global.must_equal :test2 }
337
- 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' }
338
354
  end
339
355
  end
340
356
 
341
357
  describe 'activity hooks' do
342
- subject { s = article; s.activity_hooks = {:test => hook}; s }
343
- let(:hook) { lambda {} }
358
+ subject do
359
+ s = article
360
+ s.activity_hooks = { test: hook }
361
+ s
362
+ end
363
+ let(:hook) { -> {} }
344
364
 
345
365
  it 'retrieves hooks' do
346
366
  assert_same hook, subject.get_hook(:test)
@@ -351,33 +371,37 @@ describe PublicActivity::Tracked do
351
371
  end
352
372
 
353
373
  it 'returns nil when no matching hook is present' do
354
- nil.must_be_same_as subject.get_hook(:nonexistent)
374
+ assert_same nil, subject.get_hook(:nonexistent)
355
375
  end
356
376
 
357
377
  it 'allows hooks to decide if activity should be created' do
358
378
  subject.tracked
359
- @article = subject.new(:name => 'Some Name')
379
+ @article = subject.new(name: 'Some Name')
360
380
  PublicActivity.set_controller(mock('controller'))
361
381
  pf = proc { |model, controller|
362
- controller.must_be_same_as PublicActivity.get_controller
363
- model.name.must_equal 'Some Name'
382
+ assert_same controller, PublicActivity.get_controller
383
+ assert_equal model.name, 'Some Name'
364
384
  false
365
385
  }
366
386
  pt = proc { |model, controller|
367
- controller.must_be_same_as PublicActivity.get_controller
368
- model.name.must_equal 'Other Name'
387
+ assert_same controller, PublicActivity.get_controller
388
+ assert_equal model.name, 'Other Name'
369
389
  true # this will save the activity with *.update key
370
390
  }
371
- @article.class.activity_hooks = {:create => pf, :update => pt, :destroy => pt}
391
+ @article.class.activity_hooks = { create: pf, update: pt, destroy: pt }
372
392
 
373
- @article.activities.to_a.must_be_empty
393
+ assert_empty @article.activities.to_a
374
394
  @article.save # create
375
395
  @article.name = 'Other Name'
376
396
  @article.save # update
377
397
  @article.destroy # destroy
378
398
 
379
- @article.activities.count.must_equal 2
380
- @article.activities.first.key.must_equal 'article.update'
399
+ assert_equal @article.activities.count, 2
400
+ assert_equal @article.activities.first.key, 'article.update'
381
401
  end
382
402
  end
403
+
404
+ def teardown
405
+ PublicActivity.set_controller(nil)
406
+ end
383
407
  end