spec/audited/audit_spec.rb in audited-4.5.0 vs spec/audited/audit_spec.rb in audited-4.6.0

- old
+ new

@@ -36,9 +36,31 @@ expect(audit).to be_a CustomAudit expect(audit.custom_method).to eq "I'm custom!" end end + it "should undo changes" do + user = Models::ActiveRecord::User.create(name: "John") + user.update_attribute(:name, 'Joe') + user.audits.last.undo + user.reload + + expect(user.name).to eq("John") + end + + it "should undo destroyed model" do + user = Models::ActiveRecord::User.create(name: "John") + user.destroy + user.audits.last.undo + user = Models::ActiveRecord::User.find_by(name: "John") + expect(user.name).to eq("John") + end + + it "should undo created model" do + user = Models::ActiveRecord::User.create(name: "John") + expect {user.audits.last.undo}.to change(Models::ActiveRecord::User, :count).by(-1) + end + context "when a custom audit class is not configured" do it "should default to #{described_class}" do TempModel.audited record = TempModel.create