velocity_audited 5.1.4 → 5.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 442ee1a7c413fc26e6ddd02cfb1d1201fb5034cb19f54f5607d5ed0f04328012
4
- data.tar.gz: 456faa3bd554bcd65ef6277caf785f283456d3683e54d70067ec75380f618bff
3
+ metadata.gz: 45a7f9290cee6aae7cd334dcb7ad8caa04499b1b7dfbded332b9610edafb0cdf
4
+ data.tar.gz: f61d64e7ca9fd56f06b0b7c3d50a2fb05b4a8557a9c12ae84913f2be4e0ba462
5
5
  SHA512:
6
- metadata.gz: bcb4961726f31f2af54ab96f3501fdc5cc1406c257c9eeb8d985d99e37f60c19112dbd366e46793b29589dd07900be3e16caf23da71f8f330f53cc4ab79c0b05
7
- data.tar.gz: b099ebb6947568e53c37799057f2e39794a13674e5ef712b4c31e6c30a1727fe7c64db7ad25135e9068daa29fd97ec4215c8a0c0673785829964710d36ad58b3
6
+ metadata.gz: f120f84272a20e9eb9eac563c31600076fb7853b5f104d649455ea4cf248515688f988a826bbf7663479fc1fad52b95ba4bd70e1e53e876daab58865b8056520
7
+ data.tar.gz: 37f3937367adee851552565841a7041d52491a9dc637ced5971185aff206371663861698dd11f5cfc53a59c2e270bfe78e14e6a2d895c19ea8b735d2e5e247e3
data/README.md CHANGED
@@ -42,10 +42,10 @@ gem "audited", "~> 5.0"
42
42
  And if you're using ```require: false``` you must add initializers like this:
43
43
 
44
44
  ```ruby
45
- #./config/initializers/audited.rb
46
- require "audited"
45
+ #./config/initializers/velocity_audited.rb
46
+ require "velocity_audited"
47
47
 
48
- Audited::Railtie.initializers.each(&:run)
48
+ VelocityAudited::Railtie.initializers.each(&:run)
49
49
  ```
50
50
 
51
51
  Then, from your Rails app directory, create the `audits` table:
@@ -174,7 +174,7 @@ end
174
174
  You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer file (`config/initializers/audited.rb`):
175
175
 
176
176
  ```ruby
177
- Audited.max_audits = 10 # keep only 10 latest audits
177
+ VelocityAudited.max_audits = 10 # keep only 10 latest audits
178
178
  ```
179
179
 
180
180
  or customize per model:
@@ -213,13 +213,13 @@ end
213
213
  To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
214
214
 
215
215
  ```ruby
216
- Audited.current_user_method = :authenticated_user
216
+ VelocityAudited.current_user_method = :authenticated_user
217
217
  ```
218
218
 
219
219
  Outside of a request, Audited can still record the user with the `as_user` method:
220
220
 
221
221
  ```ruby
222
- Audited.audit_class.as_user(User.find(1)) do
222
+ VelocityAudited.audit_class.as_user(User.find(1)) do
223
223
  post.update!(title: "Hello, world!")
224
224
  end
225
225
  post.audits.last.user # => #<User id: 1>
@@ -246,7 +246,7 @@ end
246
246
  `as_user` also accepts a string, which can be useful for auditing updates made in a CLI environment:
247
247
 
248
248
  ```rb
249
- Audited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
249
+ VelocityAudited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
250
250
  post.update_attributes!(title: "Hello, world!")
251
251
  end
252
252
  post.audits.last.user # => 'console-user-username'
@@ -255,11 +255,11 @@ post.audits.last.user # => 'console-user-username'
255
255
  If you want to set a specific user as the auditor of the commands in a CLI environment, whether that is a string or an ActiveRecord object, you can use the following command:
256
256
 
257
257
  ```rb
258
- Audited.store[:audited_user] = "username"
258
+ VelocityAudited.store[:audited_user] = "username"
259
259
 
260
260
  # or
261
261
 
262
- Audited.store[:audited_user] = User.find(1)
262
+ VelocityAudited.store[:audited_user] = User.find(1)
263
263
  ```
264
264
 
265
265
  ### Associated Audits
@@ -366,7 +366,7 @@ User.auditing_enabled = false
366
366
  To disable auditing on all models:
367
367
 
368
368
  ```ruby
369
- Audited.auditing_enabled = false
369
+ VelocityAudited.auditing_enabled = false
370
370
  ```
371
371
 
372
372
  If you have auditing disabled by default on your model you can enable auditing
@@ -390,18 +390,20 @@ end
390
390
 
391
391
  If you want to extend or modify the audit model, create a new class that
392
392
  inherits from `Audited::Audit`:
393
+
393
394
  ```ruby
394
- class CustomAudit < Audited::Audit
395
+ class CustomAudit < VelocityAudited::Audit
395
396
  def some_custom_behavior
396
397
  "Hiya!"
397
398
  end
398
399
  end
399
400
  ```
400
401
  Then set it in an initializer:
402
+
401
403
  ```ruby
402
- # config/initializers/audited.rb
404
+ # config/initializers/velocity_audited.rb
403
405
 
404
- Audited.config do |config|
406
+ VelocityAudited.config do |config|
405
407
  config.audit_class = CustomAudit
406
408
  end
407
409
  ```
@@ -411,9 +413,9 @@ end
411
413
  In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:
412
414
 
413
415
  ```ruby
414
- # config/initializers/audited.rb
416
+ # config/initializers/velocity_audited.rb
415
417
 
416
- Audited.store_synthesized_enums = true
418
+ VelocityAudited.store_synthesized_enums = true
417
419
  ```
418
420
 
419
421
  ## Support
data/lib/audited/audit.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "set"
4
4
 
5
- module Audited
5
+ module VelocityAudited
6
6
  # Audit saves the changes to ActiveRecord models. It has the following attributes:
7
7
  #
8
8
  # * <tt>auditable</tt>: the ActiveRecord model that was changed
@@ -34,7 +34,7 @@ module Audited
34
34
  end
35
35
 
36
36
  def text_column?
37
- Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
37
+ VelocityAudited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
38
38
  end
39
39
  end
40
40
  end
@@ -134,11 +134,11 @@ module Audited
134
134
  # by +user+. This method is hopefully threadsafe, making it ideal
135
135
  # for background operations that require audit information.
136
136
  def self.as_user(user)
137
- last_audited_user = ::Audited.store[:audited_user]
138
- ::Audited.store[:audited_user] = user
137
+ last_audited_user = ::VelocityAudited.store[:audited_user]
138
+ ::VelocityAudited.store[:audited_user] = user
139
139
  yield
140
140
  ensure
141
- ::Audited.store[:audited_user] = last_audited_user
141
+ ::VelocityAudited.store[:audited_user] = last_audited_user
142
142
  end
143
143
 
144
144
  # @private
@@ -181,18 +181,18 @@ module Audited
181
181
  end
182
182
 
183
183
  def set_audit_user
184
- self.user ||= ::Audited.store[:audited_user] # from .as_user
185
- self.user ||= ::Audited.store[:current_user].try!(:call) # from Sweeper
184
+ self.user ||= ::VelocityAudited.store[:audited_user] # from .as_user
185
+ self.user ||= ::VelocityAudited.store[:current_user].try!(:call) # from Sweeper
186
186
  nil # prevent stopping callback chains
187
187
  end
188
188
 
189
189
  def set_request_uuid
190
- self.request_uuid ||= ::Audited.store[:current_request_uuid]
190
+ self.request_uuid ||= ::VelocityAudited.store[:current_request_uuid]
191
191
  self.request_uuid ||= SecureRandom.uuid
192
192
  end
193
193
 
194
194
  def set_remote_address
195
- self.remote_address ||= ::Audited.store[:current_remote_address]
195
+ self.remote_address ||= ::VelocityAudited.store[:current_remote_address]
196
196
  end
197
197
  end
198
198
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  # Specify this act if you want changes to your model to be saved in an
5
5
  # audit table. This assumes there is an audits table ready.
6
6
  #
@@ -60,10 +60,10 @@ module Audited
60
60
  #
61
61
  def audited(options = {})
62
62
  # don't allow multiple calls
63
- return if included_modules.include?(Audited::Auditor::AuditedInstanceMethods)
63
+ return if included_modules.include?(VelocityAudited::Auditor::AuditedInstanceMethods)
64
64
 
65
- extend Audited::Auditor::AuditedClassMethods
66
- include Audited::Auditor::AuditedInstanceMethods
65
+ extend VelocityAudited::Auditor::AuditedClassMethods
66
+ include VelocityAudited::Auditor::AuditedInstanceMethods
67
67
 
68
68
  class_attribute :audit_associated_with, instance_writer: false
69
69
  class_attribute :audited_options, instance_writer: false
@@ -79,8 +79,8 @@ module Audited
79
79
  before_destroy :require_comment if audited_options[:on].include?(:destroy)
80
80
  end
81
81
 
82
- has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: Audited.audit_class.name, inverse_of: :auditable
83
- Audited.audit_class.audited_class_names << to_s
82
+ has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: VelocityAudited.audit_class.name, inverse_of: :auditable
83
+ VelocityAudited.audit_class.audited_class_names << to_s
84
84
 
85
85
  after_create :audit_create if audited_options[:on].include?(:create)
86
86
  before_update :audit_update if audited_options[:on].include?(:update)
@@ -97,7 +97,7 @@ module Audited
97
97
  end
98
98
 
99
99
  def has_associated_audits
100
- has_many :associated_audits, as: :associated, class_name: Audited.audit_class.name
100
+ has_many :associated_audits, as: :associated, class_name: VelocityAudited.audit_class.name
101
101
  end
102
102
  end
103
103
 
@@ -159,14 +159,14 @@ module Audited
159
159
  # Returns nil for versions greater than revisions count
160
160
  def revision(version)
161
161
  if version == :previous || audits.last.version >= version
162
- revision_with Audited.audit_class.reconstruct_attributes(audits_to(version))
162
+ revision_with VelocityAudited.audit_class.reconstruct_attributes(audits_to(version))
163
163
  end
164
164
  end
165
165
 
166
166
  # Find the oldest revision recorded prior to the date/time provided.
167
167
  def revision_at(date_or_time)
168
168
  audits = self.audits.up_until(date_or_time)
169
- revision_with Audited.audit_class.reconstruct_attributes(audits) unless audits.empty?
169
+ revision_with VelocityAudited.audit_class.reconstruct_attributes(audits) unless audits.empty?
170
170
  end
171
171
 
172
172
  # List of attributes that are audited.
@@ -177,7 +177,7 @@ module Audited
177
177
 
178
178
  # Returns a list combined of record audits and associated audits.
179
179
  def own_and_associated_audits
180
- Audited.audit_class.unscoped
180
+ VelocityAudited.audit_class.unscoped
181
181
  .where("(auditable_type = :type AND auditable_id = :id) OR (associated_type = :type AND associated_id = :id)",
182
182
  type: self.class.base_class.name, id: id)
183
183
  .order(created_at: :desc)
@@ -206,7 +206,7 @@ module Audited
206
206
  revision.send :instance_variable_set, "@destroyed", false
207
207
  revision.send :instance_variable_set, "@_destroyed", false
208
208
  revision.send :instance_variable_set, "@marked_for_destruction", false
209
- Audited.audit_class.assign_revision_attributes(revision, attributes)
209
+ VelocityAudited.audit_class.assign_revision_attributes(revision, attributes)
210
210
 
211
211
  # Remove any association proxies so that they will be recreated
212
212
  # and reference the correct object for this revision. The only way
@@ -239,7 +239,7 @@ module Audited
239
239
  end
240
240
 
241
241
  def normalize_enum_changes(changes)
242
- return changes if Audited.store_synthesized_enums
242
+ return changes if VelocityAudited.store_synthesized_enums
243
243
 
244
244
  self.class.defined_enums.each do |name, values|
245
245
  if changes.has_key?(name)
@@ -318,11 +318,11 @@ module Audited
318
318
  end
319
319
 
320
320
  def add_metadata(attrs)
321
- attrs[:client] = ::Audited.store[:client]
322
- attrs[:origin] = ::Audited.store[:origin]
323
- attrs[:user_agent] = ::Audited.store[:user_agent]
324
- attrs[:ip] = ::Audited.store[:ip]
325
- attrs[:uid] = ::Audited.store[:uid]
321
+ attrs[:client] = ::VelocityAudited.store[:client]
322
+ attrs[:origin] = ::VelocityAudited.store[:origin]
323
+ attrs[:user_agent] = ::VelocityAudited.store[:user_agent]
324
+ attrs[:ip] = ::VelocityAudited.store[:ip]
325
+ attrs[:uid] = ::VelocityAudited.store[:uid]
326
326
  attrs
327
327
  end
328
328
 
@@ -436,19 +436,19 @@ module Audited
436
436
  # convenience wrapper around
437
437
  # @see Audit#as_user.
438
438
  def audit_as(user, &block)
439
- Audited.audit_class.as_user(user, &block)
439
+ VelocityAudited.audit_class.as_user(user, &block)
440
440
  end
441
441
 
442
442
  def auditing_enabled
443
- Audited.store.fetch("#{table_name}_auditing_enabled", true) && Audited.auditing_enabled
443
+ VelocityAudited.store.fetch("#{table_name}_auditing_enabled", true) && VelocityAudited.auditing_enabled
444
444
  end
445
445
 
446
446
  def auditing_enabled=(val)
447
- Audited.store["#{table_name}_auditing_enabled"] = val
447
+ VelocityAudited.store["#{table_name}_auditing_enabled"] = val
448
448
  end
449
449
 
450
450
  def default_ignored_attributes
451
- [primary_key, inheritance_column] | Audited.ignored_attributes
451
+ [primary_key, inheritance_column] | VelocityAudited.ignored_attributes
452
452
  end
453
453
 
454
454
  protected
@@ -458,7 +458,7 @@ module Audited
458
458
  audited_options[:on] = [:create, :update, :destroy] if audited_options[:on].empty?
459
459
  audited_options[:only] = Array.wrap(audited_options[:only]).map(&:to_s)
460
460
  audited_options[:except] = Array.wrap(audited_options[:except]).map(&:to_s)
461
- max_audits = audited_options[:max_audits] || Audited.max_audits
461
+ max_audits = audited_options[:max_audits] || VelocityAudited.max_audits
462
462
  audited_options[:max_audits] = Integer(max_audits).abs if max_audits
463
463
  end
464
464
 
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "audited.sweeper" do
6
6
  ActiveSupport.on_load(:action_controller) do
7
7
  if defined?(ActionController::Base)
8
- ActionController::Base.around_action Audited::Sweeper.new
8
+ ActionController::Base.around_action VelocityAudited::Sweeper.new
9
9
  end
10
10
  if defined?(ActionController::API)
11
- ActionController::API.around_action Audited::Sweeper.new
11
+ ActionController::API.around_action VelocityAudited::Sweeper.new
12
12
  end
13
13
  end
14
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module RspecMatchers
5
5
  # Ensure that the model is audited.
6
6
  #
@@ -221,7 +221,7 @@ module Audited
221
221
  def association_exists?
222
222
  !reflection.nil? &&
223
223
  reflection.macro == :has_many &&
224
- reflection.options[:class_name] == Audited.audit_class.name
224
+ reflection.options[:class_name] == VelocityAudited.audit_class.name
225
225
  end
226
226
  end
227
227
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  class Sweeper
5
5
  STORED_DATA = {
6
6
  current_remote_address: :remote_ip,
@@ -13,7 +13,7 @@ module Audited
13
13
  client: :client
14
14
  }
15
15
 
16
- delegate :store, to: ::Audited
16
+ delegate :store, to: ::VelocityAudited
17
17
 
18
18
  def around(controller)
19
19
  self.controller = controller
@@ -25,7 +25,7 @@ module Audited
25
25
  end
26
26
 
27
27
  def current_user
28
- lambda { controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true) }
28
+ lambda { controller.send(VelocityAudited.current_user_method) if controller.respond_to?(VelocityAudited.current_user_method, true) }
29
29
  end
30
30
 
31
31
  def remote_ip
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
4
- VERSION = "5.1.4"
3
+ module VelocityAudited
4
+ VERSION = "5.1.5"
5
5
  end
data/lib/audited-rspec.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  require "audited/rspec_matchers"
4
4
  module RSpec::Matchers
5
- include Audited::RspecMatchers
5
+ include VelocityAudited::RspecMatchers
6
6
  end
@@ -7,12 +7,12 @@ require "rails/generators/active_record"
7
7
  require "generators/audited/migration"
8
8
  require "generators/audited/migration_helper"
9
9
 
10
- module Audited
10
+ module VelocityAudited
11
11
  module Generators
12
12
  class InstallGenerator < Rails::Generators::Base
13
13
  include Rails::Generators::Migration
14
- include Audited::Generators::MigrationHelper
15
- extend Audited::Generators::Migration
14
+ include VelocityAudited::Generators::MigrationHelper
15
+ extend VelocityAudited::Generators::Migration
16
16
 
17
17
  class_option :audited_changes_column_type, type: :string, default: "text", required: false
18
18
  class_option :audited_user_id_column_type, type: :string, default: "integer", required: false
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module Generators
5
5
  module Migration
6
6
  # Implement the required interface for Rails::Generators::Migration.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Audited
3
+ module VelocityAudited
4
4
  module Generators
5
5
  module MigrationHelper
6
6
  def migration_parent
@@ -7,12 +7,12 @@ require "rails/generators/active_record"
7
7
  require "generators/audited/migration"
8
8
  require "generators/audited/migration_helper"
9
9
 
10
- module Audited
10
+ module VelocityAudited
11
11
  module Generators
12
12
  class UpgradeGenerator < Rails::Generators::Base
13
13
  include Rails::Generators::Migration
14
- include Audited::Generators::MigrationHelper
15
- extend Audited::Generators::Migration
14
+ include VelocityAudited::Generators::MigrationHelper
15
+ extend VelocityAudited::Generators::Migration
16
16
 
17
17
  source_root File.expand_path("../templates", __FILE__)
18
18
 
@@ -25,9 +25,9 @@ module Audited
25
25
  private
26
26
 
27
27
  def migrations_to_be_applied
28
- Audited::Audit.reset_column_information
29
- columns = Audited::Audit.columns.map(&:name)
30
- indexes = Audited::Audit.connection.indexes(Audited::Audit.table_name)
28
+ VelocityAudited::Audit.reset_column_information
29
+ columns = VelocityAudited::Audit.columns.map(&:name)
30
+ indexes = VelocityAudited::Audit.connection.indexes(VelocityAudited::Audit.table_name)
31
31
 
32
32
  yield :add_comment_to_audits unless columns.include?("comment")
33
33
 
@@ -1,53 +1,49 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record"
2
4
 
3
5
  module VelocityAudited
4
- # frozen_string_literal: true
5
- #
6
- module Audited
7
- class << self
8
- attr_accessor \
6
+ class << self
7
+ attr_accessor \
9
8
  :auditing_enabled,
10
9
  :current_user_method,
11
10
  :ignored_attributes,
12
11
  :max_audits,
13
12
  :store_synthesized_enums
14
- attr_writer :audit_class
15
-
16
- def audit_class
17
- @audit_class ||= Audit
18
- end
13
+ attr_writer :audit_class
19
14
 
20
- def store
21
- current_store_value = Thread.current.thread_variable_get(:audited_store)
15
+ def audit_class
16
+ @audit_class ||= Audit
17
+ end
22
18
 
23
- if current_store_value.nil?
24
- Thread.current.thread_variable_set(:audited_store, {})
25
- else
26
- current_store_value
27
- end
28
- end
19
+ def store
20
+ current_store_value = Thread.current.thread_variable_get(:audited_store)
29
21
 
30
- def config
31
- yield(self)
22
+ if current_store_value.nil?
23
+ Thread.current.thread_variable_set(:audited_store, {})
24
+ else
25
+ current_store_value
32
26
  end
33
27
  end
34
28
 
35
- @ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]
36
-
37
- @current_user_method = :current_user
38
- @auditing_enabled = true
39
- @store_synthesized_enums = false
29
+ def config
30
+ yield(self)
31
+ end
40
32
  end
41
33
 
42
- require "audited/auditor"
34
+ @ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]
43
35
 
44
- ActiveSupport.on_load :active_record do
45
- require "audited/audit"
46
- include Audited::Auditor
47
- end
36
+ @current_user_method = :current_user
37
+ @auditing_enabled = true
38
+ @store_synthesized_enums = false
39
+ end
48
40
 
49
- require "audited/sweeper"
50
- require "audited/railtie"
41
+ require "audited/auditor"
51
42
 
43
+ ActiveSupport.on_load :active_record do
44
+ require "audited/audit"
45
+ include VelocityAudited::Auditor
46
+ end
52
47
 
53
- end
48
+ require "audited/sweeper"
49
+ require "audited/railtie"
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: velocity_audited
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.4
4
+ version: 5.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -183,7 +183,6 @@ files:
183
183
  - gemfiles/rails61.gemfile
184
184
  - gemfiles/rails70.gemfile
185
185
  - lib/audited-rspec.rb
186
- - lib/audited.rb
187
186
  - lib/audited/audit.rb
188
187
  - lib/audited/auditor.rb
189
188
  - lib/audited/railtie.rb
@@ -209,7 +208,6 @@ files:
209
208
  - spec/audited/auditor_spec.rb
210
209
  - spec/audited/rspec_matchers_spec.rb
211
210
  - spec/audited/sweeper_spec.rb
212
- - spec/audited_spec.rb
213
211
  - spec/audited_spec_helpers.rb
214
212
  - spec/rails_app/app/assets/config/manifest.js
215
213
  - spec/rails_app/config/application.rb
@@ -225,6 +223,7 @@ files:
225
223
  - spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb
226
224
  - spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb
227
225
  - spec/support/active_record/schema.rb
226
+ - spec/velocity_audited_spec.rb
228
227
  - test/db/version_1.rb
229
228
  - test/db/version_2.rb
230
229
  - test/db/version_3.rb
data/lib/audited.rb DELETED
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_record"
4
-
5
- module Audited
6
- class << self
7
- attr_accessor \
8
- :auditing_enabled,
9
- :current_user_method,
10
- :ignored_attributes,
11
- :max_audits,
12
- :store_synthesized_enums
13
- attr_writer :audit_class
14
-
15
- def audit_class
16
- @audit_class ||= Audit
17
- end
18
-
19
- def store
20
- current_store_value = Thread.current.thread_variable_get(:audited_store)
21
-
22
- if current_store_value.nil?
23
- Thread.current.thread_variable_set(:audited_store, {})
24
- else
25
- current_store_value
26
- end
27
- end
28
-
29
- def config
30
- yield(self)
31
- end
32
- end
33
-
34
- @ignored_attributes = %w[lock_version created_at updated_at created_on updated_on]
35
-
36
- @current_user_method = :current_user
37
- @auditing_enabled = true
38
- @store_synthesized_enums = false
39
- end
40
-
41
- require "audited/auditor"
42
-
43
- ActiveSupport.on_load :active_record do
44
- require "audited/audit"
45
- include Audited::Auditor
46
- end
47
-
48
- require "audited/sweeper"
49
- require "audited/railtie"
data/spec/audited_spec.rb DELETED
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Audited do
4
- describe "#store" do
5
- describe "maintains state of store" do
6
- let(:current_user) { "current_user" }
7
- before { Audited.store[:current_user] = current_user }
8
-
9
- it "when executed without fibers" do
10
- expect(Audited.store[:current_user]).to eq(current_user)
11
- end
12
-
13
- it "when executed with Fibers" do
14
- Fiber.new { expect(Audited.store[:current_user]).to eq(current_user) }.resume
15
- end
16
- end
17
- end
18
- end