diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 892ca86a..4f5bf267 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,74 +10,127 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2] + ruby: ["2.3", "2.4", "2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3"] appraisal: - rails52 - rails60 - rails61 - rails70 - rails71 + - rails72 + - rails80 + - rails_main db: [POSTGRES, MYSQL, SQLITE] exclude: # MySQL has issues on Ruby 2.3 # https://github.com/ruby/setup-ruby/issues/150 - - ruby: 2.3 + - ruby: "2.3" db: MYSQL # PostgreSQL is segfaulting on 2.3 # Doesn't seem worth solving. - - ruby: 2.3 + - ruby: "2.3" db: POSTGRES # Rails 5.2 supports Ruby 2.2-2.5 - appraisal: rails52 - ruby: 2.6 + ruby: "2.6" - appraisal: rails52 - ruby: 2.7 + ruby: "2.7" - appraisal: rails52 - ruby: 3.0 + ruby: "3.0" - appraisal: rails52 - ruby: 3.1 + ruby: "3.1" - appraisal: rails52 - ruby: 3.2 + ruby: "3.2" + - appraisal: rails52 + ruby: "3.3" # Rails 6.0 supports Ruby 2.5-2.7 - appraisal: rails60 - ruby: 2.3 + ruby: "2.3" + - appraisal: rails60 + ruby: "2.4" - appraisal: rails60 - ruby: 2.4 + ruby: "3.0" - appraisal: rails60 - ruby: 3.0 + ruby: "3.1" - appraisal: rails60 - ruby: 3.1 + ruby: "3.2" - appraisal: rails60 - ruby: 3.2 + ruby: "3.3" # Rails 6.1 supports Ruby 2.5+ - appraisal: rails61 - ruby: 2.3 + ruby: "2.3" - appraisal: rails61 - ruby: 2.4 + ruby: "2.4" # Rails 7 supports Ruby 2.7+ - appraisal: rails70 - ruby: 2.3 + ruby: "2.3" - appraisal: rails70 - ruby: 2.4 + ruby: "2.4" - appraisal: rails70 - ruby: 2.5 + ruby: "2.5" - appraisal: rails70 - ruby: 2.6 + ruby: "2.6" # Rails 7.1 supports Ruby 2.7+ - appraisal: rails71 - ruby: 2.3 + ruby: "2.3" - appraisal: rails71 - ruby: 2.4 + ruby: "2.4" - appraisal: rails71 - ruby: 2.5 + ruby: "2.5" - appraisal: rails71 - ruby: 2.6 + ruby: "2.6" + + # Rails 7.2 supports Ruby 3.1+ + - appraisal: rails72 + ruby: "2.3" + - appraisal: rails72 + ruby: "2.4" + - appraisal: rails72 + ruby: "2.5" + - appraisal: rails72 + ruby: "2.6" + - appraisal: rails72 + ruby: "2.7" + - appraisal: rails72 + ruby: "3.0" + + # Rails 8.0 supports Ruby 3.2+ + - appraisal: rails80 + ruby: "2.3" + - appraisal: rails80 + ruby: "2.4" + - appraisal: rails80 + ruby: "2.5" + - appraisal: rails80 + ruby: "2.6" + - appraisal: rails80 + ruby: "2.7" + - appraisal: rails80 + ruby: "3.0" + - appraisal: rails80 + ruby: "3.1" + + # Rails main supports Ruby 3.2+ + - appraisal: rails_main + ruby: "2.3" + - appraisal: rails_main + ruby: "2.4" + - appraisal: rails_main + ruby: "2.5" + - appraisal: rails_main + ruby: "2.6" + - appraisal: rails_main + ruby: "2.7" + - appraisal: rails_main + ruby: "3.0" + - appraisal: rails_main + ruby: "3.1" services: postgres: @@ -94,24 +147,24 @@ jobs: env: DB_DATABASE: audited_test DB_USER: root - DB_PASSWORD: 'root' + DB_PASSWORD: "root" DB_HOST: localhost steps: - - name: Setup MySQL - run: | - sudo /etc/init.d/mysql start - mysql -e 'CREATE DATABASE audited_test;' -uroot -proot - mysql -e 'SHOW DATABASES;' -uroot -proot - - uses: actions/checkout@v3 - - name: Copy Gemfile - run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile - - name: Set up Ruby ${{ matrix.ruby }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run tests - env: - DB: ${{ matrix.db }} - run: bundle exec rake + - name: Setup MySQL + run: | + sudo /etc/init.d/mysql start + mysql -e 'CREATE DATABASE audited_test;' -uroot -proot + mysql -e 'SHOW DATABASES;' -uroot -proot + - uses: actions/checkout@v4 + - name: Copy Gemfile + run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + env: + DB: ${{ matrix.db }} + run: bundle exec rake diff --git a/Appraisals b/Appraisals index e724b7b4..d23f3ef0 100644 --- a/Appraisals +++ b/Appraisals @@ -1,26 +1,8 @@ # Include DB adapters matching the version requirements in # rails/activerecord/lib/active_record/connection_adapters/*adapter.rb -appraise "rails50" do - gem "rails", "~> 5.0.0" - gem "mysql2", ">= 0.3.18", "< 0.6.0" - gem "pg", ">= 0.18", "< 2.0" - gem "sqlite3", "~> 1.3.6" - gem "psych", "~> 3.1" - gem "loofah", "2.20.0" -end - -appraise "rails51" do - gem "rails", "~> 5.1.4" - gem "mysql2", ">= 0.3.18", "< 0.6.0" - gem "pg", ">= 0.18", "< 2.0" - gem "sqlite3", "~> 1.3.6" - gem "psych", "~> 3.1" - gem "loofah", "2.20.0" -end - appraise "rails52" do - gem "rails", ">= 5.2.8.1", "< 5.3" + gem "rails", "~> 5.2.8" gem "mysql2", ">= 0.4.4", "< 0.6.0" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" @@ -29,29 +11,50 @@ appraise "rails52" do end appraise "rails60" do - gem "rails", ">= 6.0.0", "< 6.1" + gem "rails", "~> 6.0.6" 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 "rails", "~> 6.1.7" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1", "< 2.0" gem "sqlite3", "~> 1.4" end appraise "rails70" do - gem "rails", ">= 7.0.0", "< 7.1" + gem "rails", "~> 7.0.8" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1" - gem "sqlite3", ">= 1.4" + gem "sqlite3", "~> 1.4" end appraise "rails71" do - gem "rails", ">= 7.1.0.beta1", "< 7.2" + gem "rails", "~> 7.1.3" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1" + gem "sqlite3", "~> 1.4" +end + +appraise "rails72" do + gem "rails", "~> 7.2.0" + gem "mysql2", "~> 0.5" + gem "pg", "~> 1.1" gem "sqlite3", ">= 1.4" end + +appraise "rails80" do + gem "rails", "~> 8.0.0" + gem "mysql2", "~> 0.5" + gem "pg", "~> 1.1" + gem "sqlite3", ">= 1.4" +end + +appraise "rails_main" do + gem "rails", github: "rails/rails", branch: "main" + gem "mysql2", "~> 0.5" + gem "pg", "~> 1.1" + gem "sqlite3", ">= 2.0" +end diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fb4bd0..6395c14f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Audited ChangeLog +### 5.8.0 (2024-11-08) +- Allow calling audited multiple times - @mohammednasser-32 + [734](https://github.com/collectiveidea/audited/pull/734) +- Relax gemspec to allow Rails 8.1 - @BranLiang + [738](https://github.com/collectiveidea/audited/pull/738) + +### 5.7.0 (2024-08-13) + +- Support for Rails 7.2 and Ruby 3.3, and testing cleanups - @mattbrictson + [#723](https://github.com/collectiveidea/audited/pull/723) +- Allow max_audits to be a proc or symbol - @gmhawash + [#718](https://github.com/collectiveidea/audited/pull/718) +- Support Rails 8 - @fernandomenolli + [#717](https://github.com/collectiveidea/audited/pull/717) + + ### 5.6.0 (2024-04-05) - Removed support for Rails 5.0 and 5.1. @@ -38,7 +54,7 @@ ## 5.3.3 (2023-03-24) - Use RequestStore instead of Thread.current for thread-safe requests - @tiagocassio - [#669](https://github.com/collectiveidea/audited/pull/669) + [#669](https://github.com/c ollectiveidea/audited/pull/669) - Clean up Touch audits - @mcyoung, @akostadinov [#668](https://github.com/collectiveidea/audited/pull/668) diff --git a/README.md b/README.md index 4dabfbb7..7a076c2c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 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.6) works with Rails 7.1, 7.0, 6.1, 6.0, 5.2. +Audited currently (5.6) works with Rails 7.2, 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 @@ -26,6 +26,7 @@ Audited supports and is [tested against](https://github.com/collectiveidea/audit * 3.0 * 3.1 * 3.2 +* 3.3 Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls). diff --git a/audited.gemspec b/audited.gemspec index 1f52c860..386cdf67 100644 --- a/audited.gemspec +++ b/audited.gemspec @@ -16,11 +16,11 @@ Gem::Specification.new do |gem| gem.required_ruby_version = ">= 2.3.0" - gem.add_dependency "activerecord", ">= 5.2", "< 7.2" - gem.add_dependency "activesupport", ">= 5.2", "< 7.2" + gem.add_dependency "activerecord", ">= 5.2", "< 8.2" + gem.add_dependency "activesupport", ">= 5.2", "< 8.2" gem.add_development_dependency "appraisal" - gem.add_development_dependency "rails", ">= 5.2", "< 7.2" + gem.add_development_dependency "rails", ">= 5.2", "< 8.2" gem.add_development_dependency "rspec-rails" gem.add_development_dependency "standard" gem.add_development_dependency "single_cov" diff --git a/gemfiles/rails50.gemfile b/gemfiles/rails50.gemfile deleted file mode 100644 index 92d5f8c4..00000000 --- a/gemfiles/rails50.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 5.0.0" -gem "mysql2", ">= 0.3.18", "< 0.6.0" -gem "pg", ">= 0.18", "< 2.0" -gem "sqlite3", "~> 1.3.6" -gem "psych", "~> 3.1" -gem "loofah", "2.20.0" - -gemspec name: "audited", path: "../" diff --git a/gemfiles/rails51.gemfile b/gemfiles/rails51.gemfile deleted file mode 100644 index fa43c66f..00000000 --- a/gemfiles/rails51.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 5.1.4" -gem "mysql2", ">= 0.3.18", "< 0.6.0" -gem "pg", ">= 0.18", "< 2.0" -gem "sqlite3", "~> 1.3.6" -gem "psych", "~> 3.1" -gem "loofah", "2.20.0" - -gemspec name: "audited", path: "../" diff --git a/gemfiles/rails52.gemfile b/gemfiles/rails52.gemfile index b8d7a12b..5b4e53b1 100644 --- a/gemfiles/rails52.gemfile +++ b/gemfiles/rails52.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", ">= 5.2.8.1", "< 5.3" +gem "rails", "~> 5.2.8" gem "mysql2", ">= 0.4.4", "< 0.6.0" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" diff --git a/gemfiles/rails60.gemfile b/gemfiles/rails60.gemfile index e4c46a7a..b182f534 100644 --- a/gemfiles/rails60.gemfile +++ b/gemfiles/rails60.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", ">= 6.0.0", "< 6.1" +gem "rails", "~> 6.0.6" gem "mysql2", ">= 0.4.4" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.4" diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile index b2915340..7fa51886 100644 --- a/gemfiles/rails61.gemfile +++ b/gemfiles/rails61.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", ">= 6.1.0", "< 6.2" +gem "rails", "~> 6.1.7" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1", "< 2.0" gem "sqlite3", "~> 1.4" diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index 396fda4d..592d2cd8 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -2,9 +2,9 @@ source "https://rubygems.org" -gem "rails", ">= 7.0.0", "< 7.1" +gem "rails", "~> 7.0.8" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1" -gem "sqlite3", ">= 1.4" +gem "sqlite3", "~> 1.4" gemspec name: "audited", path: "../" diff --git a/gemfiles/rails71.gemfile b/gemfiles/rails71.gemfile index e34fc967..90e3e25b 100644 --- a/gemfiles/rails71.gemfile +++ b/gemfiles/rails71.gemfile @@ -2,9 +2,9 @@ source "https://rubygems.org" -gem "rails", ">= 7.1.0.beta1", "< 7.2" +gem "rails", "~> 7.1.3" gem "mysql2", ">= 0.4.4" gem "pg", ">= 1.1" -gem "sqlite3", ">= 1.4" +gem "sqlite3", "~> 1.4" gemspec name: "audited", path: "../" diff --git a/gemfiles/rails72.gemfile b/gemfiles/rails72.gemfile new file mode 100644 index 00000000..52cd9d17 --- /dev/null +++ b/gemfiles/rails72.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.2.0" +gem "mysql2", "~> 0.5" +gem "pg", "~> 1.1" +gem "sqlite3", ">= 1.4" + +gemspec name: "audited", path: "../" diff --git a/gemfiles/rails80.gemfile b/gemfiles/rails80.gemfile new file mode 100644 index 00000000..2942329f --- /dev/null +++ b/gemfiles/rails80.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 8.0.0" +gem "mysql2", "~> 0.5" +gem "pg", "~> 1.1" +gem "sqlite3", ">= 1.4" + +gemspec name: "audited", path: "../" diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile new file mode 100644 index 00000000..c0bd890a --- /dev/null +++ b/gemfiles/rails_main.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", github: "rails/rails", branch: "main" +gem "mysql2", "~> 0.5" +gem "pg", "~> 1.1" +gem "sqlite3", ">= 2.0" + +gemspec name: "audited", path: "../" diff --git a/lib/audited/auditor.rb b/lib/audited/auditor.rb index 67fb173c..16f81a95 100644 --- a/lib/audited/auditor.rb +++ b/lib/audited/auditor.rb @@ -59,9 +59,16 @@ module ClassMethods # end # def audited(options = {}) - # don't allow multiple calls - return if included_modules.include?(Audited::Auditor::AuditedInstanceMethods) + audited? ? update_audited_options(options) : set_audit(options) + end + + private + def audited? + included_modules.include?(Audited::Auditor::AuditedInstanceMethods) + end + + def set_audit(options) extend Audited::Auditor::AuditedClassMethods include Audited::Auditor::AuditedInstanceMethods @@ -69,10 +76,7 @@ def audited(options = {}) class_attribute :audited_options, instance_writer: false attr_accessor :audit_version, :audit_comment - self.audited_options = options - normalize_audited_options - - self.audit_associated_with = audited_options[:associated_with] + set_audited_options(options) if audited_options[:comment_required] validate :presence_of_audit_comment @@ -105,6 +109,18 @@ def audited(options = {}) def has_associated_audits has_many :associated_audits, as: :associated, class_name: Audited.audit_class.name, dependent: :nullify end + + def update_audited_options(new_options) + previous_audit_options = self.audited_options + set_audited_options(new_options) + self.reset_audited_columns + end + + def set_audited_options(options) + self.audited_options = options + normalize_audited_options + self.audit_associated_with = audited_options[:associated_with] + end end module AuditedInstanceMethods @@ -389,13 +405,25 @@ def comment_required_state? end def combine_audits_if_needed - max_audits = audited_options[:max_audits] + max_audits = evaluate_max_audits + if max_audits && (extra_count = audits.count - max_audits) > 0 audits_to_combine = audits.limit(extra_count + 1) combine_audits(audits_to_combine) end end + def evaluate_max_audits + max_audits = case (option = audited_options[:max_audits]) + when Proc then option.call + when Symbol then send(option) + else + option + end + + Integer(max_audits).abs if max_audits + end + def require_comment if auditing_enabled && audit_comment.blank? errors.add(:audit_comment, :blank) @@ -507,8 +535,7 @@ def normalize_audited_options audited_options[:on] = ([:create, :update, :touch, :destroy] - Audited.ignored_default_callbacks) if audited_options[:on].empty? audited_options[:only] = Array.wrap(audited_options[:only]).map(&:to_s) audited_options[:except] = Array.wrap(audited_options[:except]).map(&:to_s) - max_audits = audited_options[:max_audits] || Audited.max_audits - audited_options[:max_audits] = Integer(max_audits).abs if max_audits + audited_options[:max_audits] ||= Audited.max_audits end def calculate_non_audited_columns @@ -524,6 +551,11 @@ def calculate_non_audited_columns def class_auditing_enabled Audited.store.fetch("#{table_name}_auditing_enabled", true) end + + def reset_audited_columns + @audited_columns = nil + @non_audited_columns = nil + end end end end diff --git a/lib/audited/version.rb b/lib/audited/version.rb index 7532757a..4e622287 100644 --- a/lib/audited/version.rb +++ b/lib/audited/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Audited - VERSION = "5.6.0" + VERSION = "5.8.0" end diff --git a/spec/audited/auditor_spec.rb b/spec/audited/auditor_spec.rb index d540c85a..d5abe339 100644 --- a/spec/audited/auditor_spec.rb +++ b/spec/audited/auditor_spec.rb @@ -2,7 +2,8 @@ # not testing proxy_respond_to? hack / 2 methods / deprecation of `version` # also, an additional 6 around `after_touch` for Versions before 6. -uncovered = (ActiveRecord::VERSION::MAJOR < 6) ? 15 : 9 +# Increased to 17/10 to get to green CI as a new baseline, August 2024. +uncovered = (ActiveRecord::VERSION::MAJOR < 6) ? 17 : 10 SingleCov.covered! uncovered: uncovered class ConditionalPrivateCompany < ::ActiveRecord::Base @@ -1282,4 +1283,20 @@ def stub_global_max_audits(max_audits) }.to_not change(Audited::Audit, :count) end end + + describe "call audit multiple times" do + it "should update audit options" do + user = Models::ActiveRecord::UserOnlyName.create + user.update(password: "new password 1", name: "new name 1") + expect(user.audits.last.audited_changes.keys).to eq(%w[name]) + + user.class.class_eval do + audited only: :password + end + + user = Models::ActiveRecord::UserOnlyName.last + user.update(password: "new password 2", name: "new name 2") + expect(user.audits.last.audited_changes.keys).to eq(%w[password]) + end + end end diff --git a/spec/audited_spec_helpers.rb b/spec/audited_spec_helpers.rb index dc1c57c6..06faba71 100644 --- a/spec/audited_spec_helpers.rb +++ b/spec/audited_spec_helpers.rb @@ -23,7 +23,7 @@ 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) - elsif rails_below?("6.0.0.rc1") + elsif rails_below?("6.0.0.rc1") || rails_at_least?("7.2.0") ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version) else ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration).send(direction, target_version) @@ -33,4 +33,8 @@ def run_migrations(direction, migrations_paths, target_version = nil) def rails_below?(rails_version) Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(rails_version) end + + def rails_at_least?(rails_version) + Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(rails_version) + end end diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb index ef40455f..a485f848 100644 --- a/spec/rails_app/config/application.rb +++ b/spec/rails_app/config/application.rb @@ -5,7 +5,7 @@ class Application < Rails::Application config.root = File.expand_path("../../", __FILE__) config.i18n.enforce_available_locales = true - if Rails.version.start_with?("7.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=) + if Rails.gem_version >= Gem::Version.new("7.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=) config.active_record.yaml_column_permitted_classes = [ String, Symbol, @@ -33,6 +33,10 @@ class Application < Rails::Application if Rails.gem_version >= Gem::Version.new("7.1") config.active_support.cache_format_version = 7.1 end + + if Rails.gem_version >= Gem::Version.new("8.0.0.alpha") + config.active_support.to_time_preserves_timezone = :zone + end end end diff --git a/spec/support/active_record/models.rb b/spec/support/active_record/models.rb index 2922afe4..53b57863 100644 --- a/spec/support/active_record/models.rb +++ b/spec/support/active_record/models.rb @@ -7,7 +7,12 @@ class User < ::ActiveRecord::Base audited except: :password attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1") attr_protected :logins if respond_to?(:attr_protected) - enum status: {active: 0, reliable: 1, banned: 2} + + if Rails.gem_version >= Gem::Version.new("7.2") + enum :status, {active: 0, reliable: 1, banned: 2} + else + enum status: {active: 0, reliable: 1, banned: 2} + end if Rails.gem_version >= Gem::Version.new("7.1") serialize :phone_numbers, type: Array @@ -31,6 +36,12 @@ class UserOnlyPassword < ::ActiveRecord::Base audited only: :password end + class UserOnlyName < ::ActiveRecord::Base + self.table_name = :users + attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1") + audited only: :name + end + class UserRedactedPassword < ::ActiveRecord::Base self.table_name = :users audited redacted: :password @@ -136,7 +147,12 @@ 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} + + if Rails.gem_version >= Gem::Version.new("7.2") + enum :status, {active: 0, reliable: 1, banned: 2} + else + enum status: {active: 0, reliable: 1, banned: 2} + end end class OwnedCompany < ::ActiveRecord::Base