Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hotfix/audit_commit_validations'

  • Loading branch information...
commit 0c099996733d7752dcfdbdd940ae987b4309713b 2 parents c5174a5 + a5605c2
@kennethkalmer kennethkalmer authored
Showing with 23 additions and 5 deletions.
  1. +2 −2 lib/acts_as_audited/auditor.rb
  2. +21 −3 spec/acts_as_audited_spec.rb
View
4 lib/acts_as_audited/auditor.rb
@@ -67,7 +67,7 @@ def acts_as_audited(options = {})
write_inheritable_attribute :audit_associated_with, options[:associated_with]
if options[:comment_required]
- validates_presence_of :audit_comment
+ validates_presence_of :audit_comment, :if => :auditing_enabled
before_destroy :require_comment
end
@@ -215,7 +215,7 @@ def write_audit(attrs)
end
def require_comment
- if audit_comment.blank?
+ if auditing_enabled && audit_comment.blank?
errors.add(:audit_comment, "Comment required before destruction")
return false
end
View
24 spec/acts_as_audited_spec.rb
@@ -32,7 +32,7 @@
:activated => true,
:suspended_at => yesterday,
:logins => 2)
-
+
u.name.should eq('name')
u.username.should eq('username')
u.password.should eq('password')
@@ -182,7 +182,7 @@
owned_company.update_attribute(:name, 'The Auditors')
owned_company.audits.last.association.should == owner
end
-
+
it "should store the associated object on destroy" do
owned_company.destroy
owned_company.audits.last.association.should == owner
@@ -382,10 +382,16 @@
it "should validate when audit_comment is supplied" do
CommentRequiredUser.new( :audit_comment => 'Create').should be_valid
end
+
+ it "should validate when audit_comment is not supplied, and auditing is disabled" do
+ CommentRequiredUser.disable_auditing
+ CommentRequiredUser.new.should be_valid
+ CommentRequiredUser.enable_auditing
+ end
end
describe "on update" do
- let( :user ) { CommentRequiredUser.create!( :audit_comment => 'Create' )}
+ let( :user ) { CommentRequiredUser.create!( :audit_comment => 'Create' ) }
it "should not validate when audit_comment is not supplied" do
user.update_attributes(:name => 'Test').should be_false
@@ -394,6 +400,12 @@
it "should validate when audit_comment is supplied" do
user.update_attributes(:name => 'Test', :audit_comment => 'Update').should be_true
end
+
+ it "should validate when audit_comment is not supplied, and auditing is disabled" do
+ CommentRequiredUser.disable_auditing
+ user.update_attributes(:name => 'Test').should be_true
+ CommentRequiredUser.enable_auditing
+ end
end
describe "on destroy" do
@@ -407,6 +419,12 @@
user.audit_comment = "Destroy"
user.destroy.should == user
end
+
+ it "should validate when audit_comment is not supplied, and auditing is disabled" do
+ CommentRequiredUser.disable_auditing
+ user.destroy.should == user
+ CommentRequiredUser.enable_auditing
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.