Commit 8cebe375 authored by Markus Koller's avatar Markus Koller

Merge branch '231343-audit_json-log-serializes-ip_address-into-json-object' into 'master'

Override ip_address JSON representation for AuditEvents

See merge request gitlab-org/gitlab!38157
parents b4f1af74 39f3a17c
......@@ -58,6 +58,12 @@ class AuditEvent < ApplicationRecord
end
end
def as_json(options = {})
super(options).tap do |json|
json['ip_address'] = self.ip_address.to_s
end
end
private
def default_author_value
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuditEvent do
let_it_be(:audit_event) { create(:project_audit_event) }
subject { audit_event }
describe '#as_json' do
context 'ip_address' do
subject { build(:group_audit_event, ip_address: '192.168.1.1').as_json }
it 'overrides the ip_address with its string value' do
expect(subject['ip_address']).to eq('192.168.1.1')
end
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