spec/audited/auditor_spec.rb in velocity_audited-5.1.4 vs spec/audited/auditor_spec.rb in velocity_audited-5.1.5
- old
+ new
@@ -61,18 +61,18 @@
class Secret2 < ::ActiveRecord::Base
audited
self.non_audited_columns = ["delta", "top_secret", "created_at"]
end
-describe Audited::Auditor do
+describe VelocityAudited::Auditor do
describe "configuration" do
it "should include instance methods" do
- expect(Models::ActiveRecord::User.new).to be_a_kind_of(Audited::Auditor::AuditedInstanceMethods)
+ expect(Models::ActiveRecord::User.new).to be_a_kind_of(VelocityAudited::Auditor::AuditedInstanceMethods)
end
it "should include class methods" do
- expect(Models::ActiveRecord::User).to be_a_kind_of(Audited::Auditor::AuditedClassMethods)
+ expect(Models::ActiveRecord::User).to be_a_kind_of(VelocityAudited::Auditor::AuditedClassMethods)
end
["created_at", "updated_at", "created_on", "updated_on", "lock_version", "id", "password"].each do |column|
it "should not audit #{column}" do
expect(Models::ActiveRecord::User.non_audited_columns).to include(column)
@@ -141,11 +141,11 @@
end
end
end
it "should be configurable which attributes are not audited via ignored_attributes" do
- Audited.ignored_attributes = ["delta", "top_secret", "created_at"]
+ VelocityAudited.ignored_attributes = ["delta", "top_secret", "created_at"]
expect(Secret.non_audited_columns).to include("delta", "top_secret", "created_at")
end
it "should be configurable which attributes are not audited via non_audited_columns=" do
@@ -200,21 +200,21 @@
user.save!
expect(user.audits.last.audited_changes.keys).to eq(%w[non_column_attr])
end
it "should redact columns specified in 'redacted' option" do
- redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
+ redacted = VelocityAudited::Auditor::AuditedInstanceMethods::REDACTED
user = Models::ActiveRecord::UserRedactedPassword.create(password: "password")
user.save!
expect(user.audits.last.audited_changes["password"]).to eq(redacted)
user.password = "new_password"
user.save!
expect(user.audits.last.audited_changes["password"]).to eq([redacted, redacted])
end
it "should redact columns specified in 'redacted' option when there are multiple specified" do
- redacted = Audited::Auditor::AuditedInstanceMethods::REDACTED
+ redacted = VelocityAudited::Auditor::AuditedInstanceMethods::REDACTED
user =
Models::ActiveRecord::UserMultipleRedactedAttributes.create(
password: "password",
ssn: 123456789
)
@@ -242,23 +242,23 @@
run_migrations(:down, migrations_path)
end
it "should work if column type is 'json'" do
run_migrations(:up, migrations_path, 1)
- Audited::Audit.reset_column_information
- expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("json")
+ VelocityAudited::Audit.reset_column_information
+ expect(VelocityAudited::Audit.columns_hash["audited_changes"].sql_type).to eq("json")
user = Models::ActiveRecord::User.create
user.name = "new name"
user.save!
expect(user.audits.last.audited_changes).to eq({"name" => [nil, "new name"]})
end
it "should work if column type is 'jsonb'" do
run_migrations(:up, migrations_path, 2)
- Audited::Audit.reset_column_information
- expect(Audited::Audit.columns_hash["audited_changes"].sql_type).to eq("jsonb")
+ VelocityAudited::Audit.reset_column_information
+ expect(VelocityAudited::Audit.columns_hash["audited_changes"].sql_type).to eq("jsonb")
user = Models::ActiveRecord::User.create
user.name = "new name"
user.save!
expect(user.audits.last.audited_changes).to eq({"name" => [nil, "new name"]})
@@ -291,20 +291,20 @@
let(:user) { create_user status: :reliable, audit_comment: "Create" }
it "should change the audit count" do
expect {
user
- }.to change(Audited::Audit, :count).by(1)
+ }.to change(VelocityAudited::Audit, :count).by(1)
end
it "should create associated audit" do
expect(user.audits.count).to eq(1)
end
it "should set the action to create" do
expect(user.audits.first.action).to eq("create")
- expect(Audited::Audit.creates.order(:id).last).to eq(user.audits.first)
+ expect(VelocityAudited::Audit.creates.order(:id).last).to eq(user.audits.first)
expect(user.audits.creates.count).to eq(1)
expect(user.audits.updates.count).to eq(0)
expect(user.audits.destroys.count).to eq(0)
end
@@ -315,12 +315,12 @@
it "should store enum value" do
expect(user.audits.first.audited_changes["status"]).to eq(1)
end
context "when store_synthesized_enums is set to true" do
- before { Audited.store_synthesized_enums = true }
- after { Audited.store_synthesized_enums = false }
+ before { VelocityAudited.store_synthesized_enums = true }
+ after { VelocityAudited.store_synthesized_enums = false }
it "should store enum value as Rails synthesized value" do
expect(user.audits.first.audited_changes["status"]).to eq("reliable")
end
end
@@ -335,11 +335,11 @@
end
it "should not save an audit if only specified on update/destroy" do
expect {
Models::ActiveRecord::OnUpdateDestroy.create!(name: "Bart")
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
end
describe "on update" do
before do
@@ -347,20 +347,20 @@
end
it "should save an audit" do
expect {
@user.update_attribute(:name, "Someone")
- }.to change(Audited::Audit, :count).by(1)
+ }.to change(VelocityAudited::Audit, :count).by(1)
expect {
@user.update_attribute(:name, "Someone else")
- }.to change(Audited::Audit, :count).by(1)
+ }.to change(VelocityAudited::Audit, :count).by(1)
end
it "should set the action to 'update'" do
@user.update! name: "Changed"
expect(@user.audits.last.action).to eq("update")
- expect(Audited::Audit.updates.order(:id).last).to eq(@user.audits.last)
+ expect(VelocityAudited::Audit.updates.order(:id).last).to eq(@user.audits.last)
expect(@user.audits.updates.last).to eq(@user.audits.last)
end
it "should store the changed attributes" do
@user.update! name: "Changed"
@@ -378,32 +378,32 @@
it "should not save an audit if only specified on create/destroy" do
on_create_destroy = Models::ActiveRecord::OnCreateDestroy.create(name: "Bart")
expect {
on_create_destroy.update! name: "Changed"
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
it "should not save an audit if the value doesn't change after type casting" do
@user.update! logins: 0, activated: true
- expect { @user.update_attribute :logins, "0" }.to_not change(Audited::Audit, :count)
- expect { @user.update_attribute :activated, 1 }.to_not change(Audited::Audit, :count)
- expect { @user.update_attribute :activated, "1" }.to_not change(Audited::Audit, :count)
+ expect { @user.update_attribute :logins, "0" }.to_not change(VelocityAudited::Audit, :count)
+ expect { @user.update_attribute :activated, 1 }.to_not change(VelocityAudited::Audit, :count)
+ expect { @user.update_attribute :activated, "1" }.to_not change(VelocityAudited::Audit, :count)
end
describe "with no dirty changes" do
it "does not create an audit if the record is not changed" do
expect {
@user.save!
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
it "creates an audit when an audit comment is present" do
expect {
@user.audit_comment = "Comment"
@user.save!
- }.to change(Audited::Audit, :count)
+ }.to change(VelocityAudited::Audit, :count)
end
end
end
describe "on destroy" do
@@ -412,20 +412,20 @@
end
it "should save an audit" do
expect {
@user.destroy
- }.to change(Audited::Audit, :count)
+ }.to change(VelocityAudited::Audit, :count)
expect(@user.audits.size).to eq(2)
end
it "should set the action to 'destroy'" do
@user.destroy
expect(@user.audits.last.action).to eq("destroy")
- expect(Audited::Audit.destroys.order(:id).last).to eq(@user.audits.last)
+ expect(VelocityAudited::Audit.destroys.order(:id).last).to eq(@user.audits.last)
expect(@user.audits.destroys.last).to eq(@user.audits.last)
end
it "should store all of the audited attributes" do
@user.destroy
@@ -449,20 +449,20 @@
it "should not save an audit if only specified on create/update" do
on_create_update = Models::ActiveRecord::OnCreateUpdate.create!(name: "Bart")
expect {
on_create_update.destroy
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
it "should audit dependent destructions" do
owner = Models::ActiveRecord::Owner.create!
company = owner.companies.create!
expect {
owner.destroy
- }.to change(Audited::Audit, :count)
+ }.to change(VelocityAudited::Audit, :count)
expect(company.audits.map { |a| a.action }).to eq(["create", "destroy"])
end
end
@@ -541,11 +541,11 @@
user = Models::ActiveRecord::User.create!(name: "Brandon", username: "brandon")
user.update!(name: "Foobar")
user.update!(name: "Awesome", username: "keepers")
user.update!(activated: true)
- Audited.max_audits = 3
+ VelocityAudited.max_audits = 3
Models::ActiveRecord::User.send(:normalize_audited_options)
user.update!(favourite_device: "Android Phone")
audits = user.audits
expect(audits.count).to eq(3)
@@ -563,18 +563,18 @@
expect(user.audits.first.comment).to match(/First audit comment.+is the result of multiple/m)
end
end
def stub_global_max_audits(max_audits)
- previous_max_audits = Audited.max_audits
+ previous_max_audits = VelocityAudited.max_audits
previous_user_audited_options = Models::ActiveRecord::User.audited_options.dup
begin
- Audited.max_audits = max_audits
+ VelocityAudited.max_audits = max_audits
Models::ActiveRecord::User.send(:normalize_audited_options) # reloads audited_options
yield
ensure
- Audited.max_audits = previous_max_audits
+ VelocityAudited.max_audits = previous_max_audits
Models::ActiveRecord::User.audited_options = previous_user_audited_options
end
end
end
@@ -803,17 +803,17 @@
describe "without auditing" do
it "should not save an audit when calling #save_without_auditing" do
expect {
u = Models::ActiveRecord::User.new(name: "Brandon")
expect(u.save_without_auditing).to eq(true)
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
it "should not save an audit inside of the #without_auditing block" do
expect {
Models::ActiveRecord::User.without_auditing { Models::ActiveRecord::User.create!(name: "Brandon") }
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
it "should reset auditing status even it raises an exception" do
begin
Models::ActiveRecord::User.without_auditing { raise }
@@ -848,18 +848,18 @@
expect(Models::ActiveRecord::User.find_by_name("Bart").audits.count).to eq(0)
expect(Models::ActiveRecord::User.find_by_name("Lisa").audits.count).to eq(1)
end
it "should not save an audit when auditing is globally disabled" do
- expect(Audited.auditing_enabled).to eq(true)
- Audited.auditing_enabled = false
+ expect(VelocityAudited.auditing_enabled).to eq(true)
+ VelocityAudited.auditing_enabled = false
expect(Models::ActiveRecord::User.auditing_enabled).to eq(false)
user = create_user
expect(user.audits.count).to eq(0)
- Audited.auditing_enabled = true
+ VelocityAudited.auditing_enabled = true
expect(Models::ActiveRecord::User.auditing_enabled).to eq(true)
user.update!(name: "Test")
expect(user.audits.count).to eq(1)
Models::ActiveRecord::User.enable_auditing
@@ -871,19 +871,19 @@
expect {
u = Models::ActiveRecord::User.new(name: "Brandon")
Models::ActiveRecord::User.auditing_enabled = false
expect(u.save_with_auditing).to eq(true)
Models::ActiveRecord::User.auditing_enabled = true
- }.to change(Audited::Audit, :count).by(1)
+ }.to change(VelocityAudited::Audit, :count).by(1)
end
it "should save an audit inside of the #with_auditing block" do
expect {
Models::ActiveRecord::User.auditing_enabled = false
Models::ActiveRecord::User.with_auditing { Models::ActiveRecord::User.create!(name: "Brandon") }
Models::ActiveRecord::User.auditing_enabled = true
- }.to change(Audited::Audit, :count).by(1)
+ }.to change(VelocityAudited::Audit, :count).by(1)
end
it "should reset auditing status even it raises an exception" do
Models::ActiveRecord::User.disable_auditing
begin
@@ -1017,11 +1017,11 @@
describe "no update with comment only" do
let(:user) { Models::ActiveRecord::NoUpdateWithCommentOnlyUser.create }
it "does not create an audit when only an audit_comment is present" do
user.audit_comment = "Comment"
- expect { user.save! }.to_not change(Audited::Audit, :count)
+ expect { user.save! }.to_not change(VelocityAudited::Audit, :count)
end
end
describe "attr_protected and attr_accessible" do
it "should not raise error when attr_accessible is set and protected is false" do
@@ -1089,9 +1089,9 @@
expect(company.type).to eq("Models::ActiveRecord::Company::STICompany")
expect {
Models::ActiveRecord::Company.auditing_enabled = false
company.update! name: "STI auditors"
Models::ActiveRecord::Company.auditing_enabled = true
- }.to_not change(Audited::Audit, :count)
+ }.to_not change(VelocityAudited::Audit, :count)
end
end
end