Commit 5cc95e50 authored by Etienne Baqué's avatar Etienne Baqué

Added char substitution exception for FeatureFlag related event

parent 9f9638a7
......@@ -2,8 +2,7 @@
module AuditEventsHelper
def human_text(details)
# replace '_' with " " to achive identical behavior with Audit::Details
return details[:custom_message].tr('_', ' ') if details[:custom_message]
return custom_message_for(details) if details[:custom_message]
details.map { |key, value| select_keys(key, value) }.join(" ").humanize
end
......@@ -15,4 +14,10 @@ module AuditEventsHelper
"#{key} <strong>#{value}</strong>"
end
end
def custom_message_for(details)
target_type = details[:target_type].constantize
val = details[:custom_message]
target_type == Operations::FeatureFlag ? val : val.tr('_', ' ')
end
end
......@@ -2,11 +2,12 @@ require 'spec_helper'
describe AuditEventsHelper do
describe '#human_text' do
let(:target_type) { 'User' }
let(:details) do
{
author_name: 'John Doe',
target_id: 1,
target_type: 'User',
target_type: target_type,
target_details: 'Michael'
}
end
......@@ -30,11 +31,27 @@ describe AuditEventsHelper do
expect(subject).to eq(custom_message)
end
context 'when custom message contains "_"' do
let(:custom_message) { "message_with_spaces" }
context 'when the target_type is Operations::FeatureFlag' do
let(:target_type) { 'Operations::FeatureFlag' }
it 'replace them with spaces' do
expect(subject).to eq("message with spaces")
context 'when custom message contains "_"' do
let(:custom_message) { "message_with_spaces" }
it 'does not replace them with spaces' do
expect(subject).to eq("message_with_spaces")
end
end
end
context 'when the target_type is not Operations::FeatureFlag' do
let(:target_type) { 'User' }
context 'when custom message contains "_"' do
let(:custom_message) { "message_with_spaces" }
it 'replaces them with spaces' do
expect(subject).to eq("message with spaces")
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