spec/audited/audit_spec.rb in audited-4.3.0 vs spec/audited/audit_spec.rb in audited-4.4.0

- old
+ new

@@ -1,10 +1,58 @@ require "spec_helper" describe Audited::Audit do let(:user) { Models::ActiveRecord::User.new name: "Testing" } + describe "audit class" do + around(:example) do |example| + original_audit_class = Audited.audit_class + + class CustomAudit < Audited::Audit + def custom_method + "I'm custom!" + end + end + + class TempModel < ::ActiveRecord::Base + self.table_name = :companies + end + + example.run + + Audited.config { |config| config.audit_class = original_audit_class } + Audited::Audit.audited_class_names.delete("TempModel") + Object.send(:remove_const, :TempModel) + Object.send(:remove_const, :CustomAudit) + end + + context "when a custom audit class is configured" do + it "should be used in place of #{described_class}" do + Audited.config { |config| config.audit_class = CustomAudit } + TempModel.audited + + record = TempModel.create + + audit = record.audits.first + expect(audit).to be_a CustomAudit + expect(audit.custom_method).to eq "I'm custom!" + end + end + + context "when a custom audit class is not configured" do + it "should default to #{described_class}" do + TempModel.audited + + record = TempModel.create + + audit = record.audits.first + expect(audit).to be_a Audited::Audit + expect(audit.respond_to?(:custom_method)).to be false + end + end + end + describe "user=" do it "should be able to set the user to a model object" do subject.user = user expect(subject.user).to eq(user) @@ -189,11 +237,10 @@ expect { Audited::Audit.as_user('foo') do raise StandardError.new('expected') end }.to raise_exception('expected') - expect(Thread.current[:audited_user]).to be_nil + expect(Audited.store[:audited_user]).to be_nil end end - end