audited 5.3.1 → 5.3.3

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: 051f76b7a9cfbc91222643f2e0ddaa7738d2e446c00ec079dcf0b5d64d7146d3
4
- data.tar.gz: 70ef8ed6c1473ca9d2ac21dc444ae66c0b8d42280e5a3c6bf4d1fe46c07f0e60
3
+ metadata.gz: 1979018213d9b4793bf6c450161759ad6e2ee8c0749c21c9c361bb012b703016
4
+ data.tar.gz: 113875c36e93998ef49e54e1ee65812996a28d553f5fd17c9a6252ea046f2cbc
5
5
  SHA512:
6
- metadata.gz: e085b0764b5feb96dc88cb5db4361f07148550368bde350a45fe21aba47ed80bfa38bb5683437bf3ad7cd983d7dbfe5f4980a80a7da0f1bf76dabea037323b58
7
- data.tar.gz: d55bbe1f1f139efd63ac97281d954bfac440b091e292ad57b23668a456f4e389f4401c9a6e6e4ebb9627d4556a9460cb94d2d71c0f0f2f5174b0e62cb2c10968
6
+ metadata.gz: 9d490c64b590cc9df55d67551908bd450c2737f04d55201000c637122682aaf6c1df069cc61894774c1778ddb29488e0f6e22d5786f155f6415cb47c12fc45f5
7
+ data.tar.gz: 7801bb4dadea8bef4499f50115749cf589f59ffc795c950dbfdf918989311ec6a1380237ef0bbd05f1c1c9edcfe9c42ff5d66d3e44fb71666127fe57dfbcaaee
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Audited ChangeLog
2
2
 
3
+ ## 5.3.3 (2023-03-24)
4
+
5
+ - Use RequestStore instead of Thread.current for thread-safe requests - @tiagocassio
6
+ [#669](https://github.com/collectiveidea/audited/pull/669)
7
+ - Clean up Touch audits - @mcyoung, @akostadinov
8
+ [#668](https://github.com/collectiveidea/audited/pull/668)
9
+
10
+ ## 5.3.2 (2023-02-22)
11
+
12
+ - Touch audit bug fixes - @mcyoung
13
+ [#662](https://github.com/collectiveidea/audited/pull/662)
14
+
3
15
  ## 5.3.1 (2023-02-21)
4
16
 
5
17
  - Ensure touch support doesn't cause double audits - @mcyoung
data/README.md CHANGED
@@ -37,7 +37,7 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
37
37
  Add the gem to your Gemfile:
38
38
 
39
39
  ```ruby
40
- gem "audited", "~> 5.0"
40
+ gem "audited"
41
41
  ```
42
42
 
43
43
  And if you're using ```require: false``` you must add initializers like this:
@@ -238,7 +238,7 @@ class ApplicationController < ActionController::Base
238
238
  if current_user
239
239
  current_user
240
240
  else
241
- 'Elon Musk'
241
+ 'Alexander Fleming'
242
242
  end
243
243
  end
244
244
  end
@@ -233,12 +233,12 @@ module Audited
233
233
 
234
234
  def audited_changes(for_touch: false)
235
235
  all_changes = if for_touch
236
- previous_changes
237
- elsif respond_to?(:changes_to_save)
238
- changes_to_save
239
- else
240
- changes
241
- end
236
+ previous_changes
237
+ elsif respond_to?(:changes_to_save)
238
+ changes_to_save
239
+ else
240
+ changes
241
+ end
242
242
 
243
243
  filtered_changes = \
244
244
  if audited_options[:only].present?
@@ -247,10 +247,10 @@ module Audited
247
247
  all_changes.except(*self.class.non_audited_columns)
248
248
  end
249
249
 
250
- if for_touch
250
+ if for_touch && (last_audit = audits.last&.audited_changes)
251
251
  filtered_changes.reject! do |k, v|
252
- audits.last.audited_changes[k].to_json == v.to_json ||
253
- audits.last.audited_changes[k].to_json == v[1].to_json
252
+ last_audit[k].to_json == v.to_json ||
253
+ last_audit[k].to_json == v[1].to_json
254
254
  end
255
255
  end
256
256
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Audited
4
- VERSION = "5.3.1"
4
+ VERSION = "5.3.3"
5
5
  end
data/lib/audited.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_record"
4
+ require "request_store"
4
5
 
5
6
  module Audited
6
7
  class << self
@@ -24,13 +25,7 @@ module Audited
24
25
  deprecate audit_model: "use Audited.audit_class instead of Audited.audit_model. This method will be removed."
25
26
 
26
27
  def store
27
- current_store_value = Thread.current.thread_variable_get(:audited_store)
28
-
29
- if current_store_value.nil?
30
- Thread.current.thread_variable_set(:audited_store, {})
31
- else
32
- current_store_value
33
- end
28
+ RequestStore.store[:audited_store] ||= {}
34
29
  end
35
30
 
36
31
  def config
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  # not testing proxy_respond_to? hack / 2 methods / deprecation of `version`
4
- # also, an additional 5 around `after_touch` for Versions before 6.
5
- uncovered = ActiveRecord::VERSION::MAJOR < 6 ? 14 : 9
4
+ # also, an additional 6 around `after_touch` for Versions before 6.
5
+ uncovered = (ActiveRecord::VERSION::MAJOR < 6) ? 15 : 9
6
6
  SingleCov.covered! uncovered: uncovered
7
7
 
8
8
  class ConditionalPrivateCompany < ::ActiveRecord::Base
@@ -234,9 +234,9 @@ describe Audited::Auditor do
234
234
  # If we haven't changed any attrs from 'redacted' list, audit should not contain these keys
235
235
  user.name = "new name"
236
236
  user.save!
237
- expect(user.audits.last.audited_changes).to have_key('name')
238
- expect(user.audits.last.audited_changes).not_to have_key('password')
239
- expect(user.audits.last.audited_changes).not_to have_key('ssn')
237
+ expect(user.audits.last.audited_changes).to have_key("name")
238
+ expect(user.audits.last.audited_changes).not_to have_key("password")
239
+ expect(user.audits.last.audited_changes).not_to have_key("ssn")
240
240
  end
241
241
 
242
242
  it "should redact columns in 'redacted' column with custom option" do
@@ -462,8 +462,24 @@ describe Audited::Auditor do
462
462
  }.to_not change(Audited::Audit, :count)
463
463
  end
464
464
 
465
+ it "should store an audit if touch is the only audit" do
466
+ on_touch = Models::ActiveRecord::OnTouchOnly.create(name: "Bart")
467
+ expect {
468
+ on_touch.update(name: "NotBart")
469
+ }.to_not change(Audited::Audit, :count)
470
+ expect {
471
+ on_touch.touch(:suspended_at)
472
+ }.to change(on_touch.audits, :count).from(0).to(1)
473
+
474
+ @user.audits.destroy_all
475
+ expect(@user.audits).to be_empty
476
+ expect {
477
+ @user.touch(:suspended_at)
478
+ }.to change(@user.audits, :count).from(0).to(1)
479
+ end
480
+
465
481
  context "don't double audit" do
466
- let(:user) { Models::ActiveRecord::Owner.create(name: "OwnerUser", suspended_at: 1.month.ago, companies_attributes: [{ name: "OwnedCompany" }]) }
482
+ let(:user) { Models::ActiveRecord::Owner.create(name: "OwnerUser", suspended_at: 1.month.ago, companies_attributes: [{name: "OwnedCompany"}]) }
467
483
  let(:company) { user.companies.first }
468
484
 
469
485
  it "should only create 1 (create) audit for object" do
data/spec/audited_spec.rb CHANGED
@@ -3,16 +3,12 @@ require "spec_helper"
3
3
  describe Audited do
4
4
  describe "#store" do
5
5
  describe "maintains state of store" do
6
- let(:current_user) { "current_user" }
6
+ let(:current_user) { RequestStore.store[:audited_store] }
7
7
  before { Audited.store[:current_user] = current_user }
8
8
 
9
- it "when executed without fibers" do
9
+ it "checks store is not nil" do
10
10
  expect(Audited.store[:current_user]).to eq(current_user)
11
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
12
  end
17
13
  end
18
14
  end
@@ -161,5 +161,10 @@ module Models
161
161
  self.table_name = "companies"
162
162
  audited on: [:create, :update]
163
163
  end
164
+
165
+ class OnTouchOnly < ::ActiveRecord::Base
166
+ self.table_name = "users"
167
+ audited on: [:touch]
168
+ end
164
169
  end
165
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audited
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.1
4
+ version: 5.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2023-02-21 00:00:00.000000000 Z
16
+ date: 2023-04-24 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -35,6 +35,20 @@ dependencies:
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
37
  version: '7.1'
38
+ - !ruby/object:Gem::Dependency
39
+ name: request_store
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '1.2'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '1.2'
38
52
  - !ruby/object:Gem::Dependency
39
53
  name: appraisal
40
54
  requirement: !ruby/object:Gem::Requirement
@@ -252,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
266
  - !ruby/object:Gem::Version
253
267
  version: '0'
254
268
  requirements: []
255
- rubygems_version: 3.4.6
269
+ rubygems_version: 3.4.7
256
270
  signing_key:
257
271
  specification_version: 4
258
272
  summary: Log all changes to your models