Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecation message to suggest correct formatting. #1056

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/money/money/formatting_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def symbol_position_from(rules)
def warn_about_deprecated_rules(rules)
if rules.has_key?(:symbol_position)
position = rules[:symbol_position]
template = position == :before ? '%u %n' : '%n %u'
template = position == :before ? '%u%n' : '%n%u'

warn "[DEPRECATION] `symbol_position: :#{position}` is deprecated - you can replace it with `format: #{template}`"
end
Expand Down
18 changes: 18 additions & 0 deletions spec/money/formatting_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,22 @@
expect(rules).to eq(separator: '.')
expect(rules).not_to eq(new_rules)
end

context 'when the position is :before' do
it 'warns about deprecated :symbol_position' do
expect_any_instance_of(Money::FormattingRules).to receive(:warn)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We're aware that using any_instance_of may not be great - but given that the deprecation code is called on initialize and the spec helper warning modules are noops, it is difficult to assert against the deprecation warning strings.

We are up for alternatives on testing!

.with('[DEPRECATION] `symbol_position: :before` is deprecated - you can replace it with `format: %u%n`')

Money::FormattingRules.new(Money::Currency.new('USD'), symbol_position: :before)
end
end

context "when the position is :after" do
it 'warns about deprecated :symbol_position' do
expect_any_instance_of(Money::FormattingRules).to receive(:warn)
.with('[DEPRECATION] `symbol_position: :after` is deprecated - you can replace it with `format: %n%u`')

Money::FormattingRules.new(Money::Currency.new('USD'), symbol_position: :after)
end
end
end
Loading