|
14 | 14 | expect(rules).to eq(separator: '.')
|
15 | 15 | expect(rules).not_to eq(new_rules)
|
16 | 16 | end
|
| 17 | + |
| 18 | + describe 'format' do |
| 19 | + context 'when there is a locale backend' do |
| 20 | + it 'returns the format from the passed rules' do |
| 21 | + currency = Money::Currency.new('EUR') |
| 22 | + rules = { format: '%n%u', separator: '.', delimiter: ',' } |
| 23 | + |
| 24 | + expect(Money::FormattingRules.new(currency, rules)[:format]).to eq('%n%u') |
| 25 | + end |
| 26 | + |
| 27 | + it 'returns the translated format for the locale' do |
| 28 | + I18n.backend.store_translations(:fr, number: { |
| 29 | + currency: { format: { format: "%n %u" } } |
| 30 | + }) |
| 31 | + currency = Money::Currency.new('EUR') |
| 32 | + rules = { separator: '.', delimiter: ',' } |
| 33 | + |
| 34 | + expect(I18n.with_locale(:fr) { Money::FormattingRules.new(currency, rules)[:format] }).to eq('%n %u') |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context 'when there is no locale backend' do |
| 39 | + it 'returns the format from the passed rules' do |
| 40 | + allow(Money).to receive(:locale_backend).and_return(nil) |
| 41 | + currency = Money::Currency.new('EUR') |
| 42 | + rules = { format: '%n%u', separator: '.', delimiter: ',' } |
| 43 | + |
| 44 | + expect(Money::FormattingRules.new(currency, rules)[:format]).to eq('%n%u') |
| 45 | + end |
| 46 | + |
| 47 | + it 'returns the default format for the locale' do |
| 48 | + allow(Money).to receive(:locale_backend).and_return(nil) |
| 49 | + I18n.backend.store_translations(:fr, number: { |
| 50 | + currency: { format: { format: "%n %u" } } |
| 51 | + }) |
| 52 | + currency = Money::Currency.new('EUR') |
| 53 | + rules = { separator: '.', delimiter: ',' } |
| 54 | + allow(currency).to receive(:format).and_return("%u%n") |
| 55 | + |
| 56 | + expect(I18n.with_locale(:fr) { Money::FormattingRules.new(currency, rules)[:format] }).to eq('%u%n') |
| 57 | + end |
| 58 | + end |
| 59 | + end |
17 | 60 | end
|
0 commit comments