Skip to content

Commit

Permalink
Merge pull request #886 from trade-tariff/hott-2270-bug-fix
Browse files Browse the repository at this point in the history
HOTT-2270: Fixed missing percent symbol in verbose duty
  • Loading branch information
maverickvi authored Nov 28, 2022
2 parents f8dd269 + dffdad5 commit dd63909
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/formatters/duty_expression_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def format(opts = {})
output << if monetary_unit.present? && !verbose
monetary_unit
else
'%' unless verbose
'%' unless monetary_unit
end
if measurement_unit_abbreviation.present?
output << if formatted
Expand Down
5 changes: 1 addition & 4 deletions app/models/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,7 @@ def verbose_duty_expression
end

def prettify_generated_duty_expression!(duty_expression)
duty_expression.sub!(/\s\s/, ' ')
duty_expression.sub!(/\s%/, '%') if duty_expression.scan(/\d\s%/).present?
duty_expression.sub!(/\/\s[a-zA-Z]/, &:downcase)
duty_expression
duty_expression.gsub(/\s\s/, ' ').gsub(/(\d)\s+%/, '\1%').sub(/\/\s[a-zA-Z]/, &:downcase)
end

def national_measurement_units_for(declarable)
Expand Down
4 changes: 4 additions & 0 deletions spec/models/measure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,10 @@
expect(measure.prettify_generated_duty_expression!(generated_string)).to eq '100% / percentage ABV (% vol) per 100 litre (hl)'
end

it 'removes spaces if there are multiple % symbols' do
expect(measure.prettify_generated_duty_expression!('2.70 % + EAR MAX 6.20 % +ADSZR 11 %')).to eq '2.70% + EAR MAX 6.20% +ADSZR 11%'
end

it 'does not remove space if unit is not present' do
expect(measure.prettify_generated_duty_expression!(generated_string_without_percent_amount)).to eq generated_string_without_percent_amount
end
Expand Down

0 comments on commit dd63909

Please sign in to comment.