Commit a2e03069 authored by Tan Le's avatar Tan Le

Fix parsing action text with boolean value changes

When 'from' and 'to' value being of type Boolean (i.e. false) the action
text drops the 'from <value>' portion due to the generic truthy
check. This change ensures we convert the values to string first and
then check for present to cater for Boolean values.
parent ea7591a6
......@@ -54,8 +54,8 @@ module Audit
def text_for_change(value)
changed = ["Changed #{value}"]
changed << "from #{@details[:from]}" if @details[:from]
changed << "to #{@details[:to]}" if @details[:to]
changed << "from #{@details[:from]}" if @details[:from].to_s.present?
changed << "to #{@details[:to]}" if @details[:to].to_s.present?
if access_level_changed?(value) && expiry_details_available?
changed << text_for_expiry_change
......
......@@ -130,6 +130,25 @@ describe Audit::Details do
end
end
end
context 'update merge request approval permissions' do
let(:merge_request_approval_action) do
{
change: 'prevent merge request approval from authors',
from: false,
to: true,
author_name: user.name,
target_id: project.id,
target_type: 'ApprovalProjectRules'
}
end
it 'humanizes merge request approval permissions action' do
string = described_class.humanize(merge_request_approval_action)
expect(string).to eq('Changed prevent merge request approval from authors from false to true')
end
end
end
context 'group' do
......@@ -197,13 +216,13 @@ describe Audit::Details do
context 'change email' do
let(:action) do
{
change: 'email',
from: 'a@b.com',
to: 'c@b.com',
author_name: 'author',
target_id: '',
target_type: 'Email',
target_details: 'Email'
change: 'email',
from: 'a@b.com',
to: 'c@b.com',
author_name: 'author',
target_id: '',
target_type: 'Email',
target_details: 'Email'
}
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