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

Added char substitution exception for FeatureFlag related event

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