audited 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of audited might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +11 -5
- data/CHANGELOG.md +10 -0
- data/README.md +1 -0
- data/lib/audited/audit.rb +1 -1
- data/lib/audited/auditor.rb +18 -3
- data/lib/audited/version.rb +1 -1
- data/spec/audited/auditor_spec.rb +40 -1
- data/spec/support/active_record/models.rb +5 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a879772fc10cec2e4712d1f1407f78d98e424530bcd0124a02982d65c480a86e
         | 
| 4 | 
            +
              data.tar.gz: 3323835790e0dec306f7cdf26cd7a64cd3439f62b65c796ccb7db9d444766548
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f9b3891dbf782c3a24f04fcf552d9c2b821d38af1d4d1cece7b52990657f4a8ecfac86a98dc564b916eea60fe8788729914c58b6ce0e67fe9f55e836366cd13a
         | 
| 7 | 
            +
              data.tar.gz: 0b2bcb8602361987a30661fad0d22bd0058639a8f238457d37d3ec1c98fd03c4f6978164d2975f159d640ae0aceab024e03268616b55eade69d7dc8210c0ac5a
         | 
    
        data/.github/workflows/ci.yml
    CHANGED
    
    | @@ -1,10 +1,8 @@ | |
| 1 1 | 
             
            name: CI
         | 
| 2 2 |  | 
| 3 3 | 
             
            on:
         | 
| 4 | 
            -
              pull_request | 
| 5 | 
            -
              push | 
| 6 | 
            -
                branches:
         | 
| 7 | 
            -
                - main
         | 
| 4 | 
            +
              - pull_request
         | 
| 5 | 
            +
              - push
         | 
| 8 6 |  | 
| 9 7 | 
             
            jobs:
         | 
| 10 8 | 
             
              build:
         | 
| @@ -12,7 +10,7 @@ jobs: | |
| 12 10 | 
             
                strategy:
         | 
| 13 11 | 
             
                  fail-fast: false
         | 
| 14 12 | 
             
                  matrix:
         | 
| 15 | 
            -
                    ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1]
         | 
| 13 | 
            +
                    ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2]
         | 
| 16 14 | 
             
                    appraisal:
         | 
| 17 15 | 
             
                      - rails50
         | 
| 18 16 | 
             
                      - rails51
         | 
| @@ -43,6 +41,8 @@ jobs: | |
| 43 41 | 
             
                        ruby: 3.0
         | 
| 44 42 | 
             
                      - appraisal: rails50
         | 
| 45 43 | 
             
                        ruby: 3.1
         | 
| 44 | 
            +
                      - appraisal: rails50
         | 
| 45 | 
            +
                        ruby: 3.2
         | 
| 46 46 |  | 
| 47 47 | 
             
                      # Rails 5.1 supports Ruby 2.2-2.5
         | 
| 48 48 | 
             
                      - appraisal: rails51
         | 
| @@ -53,6 +53,8 @@ jobs: | |
| 53 53 | 
             
                        ruby: 3.0
         | 
| 54 54 | 
             
                      - appraisal: rails51
         | 
| 55 55 | 
             
                        ruby: 3.1
         | 
| 56 | 
            +
                      - appraisal: rails51
         | 
| 57 | 
            +
                        ruby: 3.2
         | 
| 56 58 |  | 
| 57 59 | 
             
                      # Rails 5.2 supports Ruby 2.2-2.5
         | 
| 58 60 | 
             
                      - appraisal: rails52
         | 
| @@ -63,6 +65,8 @@ jobs: | |
| 63 65 | 
             
                        ruby: 3.0
         | 
| 64 66 | 
             
                      - appraisal: rails52
         | 
| 65 67 | 
             
                        ruby: 3.1
         | 
| 68 | 
            +
                      - appraisal: rails52
         | 
| 69 | 
            +
                        ruby: 3.2
         | 
| 66 70 |  | 
| 67 71 | 
             
                      # Rails 6.0 supports Ruby 2.5-2.7
         | 
| 68 72 | 
             
                      - appraisal: rails60
         | 
| @@ -73,6 +77,8 @@ jobs: | |
| 73 77 | 
             
                        ruby: 3.0
         | 
| 74 78 | 
             
                      - appraisal: rails60
         | 
| 75 79 | 
             
                        ruby: 3.1
         | 
| 80 | 
            +
                      - appraisal: rails60
         | 
| 81 | 
            +
                        ruby: 3.2
         | 
| 76 82 |  | 
| 77 83 | 
             
                      # Rails 6.1 supports Ruby 2.5+
         | 
| 78 84 | 
             
                      - appraisal: rails61
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,15 @@ | |
| 1 1 | 
             
            # Audited ChangeLog
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 5.3.0 (2023-02-14)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            - Audit touch calls - @mcyoung
         | 
| 6 | 
            +
              [#657](https://github.com/collectiveidea/audited/pull/657)
         | 
| 7 | 
            +
            - Allow using with Padrino and other non-Rails projects - @nicduke38degrees
         | 
| 8 | 
            +
              [#655](https://github.com/collectiveidea/audited/pull/655)
         | 
| 9 | 
            +
            - Testing updates - @jdufresne
         | 
| 10 | 
            +
              [#652](https://github.com/collectiveidea/audited/pull/652)
         | 
| 11 | 
            +
              [#653](https://github.com/collectiveidea/audited/pull/653)
         | 
| 12 | 
            +
             | 
| 3 13 | 
             
            ## 5.2.0 (2023-01-23)
         | 
| 4 14 |  | 
| 5 15 | 
             
            Improved
         | 
    
        data/README.md
    CHANGED
    
    | @@ -24,6 +24,7 @@ Audited supports and is [tested against](https://github.com/collectiveidea/audit | |
| 24 24 | 
             
            * 2.7
         | 
| 25 25 | 
             
            * 3.0
         | 
| 26 26 | 
             
            * 3.1
         | 
| 27 | 
            +
            * 3.2
         | 
| 27 28 |  | 
| 28 29 | 
             
            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).
         | 
| 29 30 |  | 
    
        data/lib/audited/audit.rb
    CHANGED
    
    | @@ -174,7 +174,7 @@ module Audited | |
| 174 174 | 
             
                  if action == "create"
         | 
| 175 175 | 
             
                    self.version = 1
         | 
| 176 176 | 
             
                  else
         | 
| 177 | 
            -
                    collection = ( | 
| 177 | 
            +
                    collection = (ActiveRecord::VERSION::MAJOR >= 6) ? self.class.unscoped : self.class
         | 
| 178 178 | 
             
                    max = collection.auditable_finder(auditable_id, auditable_type).maximum(:version) || 0
         | 
| 179 179 | 
             
                    self.version = max + 1
         | 
| 180 180 | 
             
                  end
         | 
    
        data/lib/audited/auditor.rb
    CHANGED
    
    | @@ -84,6 +84,7 @@ module Audited | |
| 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)
         | 
| 87 | 
            +
                    after_touch :audit_touch if audited_options[:on].include?(:touch) && ::ActiveRecord::VERSION::MAJOR >= 6
         | 
| 87 88 | 
             
                    before_destroy :audit_destroy if audited_options[:on].include?(:destroy)
         | 
| 88 89 |  | 
| 89 90 | 
             
                    # Define and set after_audit and around_audit callbacks. This might be useful if you want
         | 
| @@ -230,8 +231,15 @@ module Audited | |
| 230 231 |  | 
| 231 232 | 
             
                  private
         | 
| 232 233 |  | 
| 233 | 
            -
                  def audited_changes
         | 
| 234 | 
            -
                    all_changes =  | 
| 234 | 
            +
                  def audited_changes(for_touch: false)
         | 
| 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
         | 
| 242 | 
            +
             | 
| 235 243 | 
             
                    filtered_changes = \
         | 
| 236 244 | 
             
                      if audited_options[:only].present?
         | 
| 237 245 | 
             
                        all_changes.slice(*self.class.audited_columns)
         | 
| @@ -324,6 +332,13 @@ module Audited | |
| 324 332 | 
             
                    end
         | 
| 325 333 | 
             
                  end
         | 
| 326 334 |  | 
| 335 | 
            +
                  def audit_touch
         | 
| 336 | 
            +
                    unless (changes = audited_changes(for_touch: true)).empty?
         | 
| 337 | 
            +
                      write_audit(action: "update", audited_changes: changes,
         | 
| 338 | 
            +
                        comment: audit_comment)
         | 
| 339 | 
            +
                    end
         | 
| 340 | 
            +
                  end
         | 
| 341 | 
            +
             | 
| 327 342 | 
             
                  def audit_destroy
         | 
| 328 343 | 
             
                    unless new_record?
         | 
| 329 344 | 
             
                      write_audit(action: "destroy", audited_changes: audited_attributes,
         | 
| @@ -474,7 +489,7 @@ module Audited | |
| 474 489 |  | 
| 475 490 | 
             
                  def normalize_audited_options
         | 
| 476 491 | 
             
                    audited_options[:on] = Array.wrap(audited_options[:on])
         | 
| 477 | 
            -
                    audited_options[:on] = [:create, :update, :destroy] if audited_options[:on].empty?
         | 
| 492 | 
            +
                    audited_options[:on] = [:create, :update, :touch, :destroy] if audited_options[:on].empty?
         | 
| 478 493 | 
             
                    audited_options[:only] = Array.wrap(audited_options[:only]).map(&:to_s)
         | 
| 479 494 | 
             
                    audited_options[:except] = Array.wrap(audited_options[:except]).map(&:to_s)
         | 
| 480 495 | 
             
                    max_audits = audited_options[:max_audits] || Audited.max_audits
         | 
    
        data/lib/audited/version.rb
    CHANGED
    
    
| @@ -1,6 +1,9 @@ | |
| 1 1 | 
             
            require "spec_helper"
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            # not testing proxy_respond_to? hack / 2 methods / deprecation of `version`
         | 
| 4 | 
            +
            # also, an additional 3 around `after_touch` for Versions before 6.
         | 
| 5 | 
            +
            uncovered = ActiveRecord::VERSION::MAJOR < 6 ? 12 : 9
         | 
| 6 | 
            +
            SingleCov.covered! uncovered: uncovered
         | 
| 4 7 |  | 
| 5 8 | 
             
            class ConditionalPrivateCompany < ::ActiveRecord::Base
         | 
| 6 9 | 
             
              self.table_name = "companies"
         | 
| @@ -414,6 +417,42 @@ describe Audited::Auditor do | |
| 414 417 | 
             
                end
         | 
| 415 418 | 
             
              end
         | 
| 416 419 |  | 
| 420 | 
            +
              if ::ActiveRecord::VERSION::MAJOR >= 6
         | 
| 421 | 
            +
                describe "on touch" do
         | 
| 422 | 
            +
                  before do
         | 
| 423 | 
            +
                    @user = create_user(name: "Brandon", status: :active, audit_comment: "Touch")
         | 
| 424 | 
            +
                  end
         | 
| 425 | 
            +
             | 
| 426 | 
            +
                  it "should save an audit" do
         | 
| 427 | 
            +
                    expect { @user.touch(:suspended_at) }.to change(Audited::Audit, :count).by(1)
         | 
| 428 | 
            +
                  end
         | 
| 429 | 
            +
             | 
| 430 | 
            +
                  it "should set the action to 'update'" do
         | 
| 431 | 
            +
                    @user.touch(:suspended_at)
         | 
| 432 | 
            +
                    expect(@user.audits.last.action).to eq("update")
         | 
| 433 | 
            +
                    expect(Audited::Audit.updates.order(:id).last).to eq(@user.audits.last)
         | 
| 434 | 
            +
                    expect(@user.audits.updates.last).to eq(@user.audits.last)
         | 
| 435 | 
            +
                  end
         | 
| 436 | 
            +
             | 
| 437 | 
            +
                  it "should store the changed attributes" do
         | 
| 438 | 
            +
                    @user.touch(:suspended_at)
         | 
| 439 | 
            +
                    expect(@user.audits.last.audited_changes["suspended_at"][0]).to be_nil
         | 
| 440 | 
            +
                    expect(Time.parse(@user.audits.last.audited_changes["suspended_at"][1].to_s)).to be_within(1.second).of(Time.current)
         | 
| 441 | 
            +
                  end
         | 
| 442 | 
            +
             | 
| 443 | 
            +
                  it "should store audit comment" do
         | 
| 444 | 
            +
                    expect(@user.audits.last.comment).to eq("Touch")
         | 
| 445 | 
            +
                  end
         | 
| 446 | 
            +
             | 
| 447 | 
            +
                  it "should not save an audit if only specified on create/destroy" do
         | 
| 448 | 
            +
                    on_create_destroy = Models::ActiveRecord::OnCreateDestroyUser.create(name: "Bart")
         | 
| 449 | 
            +
                    expect {
         | 
| 450 | 
            +
                      on_create_destroy.touch(:suspended_at)
         | 
| 451 | 
            +
                    }.to_not change(Audited::Audit, :count)
         | 
| 452 | 
            +
                  end
         | 
| 453 | 
            +
                end
         | 
| 454 | 
            +
              end
         | 
| 455 | 
            +
             | 
| 417 456 | 
             
              describe "on destroy" do
         | 
| 418 457 | 
             
                before do
         | 
| 419 458 | 
             
                  @user = create_user(status: :active)
         | 
| @@ -146,6 +146,11 @@ module Models | |
| 146 146 | 
             
                  audited on: [:create, :destroy]
         | 
| 147 147 | 
             
                end
         | 
| 148 148 |  | 
| 149 | 
            +
                class OnCreateDestroyUser < ::ActiveRecord::Base
         | 
| 150 | 
            +
                  self.table_name = "users"
         | 
| 151 | 
            +
                  audited on: [:create, :destroy]
         | 
| 152 | 
            +
                end
         | 
| 153 | 
            +
             | 
| 149 154 | 
             
                class OnCreateDestroyExceptName < ::ActiveRecord::Base
         | 
| 150 155 | 
             
                  self.table_name = "companies"
         | 
| 151 156 | 
             
                  audited except: :name, on: [:create, :destroy]
         | 
    
        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. | 
| 4 | 
            +
              version: 5.3.0
         | 
| 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- | 
| 16 | 
            +
            date: 2023-02-14 00:00:00.000000000 Z
         | 
| 17 17 | 
             
            dependencies:
         | 
| 18 18 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 19 19 | 
             
              name: activerecord
         |