monetize 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "spec_helper"
4
- require "monetize"
5
- require "monetize/core_extensions"
3
+ require 'spec_helper'
4
+ require 'monetize'
5
+ require 'monetize/core_extensions'
6
6
 
7
- describe Monetize, "core extensions" do
7
+ describe Monetize, 'core extensions' do
8
8
  describe NilClass do
9
- describe "#to_money" do
10
- it "work as documented" do
9
+ describe '#to_money' do
10
+ it 'work as documented' do
11
11
  money = nil.to_money
12
12
  expect(money.cents).to eq 0
13
13
  expect(money.currency).to eq Money.default_currency
14
14
  end
15
15
 
16
- it "accepts optional currency" do
16
+ it 'accepts optional currency' do
17
17
  expect(nil.to_money('USD')).to eq Money.new(nil, 'USD')
18
18
  expect(nil.to_money('EUR')).to eq Money.new(nil, 'EUR')
19
19
  end
@@ -21,10 +21,10 @@ describe Monetize, "core extensions" do
21
21
  end
22
22
 
23
23
  describe Numeric do
24
- describe "#to_money" do
25
- it "work as documented" do
24
+ describe '#to_money' do
25
+ it 'work as documented' do
26
26
  money = 1234.to_money
27
- expect(money.cents).to eq 1234_00
27
+ expect(money.cents).to eq 1_234_00
28
28
  expect(money.currency).to eq Money.default_currency
29
29
 
30
30
  money = 100.37.to_money
@@ -32,183 +32,180 @@ describe Monetize, "core extensions" do
32
32
  expect(money.currency).to eq Money.default_currency
33
33
 
34
34
  money = BigDecimal.new('1234').to_money
35
- expect(money.cents).to eq 1234_00
35
+ expect(money.cents).to eq 1_234_00
36
36
  expect(money.currency).to eq Money.default_currency
37
37
  end
38
38
 
39
- it "accepts optional currency" do
40
- expect(1234.to_money('USD')).to eq Money.new(123400, 'USD')
41
- expect(1234.to_money('EUR')).to eq Money.new(123400, 'EUR')
39
+ it 'accepts optional currency' do
40
+ expect(1234.to_money('USD')).to eq Money.new(1_234_00, 'USD')
41
+ expect(1234.to_money('EUR')).to eq Money.new(1_234_00, 'EUR')
42
42
  end
43
43
 
44
- it "respects :subunit_to_unit currency property" do
44
+ it 'respects :subunit_to_unit currency property' do
45
45
  expect(10.to_money('USD')).to eq Money.new(10_00, 'USD')
46
46
  expect(10.to_money('TND')).to eq Money.new(10_000, 'TND')
47
47
  expect(10.to_money('JPY')).to eq Money.new(10, 'JPY')
48
48
  end
49
49
 
50
- specify "GH-15" do
50
+ specify 'GH-15' do
51
51
  amount = 555.55.to_money
52
- expect(amount).to eq Money.new(55555)
52
+ expect(amount).to eq Money.new(555_55)
53
53
  end
54
54
  end
55
55
  end
56
56
 
57
57
  describe String do
58
- describe "#to_money" do
59
-
58
+ describe '#to_money' do
60
59
  STRING_TO_MONEY = {
61
- "20.15" => Money.new(20_15) ,
62
- "100" => Money.new(100_00) ,
63
- "100.37" => Money.new(100_37) ,
64
- "100,37" => Money.new(100_37) ,
65
- "100 000" => Money.new(100_000_00) ,
66
- "100,000.00" => Money.new(100_000_00) ,
67
- "1,000" => Money.new(1_000_00) ,
68
- "-1,000" => Money.new(-1_000_00) ,
69
- "1,000.5" => Money.new(1_000_50) ,
70
- "1,000.51" => Money.new(1_000_51) ,
71
- "1,000.505" => Money.new(1_000_51) ,
72
- "1,000.504" => Money.new(1_000_50) ,
73
- "1,000.0000" => Money.new(1_000_00) ,
74
- "1,000.5000" => Money.new(1_000_50) ,
75
- "1,000.5099" => Money.new(1_000_51) ,
76
- "1.550" => Money.new(1_55) ,
77
- "25." => Money.new(25_00) ,
78
- ".75" => Money.new(75) ,
79
-
80
- "7.21K" => Money.new(7_210_00) ,
81
- "1M" => Money.new(1_000_000_00) ,
82
- "1.2M" => Money.new(1_200_000_00) ,
83
- "1.37M" => Money.new(1_370_000_00) ,
84
- "3.1415927M" => Money.new(3_141_592_70) ,
85
- ".42B" => Money.new(420_000_000_00) ,
86
- "5T" => Money.new(5_000_000_000_000_00) ,
87
-
88
- "100 USD" => Money.new(100_00, "USD") ,
89
- "-100 USD" => Money.new(-100_00, "USD") ,
90
- "100 EUR" => Money.new(100_00, "EUR") ,
91
- "100.37 EUR" => Money.new(100_37, "EUR") ,
92
- "100,37 EUR" => Money.new(100_37, "EUR") ,
93
- "100,000.00 USD" => Money.new(100_000_00, "USD") ,
94
- "100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
95
- "1,000 USD" => Money.new(1_000_00, "USD") ,
96
- "-1,000 USD" => Money.new(-1_000_00, "USD") ,
97
- "1,000.5500 USD" => Money.new(1_000_55, "USD") ,
98
- "-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
99
- "1.550 USD" => Money.new(1_55, "USD") ,
100
-
101
- "USD 100" => Money.new(100_00, "USD") ,
102
- "EUR 100" => Money.new(100_00, "EUR") ,
103
- "EUR 100.37" => Money.new(100_37, "EUR") ,
104
- "CAD -100.37" => Money.new(-100_37, "CAD") ,
105
- "EUR 100,37" => Money.new(100_37, "EUR") ,
106
- "EUR -100,37" => Money.new(-100_37, "EUR") ,
107
- "USD 100,000.00" => Money.new(100_000_00, "USD") ,
108
- "EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
109
- "USD 1,000" => Money.new(1_000_00, "USD") ,
110
- "USD -1,000" => Money.new(-1_000_00, "USD") ,
111
- "USD 1,000.9000" => Money.new(1_000_90, "USD") ,
112
- "USD -1,000.090" => Money.new(-1_000_09, "USD") ,
113
- "USD 1.5500" => Money.new(1_55, "USD") ,
114
-
115
- "$100 USD" => Money.new(100_00, "USD") ,
116
- "$1,194.59 USD" => Money.new(1_194_59, "USD") ,
117
- "$-1,955 USD" => Money.new(-1_955_00, "USD") ,
118
- "$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
119
- "$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
120
- "$1.99000 USD" => Money.new(1_99, "USD") ,
60
+ '20.15' => Money.new(20_15),
61
+ '100' => Money.new(100_00),
62
+ '100.37' => Money.new(100_37),
63
+ '100,37' => Money.new(100_37),
64
+ '100 000' => Money.new(100_000_00),
65
+ '100,000.00' => Money.new(100_000_00),
66
+ '1,000' => Money.new(1_000_00),
67
+ '-1,000' => Money.new(-1_000_00),
68
+ '1,000.5' => Money.new(1_000_50),
69
+ '1,000.51' => Money.new(1_000_51),
70
+ '1,000.505' => Money.new(1_000_51),
71
+ '1,000.504' => Money.new(1_000_50),
72
+ '1,000.0000' => Money.new(1_000_00),
73
+ '1,000.5000' => Money.new(1_000_50),
74
+ '1,000.5099' => Money.new(1_000_51),
75
+ '1.550' => Money.new(1_55),
76
+ '25.' => Money.new(25_00),
77
+ '.75' => Money.new(75),
78
+
79
+ '7.21K' => Money.new(7_210_00),
80
+ '1M' => Money.new(1_000_000_00),
81
+ '1.2M' => Money.new(1_200_000_00),
82
+ '1.37M' => Money.new(1_370_000_00),
83
+ '3.1415927M' => Money.new(3_141_592_70),
84
+ '.42B' => Money.new(420_000_000_00),
85
+ '5T' => Money.new(5_000_000_000_000_00),
86
+
87
+ '100 USD' => Money.new(100_00, 'USD'),
88
+ '-100 USD' => Money.new(-100_00, 'USD'),
89
+ '100 EUR' => Money.new(100_00, 'EUR'),
90
+ '100.37 EUR' => Money.new(100_37, 'EUR'),
91
+ '100,37 EUR' => Money.new(100_37, 'EUR'),
92
+ '100,000.00 USD' => Money.new(100_000_00, 'USD'),
93
+ '100.000,00 EUR' => Money.new(100_000_00, 'EUR'),
94
+ '1,000 USD' => Money.new(1_000_00, 'USD'),
95
+ '-1,000 USD' => Money.new(-1_000_00, 'USD'),
96
+ '1,000.5500 USD' => Money.new(1_000_55, 'USD'),
97
+ '-1,000.6500 USD' => Money.new(-1_000_65, 'USD'),
98
+ '1.550 USD' => Money.new(1_55, 'USD'),
99
+
100
+ 'USD 100' => Money.new(100_00, 'USD'),
101
+ 'EUR 100' => Money.new(100_00, 'EUR'),
102
+ 'EUR 100.37' => Money.new(100_37, 'EUR'),
103
+ 'CAD -100.37' => Money.new(-100_37, 'CAD'),
104
+ 'EUR 100,37' => Money.new(100_37, 'EUR'),
105
+ 'EUR -100,37' => Money.new(-100_37, 'EUR'),
106
+ 'USD 100,000.00' => Money.new(100_000_00, 'USD'),
107
+ 'EUR 100.000,00' => Money.new(100_000_00, 'EUR'),
108
+ 'USD 1,000' => Money.new(1_000_00, 'USD'),
109
+ 'USD -1,000' => Money.new(-1_000_00, 'USD'),
110
+ 'USD 1,000.9000' => Money.new(1_000_90, 'USD'),
111
+ 'USD -1,000.090' => Money.new(-1_000_09, 'USD'),
112
+ 'USD 1.5500' => Money.new(1_55, 'USD'),
113
+
114
+ '$100 USD' => Money.new(100_00, 'USD'),
115
+ '$1,194.59 USD' => Money.new(1_194_59, 'USD'),
116
+ '$-1,955 USD' => Money.new(-1_955_00, 'USD'),
117
+ '$1,194.5900 USD' => Money.new(1_194_59, 'USD'),
118
+ '$-1,955.000 USD' => Money.new(-1_955_00, 'USD'),
119
+ '$1.99000 USD' => Money.new(1_99, 'USD')
121
120
  }
122
121
 
123
- it "works as documented" do
122
+ it 'works as documented' do
124
123
  STRING_TO_MONEY.each do |string, money|
125
124
  expect(string.to_money).to eq money
126
125
  end
127
126
  end
128
127
 
129
- it "coerces input to string" do
130
- expect(Monetize.parse(20, "USD")).to eq Money.new(20_00, "USD")
128
+ it 'coerces input to string' do
129
+ expect(Monetize.parse(20, 'USD')).to eq Money.new(20_00, 'USD')
131
130
  end
132
131
 
133
- it "accepts optional currency" do
134
- expect("10.10".to_money('USD')).to eq Money.new(1010, 'USD')
135
- expect("10.10".to_money('EUR')).to eq Money.new(1010, 'EUR')
136
- expect("10.10 USD".to_money('USD')).to eq Money.new(1010, 'USD')
132
+ it 'accepts optional currency' do
133
+ expect('10.10'.to_money('USD')).to eq Money.new(10_10, 'USD')
134
+ expect('10.10'.to_money('EUR')).to eq Money.new(10_10, 'EUR')
135
+ expect('10.10 USD'.to_money('USD')).to eq Money.new(10_10, 'USD')
137
136
  end
138
137
 
139
- it "uses parsed currency, even if currency is passed" do
140
- expect("10.10 USD".to_money("EUR")).to eq(Money.new(1010, "USD"))
138
+ it 'uses parsed currency, even if currency is passed' do
139
+ expect('10.10 USD'.to_money('EUR')).to eq(Money.new(10_10, 'USD'))
141
140
  end
142
141
 
143
- it "ignores unrecognized data" do
144
- expect("hello 2000 world".to_money).to eq Money.new(2000_00)
142
+ it 'ignores unrecognized data' do
143
+ expect('hello 2000 world'.to_money).to eq Money.new(2_000_00)
145
144
  end
146
145
 
147
- it "respects :subunit_to_unit currency property" do
148
- expect("1".to_money("USD")).to eq Money.new(1_00, "USD")
149
- expect("1".to_money("TND")).to eq Money.new(1_000, "TND")
150
- expect("1".to_money("JPY")).to eq Money.new(1, "JPY")
151
- expect("1.5".to_money("KWD").cents).to eq 1500
146
+ it 'respects :subunit_to_unit currency property' do
147
+ expect('1'.to_money('USD')).to eq Money.new(1_00, 'USD')
148
+ expect('1'.to_money('TND')).to eq Money.new(1_000, 'TND')
149
+ expect('1'.to_money('JPY')).to eq Money.new(1, 'JPY')
150
+ expect('1.5'.to_money('KWD').cents).to eq 1_500
152
151
  end
153
152
  end
154
153
 
155
- describe "#to_currency" do
156
- it "converts String to Currency" do
157
- expect("USD".to_currency).to eq Money::Currency.new("USD")
158
- expect("EUR".to_currency).to eq Money::Currency.new("EUR")
154
+ describe '#to_currency' do
155
+ it 'converts String to Currency' do
156
+ expect('USD'.to_currency).to eq Money::Currency.new('USD')
157
+ expect('EUR'.to_currency).to eq Money::Currency.new('EUR')
159
158
  end
160
159
 
161
- it "raises Money::Currency::UnknownCurrency with unknown Currency" do
162
- expect { "XXX".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
163
- expect { " ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
160
+ it 'raises Money::Currency::UnknownCurrency with unknown Currency' do
161
+ expect { 'XXX'.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
162
+ expect { ' '.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
164
163
  end
165
164
  end
166
165
  end
167
166
 
168
167
  describe Hash do
169
- describe "#to_money" do
170
-
171
- context "when currency is present in hash" do
172
- subject(:hash){ { cents: 5, currency: "EUR" } }
168
+ describe '#to_money' do
169
+ context 'when currency is present in hash' do
170
+ subject(:hash) { {cents: 5, currency: 'EUR'} }
173
171
 
174
- it "converts Hash to Money using key from hash" do
175
- expect(hash.to_money).to eq(Money.new(5, "EUR"))
172
+ it 'converts Hash to Money using key from hash' do
173
+ expect(hash.to_money).to eq(Money.new(5, 'EUR'))
176
174
  end
177
175
  end
178
176
 
179
- context "when currency is passed as argument" do
180
- subject(:hash){ { cents: 10 } }
177
+ context 'when currency is passed as argument' do
178
+ subject(:hash) { {cents: 10} }
181
179
 
182
- it "converts Hash to Money using passed currency argument" do
183
- expect(hash.to_money("JPY")).to eq(Money.new(10, "JPY"))
180
+ it 'converts Hash to Money using passed currency argument' do
181
+ expect(hash.to_money('JPY')).to eq(Money.new(10, 'JPY'))
184
182
  end
185
183
  end
186
184
 
187
- context "when no currency is passed" do
188
- subject(:hash){ { cents: 123 } }
185
+ context 'when no currency is passed' do
186
+ subject(:hash) { {cents: 123} }
189
187
 
190
- before { allow(Money).to receive(:default_currency).and_return("USD") }
188
+ before { allow(Money).to receive(:default_currency).and_return('USD') }
191
189
 
192
- it "converts Hash to Money using default value" do
193
- expect(hash.to_money("USD")).to eq(Money.new(123, "USD"))
190
+ it 'converts Hash to Money using default value' do
191
+ expect(hash.to_money('USD')).to eq(Money.new(123, 'USD'))
194
192
  end
195
193
  end
196
-
197
194
  end
198
195
  end
199
196
 
200
197
  describe Symbol do
201
- describe "#to_currency" do
202
- it "converts Symbol to Currency" do
203
- expect(:usd.to_currency).to eq Money::Currency.new("USD")
204
- expect(:ars.to_currency).to eq Money::Currency.new("ARS")
198
+ describe '#to_currency' do
199
+ it 'converts Symbol to Currency' do
200
+ expect(:usd.to_currency).to eq Money::Currency.new('USD')
201
+ expect(:ars.to_currency).to eq Money::Currency.new('ARS')
205
202
  end
206
203
 
207
- it "is case-insensitive" do
208
- expect(:EUR.to_currency).to eq Money::Currency.new("EUR")
204
+ it 'is case-insensitive' do
205
+ expect(:EUR.to_currency).to eq Money::Currency.new('EUR')
209
206
  end
210
207
 
211
- it "raises Money::Currency::UnknownCurrency with unknown Currency" do
208
+ it 'raises Money::Currency::UnknownCurrency with unknown Currency' do
212
209
  expect { :XXX.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
213
210
  expect { :" ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
214
211
  end
@@ -1,26 +1,52 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "spec_helper"
4
- require "monetize"
3
+ require 'spec_helper'
4
+ require 'monetize'
5
5
 
6
6
  describe Monetize do
7
-
8
- bar = '{ "priority": 1, "iso_code": "BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }'
9
- eu4 = '{ "priority": 1, "iso_code": "EU4", "iso_numeric": "841", "name": "Euro with 4 decimal places", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "€", "decimal_mark": ",", "thousands_separator": "." }'
10
-
11
- describe ".parse" do
12
-
13
- it "parses european-formatted inputs under 10EUR" do
7
+ bar = <<-JSON
8
+ {
9
+ "priority": 1,
10
+ "iso_code": "BAR",
11
+ "iso_numeric": "840",
12
+ "name": "Dollar with 4 decimal places",
13
+ "symbol": "$",
14
+ "subunit": "Cent",
15
+ "subunit_to_unit": 10000,
16
+ "symbol_first": true,
17
+ "html_entity": "$",
18
+ "decimal_mark": ".",
19
+ "thousands_separator": ","
20
+ }
21
+ JSON
22
+
23
+ eu4 = <<-JSON
24
+ {
25
+ "priority": 1,
26
+ "iso_code": "EU4",
27
+ "iso_numeric": "841",
28
+ "name": "Euro with 4 decimal places",
29
+ "symbol": "€",
30
+ "subunit": "Cent",
31
+ "subunit_to_unit": 10000,
32
+ "symbol_first": true,
33
+ "html_entity": "€",
34
+ "decimal_mark": ",",
35
+ "thousands_separator": "."
36
+ }
37
+ JSON
38
+
39
+ describe '.parse' do
40
+ it 'parses european-formatted inputs under 10EUR' do
14
41
  expect(Monetize.parse('EUR 5,95')).to eq Money.new(595, 'EUR')
15
42
  end
16
43
 
17
- it "parses european-formatted inputs with multiple thousands-seperators" do
18
- expect(Monetize.parse('EUR 1.234.567,89')).to eq Money.new(123456789, 'EUR')
19
- expect(Monetize.parse('EUR 1.111.234.567,89')).to eq Money.new(111123456789, 'EUR')
44
+ it 'parses european-formatted inputs with multiple thousands-seperators' do
45
+ expect(Monetize.parse('EUR 1.234.567,89')).to eq Money.new(1_234_567_89, 'EUR')
46
+ expect(Monetize.parse('EUR 1.111.234.567,89')).to eq Money.new(1_111_234_567_89, 'EUR')
20
47
  end
21
48
 
22
49
  describe 'currency detection' do
23
-
24
50
  context 'opted in' do
25
51
  before :all do
26
52
  Monetize.assume_from_symbol = true
@@ -30,69 +56,68 @@ describe Monetize do
30
56
  Monetize.assume_from_symbol = false
31
57
  end
32
58
 
33
- it "parses formatted inputs with Euros passed as a symbol" do
34
- expect(Monetize.parse("€5.95")).to eq Money.new(595, 'EUR')
59
+ it 'parses formatted inputs with Euros passed as a symbol' do
60
+ expect(Monetize.parse('€5.95')).to eq Money.new(595, 'EUR')
35
61
  end
36
62
 
37
- it "parses formatted inputs with Euros passed as a symbol with surrounding space" do
38
- expect(Monetize.parse(" €5.95 ")).to eq Money.new(595, 'EUR')
63
+ it 'parses formatted inputs with Euros passed as a symbol with surrounding space' do
64
+ expect(Monetize.parse(' €5.95 ')).to eq Money.new(595, 'EUR')
39
65
  end
40
66
 
41
- it "parses formatted inputs with British Pounds Sterling passed as a symbol" do
42
- expect(Monetize.parse("£9.99")).to eq Money.new(999, 'GBP')
67
+ it 'parses formatted inputs with British Pounds Sterling passed as a symbol' do
68
+ expect(Monetize.parse('£9.99')).to eq Money.new(999, 'GBP')
43
69
  end
44
70
 
45
- it "parses formatted inputs with British Pounds Sterling passed as a lira sign symbol" do
46
- expect(Monetize.parse("₤9.99")).to eq Money.new(999, 'GBP')
71
+ it 'parses formatted inputs with British Pounds Sterling passed as a lira sign symbol' do
72
+ expect(Monetize.parse('₤9.99')).to eq Money.new(999, 'GBP')
47
73
  end
48
74
 
49
- it "parses formatted inputs with South African Rand passed as a symbol" do
50
- expect(Monetize.parse("R9.99")).to eq Money.new(999, 'ZAR')
75
+ it 'parses formatted inputs with South African Rand passed as a symbol' do
76
+ expect(Monetize.parse('R9.99')).to eq Money.new(999, 'ZAR')
51
77
  end
52
78
 
53
- it "parses formatted inputs with Brazilian real passed as a symbol" do
54
- expect(Monetize.parse("R$R9.99")).to eq Money.new(999, 'BRL')
79
+ it 'parses formatted inputs with Brazilian real passed as a symbol' do
80
+ expect(Monetize.parse('R$R9.99')).to eq Money.new(999, 'BRL')
55
81
  end
56
82
 
57
- it "parses formatted inputs with Japanese Yen passed as a symbol" do
58
- expect(Monetize.parse("¥999")).to eq Money.new(999, 'JPY')
83
+ it 'parses formatted inputs with Japanese Yen passed as a symbol' do
84
+ expect(Monetize.parse('¥999')).to eq Money.new(999, 'JPY')
59
85
  end
60
86
 
61
- it "parses formatted inputs with Canadian Dollar passed as a symbol" do
62
- expect(Monetize.parse("C$9.99")).to eq Money.new(999, 'CAD')
87
+ it 'parses formatted inputs with Canadian Dollar passed as a symbol' do
88
+ expect(Monetize.parse('C$9.99')).to eq Money.new(999, 'CAD')
63
89
  end
64
90
 
65
91
  it 'should assume default currency if not a recognised symbol' do
66
- expect(Monetize.parse("L9.99")).to eq Money.new(999, 'USD')
92
+ expect(Monetize.parse('L9.99')).to eq Money.new(999, 'USD')
67
93
  end
68
94
 
69
95
  it 'parses formatted inputs without currency detection when overridden' do
70
- expect(Monetize.parse("£9.99", nil, assume_from_symbol: false)).to eq Money.new(999, 'USD')
96
+ expect(Monetize.parse('£9.99', nil, assume_from_symbol: false)).to eq Money.new(999, 'USD')
71
97
  end
72
98
 
73
99
  it 'parses formatted inputs with minus sign and currency symbol' do
74
- expect(Monetize.parse("-€9.99")).to eq Money.new(-999, 'EUR')
75
- expect(Monetize.parse("-£9.99")).to eq Money.new(-999, 'GBP')
76
- expect(Monetize.parse("-R$R9.99")).to eq Money.new(-999, 'BRL')
77
- expect(Monetize.parse("-¥999")).to eq Money.new(-999, 'JPY')
78
- expect(Monetize.parse("-C$9.99")).to eq Money.new(-999, 'CAD')
100
+ expect(Monetize.parse('-€9.99')).to eq Money.new(-999, 'EUR')
101
+ expect(Monetize.parse('-£9.99')).to eq Money.new(-999, 'GBP')
102
+ expect(Monetize.parse('-R$R9.99')).to eq Money.new(-999, 'BRL')
103
+ expect(Monetize.parse('-¥999')).to eq Money.new(-999, 'JPY')
104
+ expect(Monetize.parse('-C$9.99')).to eq Money.new(-999, 'CAD')
79
105
  end
80
106
 
81
107
  it 'parses formatted inputs with plus and GBP passed as symbol' do
82
- expect(Monetize.parse("+€9.99")).to eq Money.new(999, 'EUR')
83
- expect(Monetize.parse("+£9.99")).to eq Money.new(999, 'GBP')
84
- expect(Monetize.parse("+R$R9.99")).to eq Money.new(999, 'BRL')
85
- expect(Monetize.parse("+¥999")).to eq Money.new(999, 'JPY')
86
- expect(Monetize.parse("+C$9.99")).to eq Money.new(999, 'CAD')
87
-
108
+ expect(Monetize.parse('+€9.99')).to eq Money.new(999, 'EUR')
109
+ expect(Monetize.parse('+£9.99')).to eq Money.new(999, 'GBP')
110
+ expect(Monetize.parse('+R$R9.99')).to eq Money.new(999, 'BRL')
111
+ expect(Monetize.parse('+¥999')).to eq Money.new(999, 'JPY')
112
+ expect(Monetize.parse('+C$9.99')).to eq Money.new(999, 'CAD')
88
113
  end
89
114
 
90
115
  it 'parses formatted inputs with currency symbol and postfix minus sign' do
91
- expect(Monetize.parse("€9.99-")).to eq Money.new(-999, 'EUR')
116
+ expect(Monetize.parse('€9.99-')).to eq Money.new(-999, 'EUR')
92
117
  end
93
118
 
94
119
  it 'parses formatted inputs with currency symbol and postfix plus sign' do
95
- expect(Monetize.parse("€9.99+")).to eq Money.new(999, 'EUR')
120
+ expect(Monetize.parse('€9.99+')).to eq Money.new(999, 'EUR')
96
121
  end
97
122
 
98
123
  it 'parses formatted inputs with amounts given with suffixes' do
@@ -109,24 +134,24 @@ describe Monetize do
109
134
  Monetize.assume_from_symbol = false
110
135
  end
111
136
 
112
- it "ignores the Euro symbol" do
113
- expect(Monetize.parse("€5.95")).to eq Money.new(595, 'USD')
137
+ it 'ignores the Euro symbol' do
138
+ expect(Monetize.parse('€5.95')).to eq Money.new(595, 'USD')
114
139
  end
115
140
 
116
- it "ignores the South African Rand symbol" do
117
- expect(Monetize.parse("R5.95")).to eq Money.new(595, 'USD')
141
+ it 'ignores the South African Rand symbol' do
142
+ expect(Monetize.parse('R5.95')).to eq Money.new(595, 'USD')
118
143
  end
119
144
 
120
- it "ignores the Euro symbol with surrounding spaces" do
121
- expect(Monetize.parse(" €5.95 ")).to eq Money.new(595, 'USD')
145
+ it 'ignores the Euro symbol with surrounding spaces' do
146
+ expect(Monetize.parse(' €5.95 ')).to eq Money.new(595, 'USD')
122
147
  end
123
148
 
124
- it "ignores the British Pounds Sterling symbol" do
125
- expect(Monetize.parse("£9.99")).to eq Money.new(999, 'USD')
149
+ it 'ignores the British Pounds Sterling symbol' do
150
+ expect(Monetize.parse('£9.99')).to eq Money.new(999, 'USD')
126
151
  end
127
152
 
128
153
  it 'parses formatted inputs with currency detection when overridden' do
129
- expect(Monetize.parse("£9.99", nil, assume_from_symbol: true)).to eq Money.new(999, 'GBP')
154
+ expect(Monetize.parse('£9.99', nil, assume_from_symbol: true)).to eq Money.new(999, 'GBP')
130
155
  end
131
156
  end
132
157
 
@@ -135,7 +160,7 @@ describe Monetize do
135
160
  end
136
161
  end
137
162
 
138
- it "parses USD-formatted inputs under $10" do
163
+ it 'parses USD-formatted inputs under $10' do
139
164
  five_ninety_five = Money.new(595, 'USD')
140
165
 
141
166
  expect(Monetize.parse(5.95)).to eq five_ninety_five
@@ -147,215 +172,223 @@ describe Monetize do
147
172
  expect(Monetize.parse('$5.95, each')).to eq five_ninety_five
148
173
  end
149
174
 
150
- it "parses USD-formatted inputs with multiple thousands-seperators" do
151
- expect(Monetize.parse('1,234,567.89')).to eq Money.new(123456789, 'USD')
152
- expect(Monetize.parse('1,111,234,567.89')).to eq Money.new(111123456789, 'USD')
175
+ it 'parses USD-formatted inputs with multiple thousands-seperators' do
176
+ expect(Monetize.parse('1,234,567.89')).to eq Money.new(1_234_567_89, 'USD')
177
+ expect(Monetize.parse('1,111,234,567.89')).to eq Money.new(1_111_234_567_89, 'USD')
153
178
  end
154
179
 
155
- it "does not return a price if there is a price range" do
180
+ it 'does not return a price if there is a price range' do
156
181
  expect { Monetize.parse('$5.95-10.95') }.to raise_error ArgumentError
157
182
  expect { Monetize.parse('$5.95 - 10.95') }.to raise_error ArgumentError
158
183
  expect { Monetize.parse('$5.95 - $10.95') }.to raise_error ArgumentError
159
184
  end
160
185
 
161
- it "does not return a price for completely invalid input" do
186
+ it 'does not return a price for completely invalid input' do
162
187
  expect(Monetize.parse(nil)).to eq Money.empty
163
188
  expect(Monetize.parse('hellothere')).to eq Money.empty
164
189
  expect(Monetize.parse('')).to eq Money.empty
165
190
  end
166
191
 
167
- it "handles negative inputs" do
192
+ it 'handles negative inputs' do
168
193
  five_ninety_five = Money.new(-595, 'USD')
169
194
 
170
- expect(Monetize.parse("$-5.95")).to eq five_ninety_five
171
- expect(Monetize.parse("-$5.95")).to eq five_ninety_five
172
- expect(Monetize.parse("$5.95-")).to eq five_ninety_five
195
+ expect(Monetize.parse('$-5.95')).to eq five_ninety_five
196
+ expect(Monetize.parse('-$5.95')).to eq five_ninety_five
197
+ expect(Monetize.parse('$5.95-')).to eq five_ninety_five
173
198
  end
174
199
 
175
- it "raises ArgumentError when unable to detect polarity" do
200
+ it 'raises ArgumentError when unable to detect polarity' do
176
201
  expect { Monetize.parse('-$5.95-') }.to raise_error ArgumentError
177
202
  end
178
203
 
179
- it "parses correctly strings with exactly 3 decimal digits" do
180
- expect(Monetize.parse("6,534", "EUR")).to eq Money.new(653, "EUR")
204
+ it 'parses correctly strings with exactly 3 decimal digits' do
205
+ expect(Monetize.parse('6,534', 'EUR')).to eq Money.new(653, 'EUR')
206
+ expect(Monetize.parse('6.534', 'EUR')).to eq Money.new(653, 'EUR')
207
+
208
+ Monetize.enforce_currency_delimiters = true
209
+ expect(Monetize.parse('6.534', 'EUR')).to eq Money.new(6_534_00, 'EUR')
210
+ Monetize.enforce_currency_delimiters = false
181
211
  end
182
212
 
183
- context "custom currencies with 4 decimal places" do
213
+ context 'custom currencies with 4 decimal places' do
184
214
  before :each do
185
- Money::Currency.register(JSON.parse(bar, :symbolize_names => true))
186
- Money::Currency.register(JSON.parse(eu4, :symbolize_names => true))
215
+ Money::Currency.register(JSON.parse(bar, symbolize_names: true))
216
+ Money::Currency.register(JSON.parse(eu4, symbolize_names: true))
187
217
  end
188
218
 
189
219
  after :each do
190
- Money::Currency.unregister(JSON.parse(bar, :symbolize_names => true))
191
- Money::Currency.unregister(JSON.parse(eu4, :symbolize_names => true))
220
+ Money::Currency.unregister(JSON.parse(bar, symbolize_names: true))
221
+ Money::Currency.unregister(JSON.parse(eu4, symbolize_names: true))
192
222
  end
193
223
 
194
224
  # String#to_money(Currency) is equivalent to Monetize.parse(String, Currency)
195
- it "parses strings respecting subunit to unit, decimal and thousands separator" do
196
- expect("$0.4".to_money("BAR")).to eq Money.new(4000, "BAR")
197
- expect("€0,4".to_money("EU4")).to eq Money.new(4000, "EU4")
225
+ it 'parses strings respecting subunit to unit, decimal and thousands separator' do
226
+ expect('$0.4'.to_money('BAR')).to eq Money.new(4000, 'BAR')
227
+ expect('€0,4'.to_money('EU4')).to eq Money.new(4000, 'EU4')
198
228
 
199
- expect("$0.04".to_money("BAR")).to eq Money.new(400, "BAR")
200
- expect("€0,04".to_money("EU4")).to eq Money.new(400, "EU4")
229
+ expect('$0.04'.to_money('BAR')).to eq Money.new(400, 'BAR')
230
+ expect('€0,04'.to_money('EU4')).to eq Money.new(400, 'EU4')
201
231
 
202
- expect("$0.004".to_money("BAR")).to eq Money.new(40, "BAR")
203
- expect("€0,004".to_money("EU4")).to eq Money.new(40, "EU4")
232
+ expect('$0.004'.to_money('BAR')).to eq Money.new(40, 'BAR')
233
+ expect('€0,004'.to_money('EU4')).to eq Money.new(40, 'EU4')
204
234
 
205
- expect("$0.0004".to_money("BAR")).to eq Money.new(4, "BAR")
206
- expect("€0,0004".to_money("EU4")).to eq Money.new(4, "EU4")
235
+ expect('$0.0004'.to_money('BAR')).to eq Money.new(4, 'BAR')
236
+ expect('€0,0004'.to_money('EU4')).to eq Money.new(4, 'EU4')
207
237
 
208
- expect("$0.0024".to_money("BAR")).to eq Money.new(24, "BAR")
209
- expect("€0,0024".to_money("EU4")).to eq Money.new(24, "EU4")
238
+ expect('$0.0024'.to_money('BAR')).to eq Money.new(24, 'BAR')
239
+ expect('€0,0024'.to_money('EU4')).to eq Money.new(24, 'EU4')
210
240
 
211
- expect("$0.0324".to_money("BAR")).to eq Money.new(324, "BAR")
212
- expect("€0,0324".to_money("EU4")).to eq Money.new(324, "EU4")
241
+ expect('$0.0324'.to_money('BAR')).to eq Money.new(324, 'BAR')
242
+ expect('€0,0324'.to_money('EU4')).to eq Money.new(324, 'EU4')
213
243
 
214
- expect("$0.5324".to_money("BAR")).to eq Money.new(5324, "BAR")
215
- expect("€0,5324".to_money("EU4")).to eq Money.new(5324, "EU4")
244
+ expect('$0.5324'.to_money('BAR')).to eq Money.new(5324, 'BAR')
245
+ expect('€0,5324'.to_money('EU4')).to eq Money.new(5324, 'EU4')
216
246
 
217
- expect("$6.5324".to_money("BAR")).to eq Money.new(65324, "BAR")
218
- expect("€6,5324".to_money("EU4")).to eq Money.new(65324, "EU4")
247
+ # Following currencies consider 4 decimal places
248
+ # rubocop:disable Style/NumericLiterals
249
+ expect('$6.5324'.to_money('BAR')).to eq Money.new(6_5324, 'BAR')
250
+ expect('€6,5324'.to_money('EU4')).to eq Money.new(6_5324, 'EU4')
219
251
 
220
- expect("$86.5324".to_money("BAR")).to eq Money.new(865324, "BAR")
221
- expect("€86,5324".to_money("EU4")).to eq Money.new(865324, "EU4")
252
+ expect('$86.5324'.to_money('BAR')).to eq Money.new(86_5324, 'BAR')
253
+ expect('€86,5324'.to_money('EU4')).to eq Money.new(86_5324, 'EU4')
222
254
 
223
- expect("$186.5324".to_money("BAR")).to eq Money.new(1865324, "BAR")
224
- expect("€186,5324".to_money("EU4")).to eq Money.new(1865324, "EU4")
255
+ expect('$186.5324'.to_money('BAR')).to eq Money.new(186_5324, 'BAR')
256
+ expect('€186,5324'.to_money('EU4')).to eq Money.new(186_5324, 'EU4')
225
257
 
226
- expect("$3,331.0034".to_money("BAR")).to eq Money.new(33310034, "BAR")
227
- expect("€3.331,0034".to_money("EU4")).to eq Money.new(33310034, "EU4")
258
+ expect('$3,331.0034'.to_money('BAR')).to eq Money.new(3_331_0034, 'BAR')
259
+ expect('€3.331,0034'.to_money('EU4')).to eq Money.new(3_331_0034, 'EU4')
228
260
 
229
- expect("$8,883,331.0034".to_money("BAR")).to eq Money.new(88833310034, "BAR")
230
- expect("€8.883.331,0034".to_money("EU4")).to eq Money.new(88833310034, "EU4")
261
+ expect('$8,883,331.0034'.to_money('BAR')).to eq Money.new(8_883_331_0034, 'BAR')
262
+ expect('€8.883.331,0034'.to_money('EU4')).to eq Money.new(8_883_331_0034, 'EU4')
263
+ # rubocop:enable Style/NumericLiterals
231
264
  end
232
265
  end
233
266
  end
234
267
 
235
- describe ".parse_collection" do
236
- it "parses into a Money::Collection" do
237
- expect(Monetize.parse_collection("$7")).to be_a Monetize::Collection
268
+ describe '.parse_collection' do
269
+ it 'parses into a Money::Collection' do
270
+ expect(Monetize.parse_collection('$7')).to be_a Monetize::Collection
238
271
  end
239
272
 
240
- it "parses comma separated values" do
241
- collection = Monetize.parse_collection("$5, $7")
242
- expect(collection.first).to eq Monetize.parse("$5")
243
- expect(collection.last).to eq Monetize.parse("$7")
273
+ it 'parses comma separated values' do
274
+ collection = Monetize.parse_collection('$5, $7')
275
+ expect(collection.first).to eq Monetize.parse('$5')
276
+ expect(collection.last).to eq Monetize.parse('$7')
244
277
  end
245
278
 
246
- it "parses slash separated values" do
247
- collection = Monetize.parse_collection("£4.50/€6")
248
- expect(collection.first).to eq Monetize.parse("£4.50")
249
- expect(collection.last).to eq Monetize.parse("€6")
279
+ it 'parses slash separated values' do
280
+ collection = Monetize.parse_collection('£4.50/€6')
281
+ expect(collection.first).to eq Monetize.parse('£4.50')
282
+ expect(collection.last).to eq Monetize.parse('€6')
250
283
  end
251
284
 
252
- it "parses hyphens as ranges" do
253
- collection = Monetize.parse_collection("$4 - $10")
254
- expect(collection.first).to eq Monetize.parse("$4")
255
- expect(collection.last).to eq Monetize.parse("$10")
285
+ it 'parses hyphens as ranges' do
286
+ collection = Monetize.parse_collection('$4 - $10')
287
+ expect(collection.first).to eq Monetize.parse('$4')
288
+ expect(collection.last).to eq Monetize.parse('$10')
256
289
  end
257
290
  end
258
291
 
259
- describe ".from_string" do
260
- it "converts given amount to cents" do
261
- expect(Monetize.from_string("1")).to eq Money.new(1_00)
262
- expect(Monetize.from_string("1")).to eq Money.new(1_00, "USD")
263
- expect(Monetize.from_string("1", "EUR")).to eq Money.new(1_00, "EUR")
292
+ describe '.from_string' do
293
+ it 'converts given amount to cents' do
294
+ expect(Monetize.from_string('1')).to eq Money.new(1_00)
295
+ expect(Monetize.from_string('1')).to eq Money.new(1_00, 'USD')
296
+ expect(Monetize.from_string('1', 'EUR')).to eq Money.new(1_00, 'EUR')
264
297
  end
265
298
 
266
- it "respects :subunit_to_unit currency property" do
267
- expect(Monetize.from_string("1", "USD")).to eq Money.new(1_00, "USD")
268
- expect(Monetize.from_string("1", "TND")).to eq Money.new(1_000, "TND")
269
- expect(Monetize.from_string("1", "JPY")).to eq Money.new(1, "JPY")
299
+ it 'respects :subunit_to_unit currency property' do
300
+ expect(Monetize.from_string('1', 'USD')).to eq Money.new(1_00, 'USD')
301
+ expect(Monetize.from_string('1', 'TND')).to eq Money.new(1_000, 'TND')
302
+ expect(Monetize.from_string('1', 'JPY')).to eq Money.new(1, 'JPY')
270
303
  end
271
304
 
272
- it "accepts a currency options" do
273
- m = Monetize.from_string("1")
305
+ it 'accepts a currency options' do
306
+ m = Monetize.from_string('1')
274
307
  expect(m.currency).to eq Money.default_currency
275
308
 
276
- m = Monetize.from_string("1", Money::Currency.wrap("EUR"))
277
- expect(m.currency).to eq Money::Currency.wrap("EUR")
309
+ m = Monetize.from_string('1', Money::Currency.wrap('EUR'))
310
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
278
311
 
279
- m = Monetize.from_string("1", "EUR")
280
- expect(m.currency).to eq Money::Currency.wrap("EUR")
312
+ m = Monetize.from_string('1', 'EUR')
313
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
281
314
  end
282
315
  end
283
316
 
284
- describe ".from_fixnum" do
285
- it "converts given amount to cents" do
317
+ describe '.from_fixnum' do
318
+ it 'converts given amount to cents' do
286
319
  expect(Monetize.from_fixnum(1)).to eq Money.new(1_00)
287
- expect(Monetize.from_fixnum(1)).to eq Money.new(1_00, "USD")
288
- expect(Monetize.from_fixnum(1, "EUR")).to eq Money.new(1_00, "EUR")
320
+ expect(Monetize.from_fixnum(1)).to eq Money.new(1_00, 'USD')
321
+ expect(Monetize.from_fixnum(1, 'EUR')).to eq Money.new(1_00, 'EUR')
289
322
  end
290
323
 
291
- it "should respect :subunit_to_unit currency property" do
292
- expect(Monetize.from_fixnum(1, "USD")).to eq Money.new(1_00, "USD")
293
- expect(Monetize.from_fixnum(1, "TND")).to eq Money.new(1_000, "TND")
294
- expect(Monetize.from_fixnum(1, "JPY")).to eq Money.new(1, "JPY")
324
+ it 'should respect :subunit_to_unit currency property' do
325
+ expect(Monetize.from_fixnum(1, 'USD')).to eq Money.new(1_00, 'USD')
326
+ expect(Monetize.from_fixnum(1, 'TND')).to eq Money.new(1_000, 'TND')
327
+ expect(Monetize.from_fixnum(1, 'JPY')).to eq Money.new(1, 'JPY')
295
328
  end
296
329
 
297
- it "accepts a currency options" do
330
+ it 'accepts a currency options' do
298
331
  m = Monetize.from_fixnum(1)
299
332
  expect(m.currency).to eq Money.default_currency
300
333
 
301
- m = Monetize.from_fixnum(1, Money::Currency.wrap("EUR"))
302
- expect(m.currency).to eq Money::Currency.wrap("EUR")
334
+ m = Monetize.from_fixnum(1, Money::Currency.wrap('EUR'))
335
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
303
336
 
304
- m = Monetize.from_fixnum(1, "EUR")
305
- expect(m.currency).to eq Money::Currency.wrap("EUR")
337
+ m = Monetize.from_fixnum(1, 'EUR')
338
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
306
339
  end
307
340
  end
308
341
 
309
- describe ".from_float" do
310
- it "converts given amount to cents" do
342
+ describe '.from_float' do
343
+ it 'converts given amount to cents' do
311
344
  expect(Monetize.from_float(1.2)).to eq Money.new(1_20)
312
- expect(Monetize.from_float(1.2)).to eq Money.new(1_20, "USD")
313
- expect(Monetize.from_float(1.2, "EUR")).to eq Money.new(1_20, "EUR")
345
+ expect(Monetize.from_float(1.2)).to eq Money.new(1_20, 'USD')
346
+ expect(Monetize.from_float(1.2, 'EUR')).to eq Money.new(1_20, 'EUR')
314
347
  end
315
348
 
316
- it "respects :subunit_to_unit currency property" do
317
- expect(Monetize.from_float(1.2, "USD")).to eq Money.new(1_20, "USD")
318
- expect(Monetize.from_float(1.2, "TND")).to eq Money.new(1_200, "TND")
319
- expect(Monetize.from_float(1.2, "JPY")).to eq Money.new(1, "JPY")
349
+ it 'respects :subunit_to_unit currency property' do
350
+ expect(Monetize.from_float(1.2, 'USD')).to eq Money.new(1_20, 'USD')
351
+ expect(Monetize.from_float(1.2, 'TND')).to eq Money.new(1_200, 'TND')
352
+ expect(Monetize.from_float(1.2, 'JPY')).to eq Money.new(1, 'JPY')
320
353
  end
321
354
 
322
- it "accepts a currency options" do
355
+ it 'accepts a currency options' do
323
356
  m = Monetize.from_float(1.2)
324
357
  expect(m.currency).to eq Money.default_currency
325
358
 
326
- m = Monetize.from_float(1.2, Money::Currency.wrap("EUR"))
327
- expect(m.currency).to eq Money::Currency.wrap("EUR")
359
+ m = Monetize.from_float(1.2, Money::Currency.wrap('EUR'))
360
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
328
361
 
329
- m = Monetize.from_float(1.2, "EUR")
330
- expect(m.currency).to eq Money::Currency.wrap("EUR")
362
+ m = Monetize.from_float(1.2, 'EUR')
363
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
331
364
  end
332
365
  end
333
366
 
334
- describe ".from_bigdecimal" do
335
- it "converts given amount to cents" do
336
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"))).to eq Money.new(1_00)
337
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"))).to eq Money.new(1_00, "USD")
338
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"), "EUR")).to eq Money.new(1_00, "EUR")
367
+ describe '.from_bigdecimal' do
368
+ it 'converts given amount to cents' do
369
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(1_00)
370
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(1_00, 'USD')
371
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'EUR')).to eq Money.new(1_00, 'EUR')
339
372
  end
340
373
 
341
- it "respects :subunit_to_unit currency property" do
342
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"), "USD")).to eq Money.new(1_00, "USD")
343
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"), "TND")).to eq Money.new(1_000, "TND")
344
- expect(Monetize.from_bigdecimal(BigDecimal.new("1"), "JPY")).to eq Money.new(1, "JPY")
374
+ it 'respects :subunit_to_unit currency property' do
375
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'USD')).to eq Money.new(1_00, 'USD')
376
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'TND')).to eq Money.new(1_000, 'TND')
377
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'), 'JPY')).to eq Money.new(1, 'JPY')
345
378
  end
346
379
 
347
- it "accepts a currency options" do
348
- m = Monetize.from_bigdecimal(BigDecimal.new("1"))
380
+ it 'accepts a currency options' do
381
+ m = Monetize.from_bigdecimal(BigDecimal.new('1'))
349
382
  expect(m.currency).to eq Money.default_currency
350
383
 
351
- m = Monetize.from_bigdecimal(BigDecimal.new("1"), Money::Currency.wrap("EUR"))
352
- expect(m.currency).to eq Money::Currency.wrap("EUR")
384
+ m = Monetize.from_bigdecimal(BigDecimal.new('1'), Money::Currency.wrap('EUR'))
385
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
353
386
 
354
- m = Monetize.from_bigdecimal(BigDecimal.new("1"), "EUR")
355
- expect(m.currency).to eq Money::Currency.wrap("EUR")
387
+ m = Monetize.from_bigdecimal(BigDecimal.new('1'), 'EUR')
388
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
356
389
  end
357
390
 
358
- context "infinite_precision = true" do
391
+ context 'infinite_precision = true' do
359
392
  before do
360
393
  Money.infinite_precision = true
361
394
  end
@@ -364,66 +397,74 @@ describe Monetize do
364
397
  Money.infinite_precision = false
365
398
  end
366
399
 
367
- it "keeps precision" do
368
- expect(Monetize.from_bigdecimal(BigDecimal.new("1.23456"))).to eq Money.new(123.456)
369
- expect(Monetize.from_bigdecimal(BigDecimal.new("-1.23456"))).to eq Money.new(-123.456)
370
- expect(Monetize.from_bigdecimal(BigDecimal.new("1.23456"))).to eq Money.new(123.456, "USD")
371
- expect(Monetize.from_bigdecimal(BigDecimal.new("1.23456"), "EUR")).to eq Money.new(123.456, "EUR")
400
+ it 'keeps precision' do
401
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1'))).to eq Money.new(100)
402
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'))).to eq Money.new(123.456)
403
+ expect(Monetize.from_bigdecimal(BigDecimal.new('-1.23456'))).to eq Money.new(-123.456)
404
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'))).to eq Money.new(123.456, 'USD')
405
+ expect(Monetize.from_bigdecimal(BigDecimal.new('1.23456'), 'EUR')).to eq Money.new(123.456, 'EUR')
406
+
407
+ expect('1'.to_money).to eq Money.new(100)
408
+ expect('1.23456'.to_money).to eq Money.new(123.456)
409
+ expect('-1.23456'.to_money).to eq Money.new(-123.456)
410
+ expect('$1.23456'.to_money).to eq Money.new(123.456, 'USD')
411
+ expect('1.23456 EUR'.to_money).to eq Money.new(123.456, 'EUR')
372
412
  end
373
413
  end
374
414
  end
375
415
 
376
- describe ".from_numeric" do
377
- it "converts given amount to cents" do
416
+ describe '.from_numeric' do
417
+ it 'converts given amount to cents' do
378
418
  expect(Monetize.from_numeric(1)).to eq Money.new(1_00)
379
419
  expect(Monetize.from_numeric(1.0)).to eq Money.new(1_00)
380
- expect(Monetize.from_numeric(BigDecimal.new("1"))).to eq Money.new(1_00)
420
+ expect(Monetize.from_numeric(BigDecimal.new('1'))).to eq Money.new(1_00)
381
421
  end
382
422
 
383
- it "raises ArgumentError with unsupported argument" do
384
- expect { Monetize.from_numeric("100") }.to raise_error(ArgumentError)
423
+ it 'raises ArgumentError with unsupported argument' do
424
+ expect { Monetize.from_numeric('100') }.to raise_error(ArgumentError)
385
425
  end
386
426
 
387
- it "optimizes workload" do
388
- expect(Monetize).to receive(:from_fixnum).with(1, "USD").and_return(Money.new(1_00, "USD"))
389
- expect(Monetize.from_numeric(1, "USD")).to eq Money.new(1_00, "USD")
390
- expect(Monetize).to receive(:from_bigdecimal).with(BigDecimal.new("1.0"), "USD").and_return(Money.new(1_00, "USD"))
391
- expect(Monetize.from_numeric(1.0, "USD")).to eq Money.new(1_00, "USD")
427
+ it 'optimizes workload' do
428
+ expect(Monetize).to receive(:from_fixnum).with(1, 'USD').and_return(Money.new(1_00, 'USD'))
429
+ expect(Monetize.from_numeric(1, 'USD')).to eq Money.new(1_00, 'USD')
430
+ expect(Monetize).to receive(:from_bigdecimal).with(BigDecimal.new('1.0'), 'USD').
431
+ and_return(Money.new(1_00, 'USD'))
432
+ expect(Monetize.from_numeric(1.0, 'USD')).to eq Money.new(1_00, 'USD')
392
433
  end
393
434
 
394
- it "respects :subunit_to_unit currency property" do
395
- expect(Monetize.from_numeric(1, "USD")).to eq Money.new(1_00, "USD")
396
- expect(Monetize.from_numeric(1, "TND")).to eq Money.new(1_000, "TND")
397
- expect(Monetize.from_numeric(1, "JPY")).to eq Money.new(1, "JPY")
435
+ it 'respects :subunit_to_unit currency property' do
436
+ expect(Monetize.from_numeric(1, 'USD')).to eq Money.new(1_00, 'USD')
437
+ expect(Monetize.from_numeric(1, 'TND')).to eq Money.new(1_000, 'TND')
438
+ expect(Monetize.from_numeric(1, 'JPY')).to eq Money.new(1, 'JPY')
398
439
  end
399
440
 
400
- it "accepts a bank option" do
441
+ it 'accepts a bank option' do
401
442
  expect(Monetize.from_numeric(1)).to eq Money.new(1_00)
402
- expect(Monetize.from_numeric(1)).to eq Money.new(1_00, "USD")
403
- expect(Monetize.from_numeric(1, "EUR")).to eq Money.new(1_00, "EUR")
443
+ expect(Monetize.from_numeric(1)).to eq Money.new(1_00, 'USD')
444
+ expect(Monetize.from_numeric(1, 'EUR')).to eq Money.new(1_00, 'EUR')
404
445
  end
405
446
 
406
- it "accepts a currency options" do
447
+ it 'accepts a currency options' do
407
448
  m = Monetize.from_numeric(1)
408
449
  expect(m.currency).to eq Money.default_currency
409
450
 
410
- m = Monetize.from_numeric(1, Money::Currency.wrap("EUR"))
411
- expect(m.currency).to eq Money::Currency.wrap("EUR")
451
+ m = Monetize.from_numeric(1, Money::Currency.wrap('EUR'))
452
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
412
453
 
413
- m = Monetize.from_numeric(1, "EUR")
414
- expect(m.currency).to eq Money::Currency.wrap("EUR")
454
+ m = Monetize.from_numeric(1, 'EUR')
455
+ expect(m.currency).to eq Money::Currency.wrap('EUR')
415
456
  end
416
457
  end
417
458
 
418
- describe ".extract_cents" do
459
+ describe '.extract_cents' do
419
460
  it "correctly treats pipe marks '|' in input (regression test)" do
420
461
  expect(Monetize.extract_cents('100|0')).to eq Monetize.extract_cents('100!0')
421
462
  end
422
463
  end
423
464
 
424
- context "given the same inputs to .parse and .from_*" do
425
- it "gives the same results" do
426
- expect(4.635.to_money).to eq "4.635".to_money
465
+ context 'given the same inputs to .parse and .from_*' do
466
+ it 'gives the same results' do
467
+ expect(4.635.to_money).to eq '4.635'.to_money
427
468
  end
428
469
  end
429
470
  end