Commit 39f3a17c authored by Max Woolf's avatar Max Woolf

Override ip_address JSON representation for AuditEvents

When called via as_json, AuditEvents serialize
ip_addresses as a Hash with 3 parts as opposed
to a human readable string.

This caused unexpected breaking changes to the
audit log JSON output.
parent c103fd5e
......@@ -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