Skip to content

Commit

Permalink
Merge upstream changes from collectiveidea/audited
Browse files Browse the repository at this point in the history
Stay up to date with the original gem, including support for Rails 6.1
that was added since the fork.

From the changelog:

Added

- Add redacted option
[collectiveidea#485](collectiveidea#485)
- Rails 6.1. support
[collectiveidea#554](collectiveidea#554)
[collectiveidea#559](collectiveidea#559)

Improved

- Avoid extra query on first audit version
[collectiveidea#513](collectiveidea#513)
  • Loading branch information
malcolmbaig committed Apr 7, 2021
2 parents 9b3c366 + 7fd8334 commit dbb6590
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 17 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ before_install:
- "travis_retry gem update --system"
# Rails 4.2 has a bundler 1.x requirement
- if [ $BUNDLE_GEMFILE = $PWD/gemfiles/rails42.gemfile ]; then
rvm @global do gem uninstall bundler -a -x;
travis_retry gem install -v '< 2.0.0' bundler;
travis_retry gem install -v '1.17.3' bundler;
bundle _1.17.3_ install;
else
travis_retry gem install bundler;
fi
Expand All @@ -30,12 +30,17 @@ gemfile:
- gemfiles/rails51.gemfile
- gemfiles/rails52.gemfile
- gemfiles/rails60.gemfile
- gemfiles/rails61.gemfile
matrix:
include:
- rvm: 2.6.3
script: bundle exec rubocop --parallel
env: DB=rubocop # make travis build display nicer
exclude:
- rvm: 2.3.7
gemfile: gemfiles/rails61.gemfile
- rvm: 2.4.4
gemfile: gemfiles/rails61.gemfile
- rvm: 2.3.7
gemfile: gemfiles/rails60.gemfile
- rvm: 2.4.4
Expand Down
9 changes: 8 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ appraise 'rails52' do
end

appraise 'rails60' do
gem 'rails', '>= 6.0.0.rc1', '< 6.1'
gem 'rails', '>= 6.0.0', '< 6.1'
gem "mysql2", ">= 0.4.4"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4"
end

appraise 'rails61' do
gem 'rails', '>= 6.1.0', '< 6.2'
gem "mysql2", ">= 0.4.4"
gem "pg", ">= 1.1", "< 2.0"
gem "sqlite3", "~> 1.4"
end
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## Unreleased

## 4.10.0 (2021-01-07)

Added

- Add redacted option
[#485](https://github.com/collectiveidea/audited/pull/485)
- Rails 6.1. support
[#554](https://github.com/collectiveidea/audited/pull/554)
[#559](https://github.com/collectiveidea/audited/pull/559)

Improved

- Avoid extra query on first audit version
[#513](https://github.com/collectiveidea/audited/pull/513)


## 4.9.0 (2019-07-17)

Breaking changes
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg

**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 (4.x) works with Rails 6.0, 5.2, 5.1, 5.0 and 4.2.
Audited currently (4.x) works with Rails 6.1, Rails 6.0, 5.2, 5.1, 5.0 and 4.2.

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 Expand Up @@ -143,7 +143,7 @@ class User < ActiveRecord::Base
end
```

You can update an audit if only audit_comment is present. You can optionally add the `:update_with_comment_only` option set to `false` to your `audited` call to turn this behavior off for all audits.
You can update an audit only if audit_comment is present. You can optionally add the `:update_with_comment_only` option set to `false` to your `audited` call to turn this behavior off for all audits.

```ruby
class User < ActiveRecord::Base
Expand Down Expand Up @@ -234,6 +234,16 @@ end
post.audits.last.user # => 'console-user-username'
```

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:

```rb
Audited.store[:audited_user] = "username"

# or

Audited.store[:audited_user] = User.find(1)
```

### Associated Audits

Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
Expand Down
4 changes: 2 additions & 2 deletions audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.3.0'

gem.add_dependency 'activerecord', '>= 4.2', '< 6.1'
gem.add_dependency 'activerecord', '>= 4.2', '< 6.2'

gem.add_development_dependency 'appraisal'
gem.add_development_dependency 'rails', '>= 4.2', '< 6.1'
gem.add_development_dependency 'rails', '>= 4.2', '< 6.2'
gem.add_development_dependency 'rubocop', '~> 0.54.0'
gem.add_development_dependency 'rspec-rails', '~> 3.5'
gem.add_development_dependency 'single_cov'
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails60.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rails", ">= 6.0.0.rc1", "< 6.1"
gem "rails", ">= 6.0.0", "< 6.1"
gem "mysql2", ">= 0.4.4"
gem "pg", ">= 0.18", "< 2.0"
gem "sqlite3", "~> 1.4"
Expand Down
10 changes: 10 additions & 0 deletions gemfiles/rails61.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", ">= 6.1.0", "< 6.2"
gem "mysql2", ">= 0.4.4"
gem "pg", ">= 1.1", "< 2.0"
gem "sqlite3", "~> 1.4"

gemspec name: "audited", path: "../"
11 changes: 8 additions & 3 deletions lib/audited/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ module Audited
class YAMLIfTextColumnType
class << self
def load(obj)
if Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
if text_column?
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
else
obj
end
end

def dump(obj)
if Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
if text_column?
ActiveRecord::Coders::YAMLColumn.new(Object).dump(obj)
else
obj
end
end

def text_column?
Audited.audit_class.columns_hash["audited_changes"].type.to_s == "text"
end
end
end

Expand Down Expand Up @@ -171,7 +175,8 @@ def set_version_number
if action == 'create'
self.version = 1
else
max = self.class.auditable_finder(auditable_id, auditable_type).maximum(:version) || 0
collection = Rails::VERSION::MAJOR == 6 ? self.class.unscoped : self.class
max = collection.auditable_finder(auditable_id, auditable_type).maximum(:version) || 0
self.version = max + 1
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/audited/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Audited
VERSION = "4.9.0"
VERSION = "4.10.0"
end
6 changes: 3 additions & 3 deletions spec/audited/audit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec_helper"

SingleCov.covered!
SingleCov.covered! uncovered: 1 # Rails version check

describe Audited::Audit do
let(:user) { Models::ActiveRecord::User.new name: "Testing" }
Expand Down Expand Up @@ -62,7 +62,7 @@ class TempModel < ::ActiveRecord::Base
end

it "does not unserialize from binary columns" do
allow(Audited.audit_class.columns_hash["audited_changes"]).to receive(:type).and_return("foo")
allow(Audited::YAMLIfTextColumnType).to receive(:text_column?).and_return(false)
audit.audited_changes = {foo: "bar"}
expect(audit.audited_changes).to eq "{:foo=>\"bar\"}"
end
Expand Down Expand Up @@ -174,7 +174,7 @@ class TempModel < ::ActiveRecord::Base
it "uses created at" do
Audited::Audit.delete_all
audit = Models::ActiveRecord::User.create(name: "John").audits.last
audit.update_columns(created_at: Time.parse('2018-01-01'))
audit.update_columns(created_at: Time.zone.parse('2018-01-01'))
expect(Audited::Audit.collection_cache_key).to match(/-20180101\d+$/)
end
else
Expand Down
3 changes: 2 additions & 1 deletion spec/audited/sweeper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def populate_user; end
controller.send(:current_user=, user)

expect {
put :update, Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}}
params = Rails::VERSION::MAJOR == 4 ? {id: 123} : {params: {id: 123}}
put :update, **params
}.to_not change( Audited::Audit, :count )
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/audited_spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def create_versions(n = 2, attrs = {})
def run_migrations(direction, migrations_paths, target_version = nil)
if rails_below?('5.2.0.rc1')
ActiveRecord::Migrator.send(direction, migrations_paths, target_version)
else
elsif rails_below?('6.0.0.rc1')
ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version)
else
ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration).send(direction, target_version)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/rails_app/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit dbb6590

Please sign in to comment.