Skip to content

Commit

Permalink
Merge branch 'collectiveidea:main' into avoid-orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann authored Apr 5, 2024
2 parents 33025e2 + 706cbff commit c6964f0
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 40 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
matrix:
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2]
appraisal:
- rails50
- rails51
- rails52
- rails60
- rails61
Expand All @@ -31,32 +29,6 @@ jobs:
- ruby: 2.3
db: POSTGRES

# Rails 5.0 supports Ruby 2.2-2.4
- appraisal: rails50
ruby: 2.5
- appraisal: rails50
ruby: 2.6
- appraisal: rails50
ruby: 2.7
- appraisal: rails50
ruby: 3.0
- appraisal: rails50
ruby: 3.1
- appraisal: rails50
ruby: 3.2

# Rails 5.1 supports Ruby 2.2-2.5
- appraisal: rails51
ruby: 2.6
- appraisal: rails51
ruby: 2.7
- appraisal: rails51
ruby: 3.0
- appraisal: rails51
ruby: 3.1
- appraisal: rails51
ruby: 3.2

# Rails 5.2 supports Ruby 2.2-2.5
- appraisal: rails52
ruby: 2.6
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Audited ChangeLog

### 5.6.0 (2024-04-05)

- Removed support for Rails 5.0 and 5.1.
- Replace RequestStore with ActiveSupport::CurrentAttributes - @punkisdead
[#702](https://github.com/collectiveidea/audited/pull/702)

### 5.5.0 (2024-04-02)

- Bad release. Same code as 5.4.1. Use 5.6.0 for updated features.

### 5.4.3 (2024-01-11)

- Ignore readonly columns in audit - @sriddbs
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Audited
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes.


Audited currently (5.x) works with Rails 7.1, 7.0, 6.1, 6.0, 5.2, 5.1, and 5.0.
Audited currently (5.6) works with Rails 7.1, 7.0, 6.1, 6.0, 5.2.

For Rails 5.0 & 5.1, use gem version 5.4.3
For Rails 4, use gem version 4.x
For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable).

Expand Down
8 changes: 4 additions & 4 deletions audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Gem::Specification.new do |gem|
gem.homepage = "https://github.com/collectiveidea/audited"
gem.license = "MIT"

gem.files = `git ls-files`.split($\).reject { |f| f =~ /(\.gemspec)/ }
gem.files = `git ls-files`.split($\).reject { |f| f =~ /^(\.gemspec|\.git|\.standard|\.yard|gemfiles|test|spec)/ }

gem.required_ruby_version = ">= 2.3.0"

gem.add_dependency "activerecord", ">= 5.0", "< 7.2"
gem.add_dependency "request_store", "~> 1.2"
gem.add_dependency "activerecord", ">= 5.2", "< 7.2"
gem.add_dependency "activesupport", ">= 5.2", "< 7.2"

gem.add_development_dependency "appraisal"
gem.add_development_dependency "rails", ">= 5.0", "< 7.2"
gem.add_development_dependency "rails", ">= 5.2", "< 7.2"
gem.add_development_dependency "rspec-rails"
gem.add_development_dependency "standard"
gem.add_development_dependency "single_cov"
Expand Down
8 changes: 6 additions & 2 deletions lib/audited.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: true

require "active_record"
require "request_store"

module Audited
# Wrapper around ActiveSupport::CurrentAttributes
class RequestStore < ActiveSupport::CurrentAttributes
attribute :audited_store
end

class << self
attr_accessor \
:auditing_enabled,
Expand All @@ -27,7 +31,7 @@ def audit_class
deprecator: ActiveSupport::Deprecation.new('6.0.0', 'Audited')

def store
RequestStore.store[:audited_store] ||= {}
RequestStore.audited_store ||= {}
end

def config
Expand Down
3 changes: 2 additions & 1 deletion lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ def audited_changes(for_touch: false, exclude_readonly_attrs: false)
all_changes.except(*self.class.non_audited_columns)
end

filtered_changes = normalize_enum_changes(filtered_changes)

if for_touch && (last_audit = audits.last&.audited_changes)
filtered_changes.reject! do |k, v|
last_audit[k].to_json == v.to_json ||
Expand All @@ -263,7 +265,6 @@ def audited_changes(for_touch: false, exclude_readonly_attrs: false)

filtered_changes = redact_values(filtered_changes)
filtered_changes = filter_encrypted_attrs(filtered_changes)
filtered_changes = normalize_enum_changes(filtered_changes)
filtered_changes.to_hash
end

Expand Down
2 changes: 1 addition & 1 deletion lib/audited/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Audited
VERSION = "5.4.3"
VERSION = "5.6.0"
end
8 changes: 8 additions & 0 deletions spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,14 @@ class CallbacksSpecified < ::ActiveRecord::Base
expect(user.audits.last.action).to eq("update")
expect(user.audits.last.audited_changes.keys).to eq(%w[suspended_at])
end

it "updating nested resource through parent while changing an enum on parent shouldn't double audit" do
user.status = :reliable
user.companies_attributes = [{name: "test"}]
expect { user.save }.to change(user.audits, :count).from(1).to(2)
expect(user.audits.last.action).to eq("update")
expect(user.audits.last.audited_changes.keys).to eq(%w[status])
end
end

context "after updating" do
Expand Down
13 changes: 10 additions & 3 deletions spec/audited_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
describe Audited do
describe "#store" do
describe "maintains state of store" do
let(:current_user) { RequestStore.store[:audited_store] }
before { Audited.store[:current_user] = current_user }
let(:current_user) { Models::ActiveRecord::User.new(name: 'Some User', username: 'some_username') }

it "can store and retrieve current_user" do
expect(Audited.store[:current_user]).to be_nil

Audited.store[:current_user] = current_user

it "checks store is not nil" do
expect(Audited.store[:current_user]).to eq(current_user)
end

it "checks store is not nil" do
expect(Audited.store).not_to be_nil
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
config.use_transactional_fixtures = false if Rails.version.start_with?("4.")
config.use_transactional_tests = false if config.respond_to?(:use_transactional_tests=)
end

1 change: 1 addition & 0 deletions spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Owner < ::ActiveRecord::Base
has_associated_audits
has_many :companies, class_name: "OwnedCompany", dependent: :destroy
accepts_nested_attributes_for :companies
enum status: {active: 0, reliable: 1, banned: 2}
end

class OwnedCompany < ::ActiveRecord::Base
Expand Down

0 comments on commit c6964f0

Please sign in to comment.