Skip to content

Commit

Permalink
Deprecate old format rules (tonsky#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
antstorm authored Oct 8, 2018
1 parent 55836cb commit 00bda38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/money/money/formatting_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ def normalize_formatting_rules(rules)
rules = {}
elsif rules.size == 1
rules = rules.pop
rules = { rules => true } if rules.is_a?(Symbol)

if rules.is_a?(Symbol)
warn '[DEPRECATION] Use Hash when passing rules to Money#format.'
rules = { rules => true }
end
end

if !rules.include?(:decimal_mark) && rules.include?(:separator)
rules[:decimal_mark] = rules[:separator]
end

if !rules.include?(:thousands_separator) && rules.include?(:delimiter)
rules[:thousands_separator] = rules[:delimiter]
end

rules
end

Expand Down
4 changes: 4 additions & 0 deletions spec/money/formatting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
end

describe "#format" do
it 'supports the old formatting options' do
expect(Money.zero.format(:display_free)).to eq('free')
end

context "Locale :ja" do
before { @_locale = I18n.locale; I18n.locale = :ja }

Expand Down

0 comments on commit 00bda38

Please sign in to comment.