velocity_audited 5.1.4 → 6.0.3

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.
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  SingleCov.covered! uncovered: 1 # Rails version check
4
4
 
5
- class CustomAudit < Audited::Audit
5
+ class CustomAudit < VelocityAudited::Audit
6
6
  def custom_method
7
7
  "I'm custom!"
8
8
  end
@@ -23,21 +23,21 @@ class Models::ActiveRecord::CustomUserSubclass < Models::ActiveRecord::CustomUse
23
23
  audited
24
24
  end
25
25
 
26
- describe Audited::Audit do
26
+ describe VelocityAudited::Audit do
27
27
  let(:user) { Models::ActiveRecord::User.new name: "Testing" }
28
28
 
29
29
  describe "audit class" do
30
30
  around(:example) do |example|
31
- original_audit_class = Audited.audit_class
31
+ original_audit_class = VelocityAudited.audit_class
32
32
 
33
33
  example.run
34
34
 
35
- Audited.config { |config| config.audit_class = original_audit_class }
35
+ VelocityAudited.config { |config| config.audit_class = original_audit_class }
36
36
  end
37
37
 
38
38
  context "when a custom audit class is configured" do
39
39
  it "should be used in place of #{described_class}" do
40
- Audited.config { |config| config.audit_class = CustomAudit }
40
+ VelocityAudited.config { |config| config.audit_class = CustomAudit }
41
41
  TempModel1.audited
42
42
 
43
43
  record = TempModel1.create
@@ -55,14 +55,14 @@ describe Audited::Audit do
55
55
  record = TempModel2.create
56
56
 
57
57
  audit = record.audits.first
58
- expect(audit).to be_a Audited::Audit
58
+ expect(audit).to be_a VelocityAudited::Audit
59
59
  expect(audit.respond_to?(:custom_method)).to be false
60
60
  end
61
61
  end
62
62
  end
63
63
 
64
64
  describe "#audited_changes" do
65
- let(:audit) { Audited.audit_class.new }
65
+ let(:audit) { VelocityAudited.audit_class.new }
66
66
 
67
67
  it "can unserialize yaml from text columns" do
68
68
  audit.audited_changes = {foo: "bar"}
@@ -70,7 +70,7 @@ describe Audited::Audit do
70
70
  end
71
71
 
72
72
  it "does not unserialize from binary columns" do
73
- allow(Audited::YAMLIfTextColumnType).to receive(:text_column?).and_return(false)
73
+ allow(VelocityAudited::YAMLIfTextColumnType).to receive(:text_column?).and_return(false)
74
74
  audit.audited_changes = {foo: "bar"}
75
75
  expect(audit.audited_changes).to eq "{:foo=>\"bar\"}"
76
76
  end
@@ -180,14 +180,14 @@ describe Audited::Audit do
180
180
  describe ".collection_cache_key" do
181
181
  if ActiveRecord::VERSION::MAJOR >= 5
182
182
  it "uses created at" do
183
- Audited::Audit.delete_all
183
+ VelocityAudited::Audit.delete_all
184
184
  audit = Models::ActiveRecord::User.create(name: "John").audits.last
185
185
  audit.update_columns(created_at: Time.zone.parse("2018-01-01"))
186
- expect(Audited::Audit.collection_cache_key).to match(/-20180101\d+$/)
186
+ expect(VelocityAudited::Audit.collection_cache_key).to match(/-20180101\d+$/)
187
187
  end
188
188
  else
189
189
  it "is not defined" do
190
- expect { Audited::Audit.collection_cache_key }.to raise_error(NoMethodError)
190
+ expect { VelocityAudited::Audit.collection_cache_key }.to raise_error(NoMethodError)
191
191
  end
192
192
  end
193
193
  end
@@ -195,12 +195,12 @@ describe Audited::Audit do
195
195
  describe ".assign_revision_attributes" do
196
196
  it "dups when frozen" do
197
197
  user.freeze
198
- assigned = Audited::Audit.assign_revision_attributes(user, name: "Bar")
198
+ assigned = VelocityAudited::Audit.assign_revision_attributes(user, name: "Bar")
199
199
  expect(assigned.name).to eq "Bar"
200
200
  end
201
201
 
202
202
  it "ignores unassignable attributes" do
203
- assigned = Audited::Audit.assign_revision_attributes(user, oops: "Bar")
203
+ assigned = VelocityAudited::Audit.assign_revision_attributes(user, oops: "Bar")
204
204
  expect(assigned.name).to eq "Testing"
205
205
  end
206
206
  end
@@ -212,7 +212,7 @@ describe Audited::Audit do
212
212
  expect(user.audits.reload.first.version).to eq(1)
213
213
  expect(user.audits.reload.last.version).to eq(2)
214
214
  user.destroy
215
- expect(Audited::Audit.where(auditable_type: "Models::ActiveRecord::User", auditable_id: user.id).last.version).to eq(3)
215
+ expect(VelocityAudited::Audit.where(auditable_type: "Models::ActiveRecord::User", auditable_id: user.id).last.version).to eq(3)
216
216
  end
217
217
 
218
218
  it "should set the request uuid on create" do
@@ -222,58 +222,58 @@ describe Audited::Audit do
222
222
 
223
223
  describe "reconstruct_attributes" do
224
224
  it "should work with the old way of storing just the new value" do
225
- audits = Audited::Audit.reconstruct_attributes([Audited::Audit.new(audited_changes: {"attribute" => "value"})])
225
+ audits = VelocityAudited::Audit.reconstruct_attributes([VelocityAudited::Audit.new(audited_changes: { "attribute" => "value"})])
226
226
  expect(audits["attribute"]).to eq("value")
227
227
  end
228
228
  end
229
229
 
230
230
  describe "audited_classes" do
231
231
  it "should include audited classes" do
232
- expect(Audited::Audit.audited_classes).to include(Models::ActiveRecord::User)
232
+ expect(VelocityAudited::Audit.audited_classes).to include(Models::ActiveRecord::User)
233
233
  end
234
234
 
235
235
  it "should include subclasses" do
236
- expect(Audited::Audit.audited_classes).to include(Models::ActiveRecord::CustomUserSubclass)
236
+ expect(VelocityAudited::Audit.audited_classes).to include(Models::ActiveRecord::CustomUserSubclass)
237
237
  end
238
238
  end
239
239
 
240
240
  describe "new_attributes" do
241
241
  it "should return the audited_changes without modification for create" do
242
- new_attributes = Audited::Audit.new(audited_changes: {int: 1, array: [1]}, action: :create).new_attributes
242
+ new_attributes = VelocityAudited::Audit.new(audited_changes: { int: 1, array: [1]}, action: :create).new_attributes
243
243
  expect(new_attributes).to eq({"int" => 1, "array" => [1]})
244
244
  end
245
245
 
246
246
  it "should return a hash that contains the after values of each attribute" do
247
- new_attributes = Audited::Audit.new(audited_changes: {a: [1, 2], b: [3, 4]}, action: :update).new_attributes
247
+ new_attributes = VelocityAudited::Audit.new(audited_changes: { a: [1, 2], b: [3, 4]}, action: :update).new_attributes
248
248
  expect(new_attributes).to eq({"a" => 2, "b" => 4})
249
249
  end
250
250
 
251
251
  it "should return the audited_changes without modification for destroy" do
252
- new_attributes = Audited::Audit.new(audited_changes: {int: 1, array: [1]}, action: :destroy).new_attributes
252
+ new_attributes = VelocityAudited::Audit.new(audited_changes: { int: 1, array: [1]}, action: :destroy).new_attributes
253
253
  expect(new_attributes).to eq({"int" => 1, "array" => [1]})
254
254
  end
255
255
  end
256
256
 
257
257
  describe "old_attributes" do
258
258
  it "should return the audited_changes without modification for create" do
259
- old_attributes = Audited::Audit.new(audited_changes: {int: 1, array: [1]}, action: :create).new_attributes
259
+ old_attributes = VelocityAudited::Audit.new(audited_changes: { int: 1, array: [1]}, action: :create).new_attributes
260
260
  expect(old_attributes).to eq({"int" => 1, "array" => [1]})
261
261
  end
262
262
 
263
263
  it "should return a hash that contains the before values of each attribute" do
264
- old_attributes = Audited::Audit.new(audited_changes: {a: [1, 2], b: [3, 4]}, action: :update).old_attributes
264
+ old_attributes = VelocityAudited::Audit.new(audited_changes: { a: [1, 2], b: [3, 4]}, action: :update).old_attributes
265
265
  expect(old_attributes).to eq({"a" => 1, "b" => 3})
266
266
  end
267
267
 
268
268
  it "should return the audited_changes without modification for destroy" do
269
- old_attributes = Audited::Audit.new(audited_changes: {int: 1, array: [1]}, action: :destroy).old_attributes
269
+ old_attributes = VelocityAudited::Audit.new(audited_changes: { int: 1, array: [1]}, action: :destroy).old_attributes
270
270
  expect(old_attributes).to eq({"int" => 1, "array" => [1]})
271
271
  end
272
272
  end
273
273
 
274
274
  describe "as_user" do
275
275
  it "should record user objects" do
276
- Audited::Audit.as_user(user) do
276
+ VelocityAudited::Audit.as_user(user) do
277
277
  company = Models::ActiveRecord::Company.create name: "The auditors"
278
278
  company.name = "The Auditors, Inc"
279
279
  company.save
@@ -285,13 +285,13 @@ describe Audited::Audit do
285
285
  end
286
286
 
287
287
  it "should support nested as_user" do
288
- Audited::Audit.as_user("sidekiq") do
288
+ VelocityAudited::Audit.as_user("sidekiq") do
289
289
  company = Models::ActiveRecord::Company.create name: "The auditors"
290
290
  company.name = "The Auditors, Inc"
291
291
  company.save
292
292
  expect(company.audits[-1].user).to eq("sidekiq")
293
293
 
294
- Audited::Audit.as_user(user) do
294
+ VelocityAudited::Audit.as_user(user) do
295
295
  company.name = "NEW Auditors, Inc"
296
296
  company.save
297
297
  expect(company.audits[-1].user).to eq(user)
@@ -304,7 +304,7 @@ describe Audited::Audit do
304
304
  end
305
305
 
306
306
  it "should record usernames" do
307
- Audited::Audit.as_user(user.name) do
307
+ VelocityAudited::Audit.as_user(user.name) do
308
308
  company = Models::ActiveRecord::Company.create name: "The auditors"
309
309
  company.name = "The Auditors, Inc"
310
310
  company.save
@@ -320,14 +320,14 @@ describe Audited::Audit do
320
320
  expect(user.save).to eq(true)
321
321
 
322
322
  t1 = Thread.new do
323
- Audited::Audit.as_user(user) do
323
+ VelocityAudited::Audit.as_user(user) do
324
324
  sleep 1
325
325
  expect(Models::ActiveRecord::Company.create(name: "The Auditors, Inc").audits.first.user).to eq(user)
326
326
  end
327
327
  end
328
328
 
329
329
  t2 = Thread.new do
330
- Audited::Audit.as_user(user.name) do
330
+ VelocityAudited::Audit.as_user(user.name) do
331
331
  expect(Models::ActiveRecord::Company.create(name: "The Competing Auditors, LLC").audits.first.username).to eq(user.name)
332
332
  sleep 0.5
333
333
  end
@@ -339,7 +339,7 @@ describe Audited::Audit do
339
339
  end
340
340
 
341
341
  it "should return the value from the yield block" do
342
- result = Audited::Audit.as_user("foo") do
342
+ result = VelocityAudited::Audit.as_user("foo") do
343
343
  42
344
344
  end
345
345
  expect(result).to eq(42)
@@ -347,11 +347,11 @@ describe Audited::Audit do
347
347
 
348
348
  it "should reset audited_user when the yield block raises an exception" do
349
349
  expect {
350
- Audited::Audit.as_user("foo") do
350
+ VelocityAudited::Audit.as_user("foo") do
351
351
  raise StandardError.new("expected")
352
352
  end
353
353
  }.to raise_exception("expected")
354
- expect(Audited.store[:audited_user]).to be_nil
354
+ expect(VelocityAudited.store[:audited_user]).to be_nil
355
355
  end
356
356
  end
357
357
  end
@@ -63,14 +63,14 @@ class Secret2 < ::ActiveRecord::Base
63
63
  self.non_audited_columns = ["delta", "top_secret", "created_at"]
64
64
  end
65
65
 
66
- describe Audited::Auditor do
66
+ describe VelocityAudited::Auditor do
67
67
  describe "configuration" do
68
68
  it "should include instance methods" do
69
- expect(Models::ActiveRecord::User.new).to be_a_kind_of(Audited::Auditor::AuditedInstanceMethods)
69
+ expect(Models::ActiveRecord::User.new).to be_a_kind_of(VelocityAudited::Auditor::AuditedInstanceMethods)
70
70
  end
71
71
 
72
72
  it "should include class methods" do
73
- expect(Models::ActiveRecord::User).to be_a_kind_of(Audited::Auditor::AuditedClassMethods)
73
+ expect(Models::ActiveRecord::User).to be_a_kind_of(VelocityAudited::Auditor::AuditedClassMethods)
74
74
  end
75
75
 
76
76
  ["created_at", "updated_at", "created_on", "updated_on", "lock_version", "id", "password"].each do |column|
@@ -143,7 +143,7 @@ describe Audited::Auditor do
143
143
  end
144
144
 
145
145
  it "should be configurable which attributes are not audited via ignored_attributes" do
146
- Audited.ignored_attributes = ["delta", "top_secret", "created_at"]
146
+ VelocityAudited.ignored_attributes = ["delta", "top_secret", "created_at"]
147
147
 
148
148
  expect(Secret.non_audited_columns).to include("delta", "top_secret", "created_at")
149
149
  end
@@ -202,7 +202,7 @@ describe Audited::Auditor do
202
202
  end
203
203
 
204
204
  it "should redact columns specified in 'redacted' option" do
205
- redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
205
+ redacted = VelocityAudited::Auditor::AuditedInstanceMethods::REDACTED
206
206
  user = Models::ActiveRecord::UserRedactedPassword.create(password: "password")
207
207
  user.save!
208
208
  expect(user.audits.last.audited_changes["password"]).to eq(redacted)
@@ -212,7 +212,7 @@ describe Audited::Auditor do
212
212
  end
213
213
 
214
214
  it "should redact columns specified in 'redacted' option when there are multiple specified" do
215
- redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
215
+ redacted = VelocityAudited::Auditor::AuditedInstanceMethods::REDACTED
216
216
  user =
217
217
  Models::ActiveRecord::UserMultipleRedactedAttributes.create(
218
218
  password: "password",
@@ -244,8 +244,8 @@ describe Audited::Auditor do
244
244
 
245
245
  it "should work if column type is 'json'" do
246
246
  run_migrations(:up, migrations_path, 1)
247
- Audited::Audit.reset_column_information
248
- expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("json")
247
+ VelocityAudited::Audit.reset_column_information
248
+ expect(VelocityAudited::Audit.columns_hash["audited_changes"].sql_type).to eq("json")
249
249
 
250
250
  user = Models::ActiveRecord::User.create
251
251
  user.name = "new name"
@@ -255,8 +255,8 @@ describe Audited::Auditor do
255
255
 
256
256
  it "should work if column type is 'jsonb'" do
257
257
  run_migrations(:up, migrations_path, 2)
258
- Audited::Audit.reset_column_information
259
- expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("jsonb")
258
+ VelocityAudited::Audit.reset_column_information
259
+ expect(VelocityAudited::Audit.columns_hash["audited_changes"].sql_type).to eq("jsonb")
260
260
 
261
261
  user = Models::ActiveRecord::User.create
262
262
  user.name = "new name"
@@ -293,7 +293,7 @@ describe Audited::Auditor do
293
293
  it "should change the audit count" do
294
294
  expect {
295
295
  user
296
- }.to change(Audited::Audit, :count).by(1)
296
+ }.to change(VelocityAudited::Audit, :count).by(1)
297
297
  end
298
298
 
299
299
  it "should create associated audit" do
@@ -302,7 +302,7 @@ describe Audited::Auditor do
302
302
 
303
303
  it "should set the action to create" do
304
304
  expect(user.audits.first.action).to eq("create")
305
- expect(Audited::Audit.creates.order(:id).last).to eq(user.audits.first)
305
+ expect(VelocityAudited::Audit.creates.order(:id).last).to eq(user.audits.first)
306
306
  expect(user.audits.creates.count).to eq(1)
307
307
  expect(user.audits.updates.count).to eq(0)
308
308
  expect(user.audits.destroys.count).to eq(0)
@@ -317,8 +317,8 @@ describe Audited::Auditor do
317
317
  end
318
318
 
319
319
  context "when store_synthesized_enums is set to true" do
320
- before { Audited.store_synthesized_enums = true }
321
- after { Audited.store_synthesized_enums = false }
320
+ before { VelocityAudited.store_synthesized_enums = true }
321
+ after { VelocityAudited.store_synthesized_enums = false }
322
322
 
323
323
  it "should store enum value as Rails synthesized value" do
324
324
  expect(user.audits.first.audited_changes["status"]).to eq("reliable")
@@ -337,7 +337,7 @@ describe Audited::Auditor do
337
337
  it "should not save an audit if only specified on update/destroy" do
338
338
  expect {
339
339
  Models::ActiveRecord::OnUpdateDestroy.create!(name: "Bart")
340
- }.to_not change(Audited::Audit, :count)
340
+ }.to_not change(VelocityAudited::Audit, :count)
341
341
  end
342
342
  end
343
343
 
@@ -349,16 +349,16 @@ describe Audited::Auditor do
349
349
  it "should save an audit" do
350
350
  expect {
351
351
  @user.update_attribute(:name, "Someone")
352
- }.to change(Audited::Audit, :count).by(1)
352
+ }.to change(VelocityAudited::Audit, :count).by(1)
353
353
  expect {
354
354
  @user.update_attribute(:name, "Someone else")
355
- }.to change(Audited::Audit, :count).by(1)
355
+ }.to change(VelocityAudited::Audit, :count).by(1)
356
356
  end
357
357
 
358
358
  it "should set the action to 'update'" do
359
359
  @user.update! name: "Changed"
360
360
  expect(@user.audits.last.action).to eq("update")
361
- expect(Audited::Audit.updates.order(:id).last).to eq(@user.audits.last)
361
+ expect(VelocityAudited::Audit.updates.order(:id).last).to eq(@user.audits.last)
362
362
  expect(@user.audits.updates.last).to eq(@user.audits.last)
363
363
  end
364
364
 
@@ -380,28 +380,28 @@ describe Audited::Auditor do
380
380
  on_create_destroy = Models::ActiveRecord::OnCreateDestroy.create(name: "Bart")
381
381
  expect {
382
382
  on_create_destroy.update! name: "Changed"
383
- }.to_not change(Audited::Audit, :count)
383
+ }.to_not change(VelocityAudited::Audit, :count)
384
384
  end
385
385
 
386
386
  it "should not save an audit if the value doesn't change after type casting" do
387
387
  @user.update! logins: 0, activated: true
388
- expect { @user.update_attribute :logins, "0" }.to_not change(Audited::Audit, :count)
389
- expect { @user.update_attribute :activated, 1 }.to_not change(Audited::Audit, :count)
390
- expect { @user.update_attribute :activated, "1" }.to_not change(Audited::Audit, :count)
388
+ expect { @user.update_attribute :logins, "0" }.to_not change(VelocityAudited::Audit, :count)
389
+ expect { @user.update_attribute :activated, 1 }.to_not change(VelocityAudited::Audit, :count)
390
+ expect { @user.update_attribute :activated, "1" }.to_not change(VelocityAudited::Audit, :count)
391
391
  end
392
392
 
393
393
  describe "with no dirty changes" do
394
394
  it "does not create an audit if the record is not changed" do
395
395
  expect {
396
396
  @user.save!
397
- }.to_not change(Audited::Audit, :count)
397
+ }.to_not change(VelocityAudited::Audit, :count)
398
398
  end
399
399
 
400
400
  it "creates an audit when an audit comment is present" do
401
401
  expect {
402
402
  @user.audit_comment = "Comment"
403
403
  @user.save!
404
- }.to change(Audited::Audit, :count)
404
+ }.to change(VelocityAudited::Audit, :count)
405
405
  end
406
406
  end
407
407
  end
@@ -414,7 +414,7 @@ describe Audited::Auditor do
414
414
  it "should save an audit" do
415
415
  expect {
416
416
  @user.destroy
417
- }.to change(Audited::Audit, :count)
417
+ }.to change(VelocityAudited::Audit, :count)
418
418
 
419
419
  expect(@user.audits.size).to eq(2)
420
420
  end
@@ -423,7 +423,7 @@ describe Audited::Auditor do
423
423
  @user.destroy
424
424
 
425
425
  expect(@user.audits.last.action).to eq("destroy")
426
- expect(Audited::Audit.destroys.order(:id).last).to eq(@user.audits.last)
426
+ expect(VelocityAudited::Audit.destroys.order(:id).last).to eq(@user.audits.last)
427
427
  expect(@user.audits.destroys.last).to eq(@user.audits.last)
428
428
  end
429
429
 
@@ -451,7 +451,7 @@ describe Audited::Auditor do
451
451
 
452
452
  expect {
453
453
  on_create_update.destroy
454
- }.to_not change(Audited::Audit, :count)
454
+ }.to_not change(VelocityAudited::Audit, :count)
455
455
  end
456
456
 
457
457
  it "should audit dependent destructions" do
@@ -460,7 +460,7 @@ describe Audited::Auditor do
460
460
 
461
461
  expect {
462
462
  owner.destroy
463
- }.to change(Audited::Audit, :count)
463
+ }.to change(VelocityAudited::Audit, :count)
464
464
 
465
465
  expect(company.audits.map { |a| a.action }).to eq(["create", "destroy"])
466
466
  end
@@ -543,7 +543,7 @@ describe Audited::Auditor do
543
543
  user.update!(name: "Awesome", username: "keepers")
544
544
  user.update!(activated: true)
545
545
 
546
- Audited.max_audits = 3
546
+ VelocityAudited.max_audits = 3
547
547
  Models::ActiveRecord::User.send(:normalize_audited_options)
548
548
  user.update!(favourite_device: "Android Phone")
549
549
  audits = user.audits
@@ -565,14 +565,14 @@ describe Audited::Auditor do
565
565
  end
566
566
 
567
567
  def stub_global_max_audits(max_audits)
568
- previous_max_audits = Audited.max_audits
568
+ previous_max_audits = VelocityAudited.max_audits
569
569
  previous_user_audited_options = Models::ActiveRecord::User.audited_options.dup
570
570
  begin
571
- Audited.max_audits = max_audits
571
+ VelocityAudited.max_audits = max_audits
572
572
  Models::ActiveRecord::User.send(:normalize_audited_options) # reloads audited_options
573
573
  yield
574
574
  ensure
575
- Audited.max_audits = previous_max_audits
575
+ VelocityAudited.max_audits = previous_max_audits
576
576
  Models::ActiveRecord::User.audited_options = previous_user_audited_options
577
577
  end
578
578
  end
@@ -805,13 +805,13 @@ describe Audited::Auditor do
805
805
  expect {
806
806
  u = Models::ActiveRecord::User.new(name: "Brandon")
807
807
  expect(u.save_without_auditing).to eq(true)
808
- }.to_not change(Audited::Audit, :count)
808
+ }.to_not change(VelocityAudited::Audit, :count)
809
809
  end
810
810
 
811
811
  it "should not save an audit inside of the #without_auditing block" do
812
812
  expect {
813
813
  Models::ActiveRecord::User.without_auditing { Models::ActiveRecord::User.create!(name: "Brandon") }
814
- }.to_not change(Audited::Audit, :count)
814
+ }.to_not change(VelocityAudited::Audit, :count)
815
815
  end
816
816
 
817
817
  it "should reset auditing status even it raises an exception" do
@@ -850,14 +850,14 @@ describe Audited::Auditor do
850
850
  end
851
851
 
852
852
  it "should not save an audit when auditing is globally disabled" do
853
- expect(Audited.auditing_enabled).to eq(true)
854
- Audited.auditing_enabled = false
853
+ expect(VelocityAudited.auditing_enabled).to eq(true)
854
+ VelocityAudited.auditing_enabled = false
855
855
  expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
856
856
 
857
857
  user = create_user
858
858
  expect(user.audits.count).to eq(0)
859
859
 
860
- Audited.auditing_enabled = true
860
+ VelocityAudited.auditing_enabled = true
861
861
  expect(Models::ActiveRecord::User.auditing_enabled).to eq(true)
862
862
 
863
863
  user.update!(name: "Test")
@@ -873,7 +873,7 @@ describe Audited::Auditor do
873
873
  Models::ActiveRecord::User.auditing_enabled = false
874
874
  expect(u.save_with_auditing).to eq(true)
875
875
  Models::ActiveRecord::User.auditing_enabled = true
876
- }.to change(Audited::Audit, :count).by(1)
876
+ }.to change(VelocityAudited::Audit, :count).by(1)
877
877
  end
878
878
 
879
879
  it "should save an audit inside of the #with_auditing block" do
@@ -881,7 +881,7 @@ describe Audited::Auditor do
881
881
  Models::ActiveRecord::User.auditing_enabled = false
882
882
  Models::ActiveRecord::User.with_auditing { Models::ActiveRecord::User.create!(name: "Brandon") }
883
883
  Models::ActiveRecord::User.auditing_enabled = true
884
- }.to change(Audited::Audit, :count).by(1)
884
+ }.to change(VelocityAudited::Audit, :count).by(1)
885
885
  end
886
886
 
887
887
  it "should reset auditing status even it raises an exception" do
@@ -1019,7 +1019,7 @@ describe Audited::Auditor do
1019
1019
 
1020
1020
  it "does not create an audit when only an audit_comment is present" do
1021
1021
  user.audit_comment = "Comment"
1022
- expect { user.save! }.to_not change(Audited::Audit, :count)
1022
+ expect { user.save! }.to_not change(VelocityAudited::Audit, :count)
1023
1023
  end
1024
1024
  end
1025
1025
 
@@ -1091,7 +1091,7 @@ describe Audited::Auditor do
1091
1091
  Models::ActiveRecord::Company.auditing_enabled = false
1092
1092
  company.update! name: "STI auditors"
1093
1093
  Models::ActiveRecord::Company.auditing_enabled = true
1094
- }.to_not change(Audited::Audit, :count)
1094
+ }.to_not change(VelocityAudited::Audit, :count)
1095
1095
  end
1096
1096
  end
1097
1097
  end
@@ -31,8 +31,8 @@ describe AuditsController do
31
31
  render_views
32
32
 
33
33
  before do
34
- Audited::Railtie.initializers.each(&:run)
35
- Audited.current_user_method = :current_user
34
+ VelocityAudited::Railtie.initializers.each(&:run)
35
+ VelocityAudited.current_user_method = :current_user
36
36
  end
37
37
 
38
38
  let(:user) { create_user }
@@ -42,27 +42,27 @@ describe AuditsController do
42
42
  controller.send(:current_user=, user)
43
43
  expect {
44
44
  post :create
45
- }.to change(Audited::Audit, :count)
45
+ }.to change(VelocityAudited::Audit, :count)
46
46
 
47
47
  expect(controller.company.audits.last.user).to eq(user)
48
48
  end
49
49
 
50
50
  it "does not audit when method is not found" do
51
51
  controller.send(:current_user=, user)
52
- Audited.current_user_method = :nope
52
+ VelocityAudited.current_user_method = :nope
53
53
  expect {
54
54
  post :create
55
- }.to change(Audited::Audit, :count)
55
+ }.to change(VelocityAudited::Audit, :count)
56
56
  expect(controller.company.audits.last.user).to eq(nil)
57
57
  end
58
58
 
59
59
  it "should support custom users for sweepers" do
60
60
  controller.send(:custom_user=, user)
61
- Audited.current_user_method = :custom_user
61
+ VelocityAudited.current_user_method = :custom_user
62
62
 
63
63
  expect {
64
64
  post :create
65
- }.to change(Audited::Audit, :count)
65
+ }.to change(VelocityAudited::Audit, :count)
66
66
 
67
67
  expect(controller.company.audits.last.user).to eq(user)
68
68
  end
@@ -92,7 +92,7 @@ describe AuditsController do
92
92
 
93
93
  expect {
94
94
  post :create
95
- }.to change(Audited::Audit, :count)
95
+ }.to change(VelocityAudited::Audit, :count)
96
96
 
97
97
  expect(controller.company.audits.last.user).to eq(user)
98
98
  end
@@ -104,14 +104,14 @@ describe AuditsController do
104
104
 
105
105
  expect {
106
106
  put :update, params: {id: 123}
107
- }.to_not change(Audited::Audit, :count)
107
+ }.to_not change(VelocityAudited::Audit, :count)
108
108
  end
109
109
  end
110
110
  end
111
111
 
112
- describe Audited::Sweeper do
112
+ describe VelocityAudited::Sweeper do
113
113
  it "should be thread-safe" do
114
- instance = Audited::Sweeper.new
114
+ instance = VelocityAudited::Sweeper.new
115
115
 
116
116
  t1 = Thread.new do
117
117
  sleep 0.5
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,7 @@ if Bundler.definition.dependencies.map(&:name).include?("protected_attributes")
8
8
  end
9
9
  require "rails_app/config/environment"
10
10
  require "rspec/rails"
11
- require "audited"
11
+ require "velocity_audited"
12
12
  require "audited-rspec"
13
13
  require "audited_spec_helpers"
14
14
  require "support/active_record/models"
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe VelocityAudited do
4
+ describe "#store" do
5
+ describe "maintains state of store" do
6
+ let(:current_user) { "current_user" }
7
+ before { VelocityAudited.store[:current_user] = current_user }
8
+
9
+ it "when executed without fibers" do
10
+ expect(VelocityAudited.store[:current_user]).to eq(current_user)
11
+ end
12
+
13
+ it "when executed with Fibers" do
14
+ Fiber.new { expect(VelocityAudited.store[:current_user]).to eq(current_user) }.resume
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ require "generators/audited/install_generator"
5
5
  class InstallGeneratorTest < Rails::Generators::TestCase
6
6
  destination File.expand_path("../../tmp", __FILE__)
7
7
  setup :prepare_destination
8
- tests Audited::Generators::InstallGenerator
8
+ tests VelocityAudited::Generators::InstallGenerator
9
9
 
10
10
  test "generate migration with 'text' type for audited_changes column" do
11
11
  run_generator
data/test/test_helper.rb CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
5
5
  require File.expand_path("../../spec/rails_app/config/environment", __FILE__)
6
6
  require "rails/test_help"
7
7
 
8
- require "audited"
8
+ require "velocity_audited"
9
9
 
10
10
  class ActiveSupport::TestCase
11
11
  setup do
@@ -5,7 +5,7 @@ require "generators/audited/upgrade_generator"
5
5
  class UpgradeGeneratorTest < Rails::Generators::TestCase
6
6
  destination File.expand_path("../../tmp", __FILE__)
7
7
  setup :prepare_destination
8
- tests Audited::Generators::UpgradeGenerator
8
+ tests VelocityAudited::Generators::UpgradeGenerator
9
9
  self.use_transactional_tests = false
10
10
 
11
11
  test "should add 'comment' to audits table" do