Commit dff7db5a authored by James Lopez's avatar James Lopez

refactor changes framework and fix spec

parent defa48ea
module EE
module Audit
module Changes
def audit_changes(column, options = {})
return unless model.send("#{column}_changed?")
def audit_changes(current_user, column, options = {})
return unless changed?(column)
@column = column
@options = generate_options(options)
audit_event
audit_event(current_user, parse_options(column, options))
end
protected
......@@ -18,20 +15,28 @@ module EE
private
def generate_options(options)
def changed?(column)
model.previous_changes.has_key?(column)
end
def changes(column)
model.previous_changes[column]
end
def parse_options(column, options)
options.tap do |options_hash|
options_hash[:column] = @column
options_hash[:column] = column
options_hash[:action] = :update
unless options[:skip_changes]
options_hash[:from] = model.public_send("#{@column}_was")
options_hash[:to] = model.public_send("#{@column}")
options_hash[:from] = changes(column).first
options_hash[:to] = changes(column).last
end
end
end
def audit_event
AuditEventService.new(@current_user, model, @options).
def audit_event(current_user, options)
AuditEventService.new(current_user, model, options).
for_changes.security_event
end
end
......
......@@ -13,8 +13,8 @@ describe EE::Audit::Changes do
it 'does not call the audit event service' do
expect_any_instance_of(AuditEventService).not_to receive(:security_event)
user.name = 'new name'
foo_class.new.audit_changes(:email)
user.update!(name: 'new name')
foo_class.new.audit_changes(user, :email)
end
end
......@@ -22,8 +22,8 @@ describe EE::Audit::Changes do
it 'calls the audit event service' do
expect_any_instance_of(AuditEventService).to receive(:security_event)
user.name = 'new name'
foo_class.new.audit_changes(:name)
user.update!(name: 'new name')
foo_class.new.audit_changes(user, :name)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment