Skip to content

Commit

Permalink
Implement test to ensure except option jibes with comment_required op…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdill2 committed Jul 9, 2018
1 parent b410a85 commit 1fa643e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ def stub_global_max_audits(max_audits)
let( :user ) { Models::ActiveRecord::CommentRequiredUser.create!( audit_comment: 'Create' ) }
let( :on_create_user ) { Models::ActiveRecord::OnDestroyCommentRequiredUser.create }
let( :on_destroy_user ) { Models::ActiveRecord::OnDestroyCommentRequiredUser.create }
let( :on_update_except_name_user ) { Models::ActiveRecord::OnUpdateCommentRequiredExceptNameUser.create }

it "should not validate when audit_comment is not supplied" do
expect(user.update_attributes(name: 'Test')).to eq(false)
Expand All @@ -810,6 +811,10 @@ def stub_global_max_audits(max_audits)
expect(on_destroy_user.update_attributes(name: 'Test')).to eq(true)
end

it "should validate when audit_comment is not supplied, and only excepted attributes have been updated" do
expect(on_update_except_name_user.update_attributes(name: 'Test')).to eq(true)
end

it "should validate when audit_comment is supplied" do
expect(user.update_attributes(name: 'Test', audit_comment: 'Update')).to eq(true)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class OnDestroyCommentRequiredUser < ::ActiveRecord::Base
audited comment_required: true, on: :destroy
end

class OnUpdateCommentRequiredExceptNameUser < ::ActiveRecord::Base
self.table_name = :users
audited comment_required: true, except: :name, on: :update
end

class AccessibleAfterDeclarationUser < ::ActiveRecord::Base
self.table_name = :users
audited
Expand Down

0 comments on commit 1fa643e

Please sign in to comment.