Commit c3896451 authored by Etienne Baqué's avatar Etienne Baqué

Refactored code in Audit::Details and added a test

parent 6c0f34bf
......@@ -27,15 +27,15 @@ module Audit
case action.keys.first
when :add
"Added #{target_type_value}#{@details[:as] ? " as #{@details[:as]}" : ''}"
"Added #{target_detail_value}#{@details[:as] ? " as #{@details[:as]}" : ''}"
when :remove
"Removed #{target_type_value}"
"Removed #{target_detail_value}"
when :failed_login
"Failed to login with #{Gitlab::Auth::OAuth::Provider.label_for(target_type_value).upcase} authentication"
"Failed to login with #{oath_label} authentication"
when :custom_message
target_type_value
detail_value
else
text_for_change(target_type_value)
text_for_change(target_detail_value)
end
end
......@@ -48,10 +48,16 @@ module Audit
changed.join(' ')
end
def target_type_value
target_type = @details[:target_type]
val = @details.values.first
target_type == 'Operations::FeatureFlag' ? val : val.tr('_', ' ')
def target_detail_value
@details[:target_type] == 'Operations::FeatureFlag' ? detail_value : detail_value.tr('_', ' ')
end
def detail_value
@details.values.first
end
def oath_label
Gitlab::Auth::OAuth::Provider.label_for(detail_value).upcase
end
end
end
......@@ -83,6 +83,22 @@ describe Audit::Details do
expect(string).to eq(custom_message)
end
context 'failed_login' do
let(:feature_flag) do
{
failed_login: 'google_oauth2',
target_type: 'Operations::FeatureFlag'
}
end
let(:message) { 'Failed to login with GOOGLE authentication' }
it 'shows the correct failed login meessage' do
string = described_class.humanize(feature_flag)
expect(string).to eq message
end
end
end
context 'deploy key' 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