money 5.1.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## 5.1.0
3
+ ## 5.1.1
4
+
5
+ - Added :sign_before_symbol option to format negative numbers as -£1 rather than £-1
6
+ - Ensure BigDecimal.new always receives a string - compatibility fix for ruby-1.9.2-p320
7
+ - Update Maldivian Currency to MVR and fix ރ. to be ރ
8
+ - Add exponent to currency
9
+ - Add find_numeric to find currencies by ISO 4217 numeric code.
10
+ - Fixed regression where thousands separator was missing on certain currencies. (GH-245)
11
+ - Added :symbol_before_without_space option to add a space between currency symbol and amount.
12
+
13
+ ## 5.1.0
4
14
 
5
15
  - Fix currency assumption when parsing $ with a non-USD default currency.
6
16
  - Changed the Bulgarian lev symbol position from before the amount to after the amount.
@@ -35,7 +45,7 @@
35
45
 
36
46
  ## 5.0.0
37
47
 
38
- - Minor bugfix - incorrect use of character range resulted in
48
+ - Minor bugfix - incorrect use of character range resulted in
39
49
  botched results for Money::Parsing#extract_cents (GH-162)
40
50
  - Money::Currency::TABLE removed. Use Money::Currency.register to add
41
51
  additional currencies (GH-143)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RubyMoney - Money
2
2
 
3
- [![Build Status](http://travis-ci.org/RubyMoney/money.png)](http://travis-ci.org/RubyMoney/money)
3
+ [![Gem Version](https://badge.fury.io/rb/money.png)](http://badge.fury.io/rb/money) [![Build Status](https://travis-ci.org/RubyMoney/money.png?branch=master)](https://travis-ci.org/RubyMoney/money) [![Code Climate](https://codeclimate.com/github/RubyMoney/money.png)](https://codeclimate.com/github/RubyMoney/money)
4
4
 
5
5
  ## Contributing
6
6
 
@@ -186,6 +186,27 @@ Money.default_currency = Money::Currency.new("CAD")
186
186
 
187
187
  If you use Rails, then `environment.rb` is a very good place to put this.
188
188
 
189
+ ### Currency Exponent
190
+
191
+ The exponent of a money value is the number of digits after the decimal
192
+ separator (which separates the major unit from the minor unit). See e.g.
193
+ [Wikipedia on ISO 4217](http://en.wikipedia.org/wiki/ISO_4217) for more
194
+ information. You can find the exponent (as a `Float`) by
195
+
196
+ ``` ruby
197
+ Money::Currency.new("USD").exponent # => 2.0
198
+ Money::Currency.new("JPY").exponent # => 0.0
199
+ Money::Currency.new("MGA").exponent # => 0.6989700043360189
200
+ ```
201
+
202
+ ### Currency Lookup
203
+
204
+ To find a given currency by ISO 4217 numeric code (three digits) you can do
205
+
206
+ ``` ruby
207
+ Money::Currency.find_by_iso_numeric(978) #=> Money::Currency.new(:eur)
208
+ ```
209
+
189
210
  ## Currency Exchange
190
211
 
191
212
  Exchanging money is performed through an exchange bank object. The default
@@ -233,4 +254,4 @@ implementations.
233
254
 
234
255
  To integrate money in a Rails application use [money-rails](http://github.com/RubyMoney/money-rails).
235
256
 
236
- For depreceated methods of integrating with Rails, check [the wiki](https://github.com/RubyMoney/money/wiki).
257
+ For depreceated methods of integrating with Rails, check [the wiki](https://github.com/RubyMoney/money/wiki).
@@ -1318,8 +1318,8 @@
1318
1318
  "priority": 100,
1319
1319
  "iso_code": "MVR",
1320
1320
  "name": "Maldivian Rufiyaa",
1321
- "symbol": "ރ.",
1322
- "alternate_symbols": ["MRF", "Rf", "MVR", "/-"],
1321
+ "symbol": "MVR",
1322
+ "alternate_symbols": ["MRF", "Rf", "/-", "ރ"],
1323
1323
  "subunit": "Laari",
1324
1324
  "subunit_to_unit": 100,
1325
1325
  "symbol_first": false,
@@ -35,6 +35,23 @@ class Money
35
35
  new(id) if self.table[id]
36
36
  end
37
37
 
38
+ # Lookup a currency with given +num+ as an ISO 4217 numeric and returns an
39
+ # +Currency+ instance on success, +nil+ otherwise.
40
+ #
41
+ # @param [#to_s] num used to look into +table+ in +iso_numeric+ and find
42
+ # the right currency id.
43
+ #
44
+ # @return [Money::Currency]
45
+ #
46
+ # @example
47
+ # Money::Currency.find_by_iso_numeric(978) #=> #<Money::Currency id: eur ...>
48
+ # Money::Currency.find_by_iso_numeric('001') #=> nil
49
+ def find_by_iso_numeric(num)
50
+ num = num.to_s
51
+ id, garbage = self.table.find{|key, currency| currency[:iso_numeric] == num}
52
+ new(id) if self.table[id]
53
+ end
54
+
38
55
  # Wraps the object in a +Currency+ unless it's already a +Currency+
39
56
  # object.
40
57
  #
@@ -139,6 +156,11 @@ class Money
139
156
  # @return [Integer]
140
157
  attr_reader :subunit_to_unit
141
158
 
159
+ # The number of digits after the decimal separator.
160
+ #
161
+ # @return [Float]
162
+ attr_reader :exponent
163
+
142
164
  # The decimal mark, or character used to separate the whole unit from the subunit.
143
165
  #
144
166
  # @return [String]
@@ -244,7 +266,7 @@ class Money
244
266
  # @example
245
267
  # Money::Currency.new(:usd) #=> #<Currency id: usd ...>
246
268
  def inspect
247
- "#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}>"
269
+ "#<#{self.class.name} id: #{id}, priority: #{priority}, symbol_first: #{symbol_first}, thousands_separator: #{thousands_separator}, html_entity: #{html_entity}, decimal_mark: #{decimal_mark}, name: #{name}, symbol: #{symbol}, subunit_to_unit: #{subunit_to_unit}, exponent: #{exponent}, iso_code: #{iso_code}, iso_numeric: #{iso_numeric}, subunit: #{subunit}>"
248
270
  end
249
271
 
250
272
  # Returns a string representation corresponding to the upcase +id+
@@ -281,6 +303,13 @@ class Money
281
303
  !!@symbol_first
282
304
  end
283
305
 
306
+ # Returns the number of digits after the decimal separator.
307
+ #
308
+ # @return [Float]
309
+ def exponent
310
+ Math.log10(@subunit_to_unit)
311
+ end
312
+
284
313
  # Cache decimal places for subunit_to_unit values. Common ones pre-cached.
285
314
  def self.decimal_places_cache
286
315
  @decimal_places_cache ||= {
@@ -25,7 +25,11 @@ class Money
25
25
  if self.class.infinite_precision
26
26
  @fractional
27
27
  else
28
- @fractional.round(0, self.class.rounding_mode).to_i
28
+ # If the Money object is created from a serialized YAML string,
29
+ # @fractional can end up being set to a Float. We need to ensure
30
+ # it is BigDecimal before calling #round with two paramers.
31
+ # Float class only provides #round with 0 or 1 parameter.
32
+ BigDecimal.new(@fractional.to_s, 0).round(0, self.class.rounding_mode).to_i
29
33
  end
30
34
  end
31
35
 
@@ -111,6 +111,33 @@ class Money
111
111
  # Money.new(10000000, "INR").format(:south_asian_number_formatting => true) #=> "1,00,000.00"
112
112
  # Money.new(10000000).format(:south_asian_number_formatting => true) #=> "$1,00,000.00"
113
113
  #
114
+ # @option *rules [Boolean, nil] :symbol_before_without_space (true) Whether
115
+ # a space between the money symbol and the amount should be inserted when
116
+ # +:symbol_position+ is +:before+. The default is true (meaning no space). Ignored
117
+ # if +:symbol+ is false or +:symbol_position+ is not +:before+.
118
+ #
119
+ # @example
120
+ # # Default is to not insert a space.
121
+ # Money.new(100, "USD").format #=> "$1.00"
122
+ #
123
+ # # Same thing.
124
+ # Money.new(100, "USD").format(:symbol_before_without_space => true) #=> "$1.00"
125
+ #
126
+ # # If set to false, will insert a space.
127
+ # Money.new(100, "USD").format(:symbol_before_without_space => false) #=> "$ 1.00"
128
+ #
129
+ # @option *rules [Boolean, nil] :symbol_after_without_space (false) Whether
130
+ # a space between the the amount and the money symbol should be inserted when
131
+ # +:symbol_position+ is +:after+. The default is false (meaning space). Ignored
132
+ # if +:symbol+ is false or +:symbol_position+ is not +:after+.
133
+ #
134
+ # @example
135
+ # # Default is to insert a space.
136
+ # Money.new(100, "USD").format(:symbol_position => :after) #=> "1.00 $"
137
+ #
138
+ # # If set to true, will not insert a space.
139
+ # Money.new(100, "USD").format(:symbol_position => :after, :symbol_after_without_space => true) #=> "1.00$"
140
+ #
114
141
  # @option *rules [Boolean, String, nil] :decimal_mark (true) Whether the
115
142
  # currency should be separated by the specified character or '.'
116
143
  #
@@ -144,6 +171,15 @@ class Money
144
171
  # @example
145
172
  # s = Money.ca_dollar(570).format(:html => true, :with_currency => true)
146
173
  # s #=> "$5.70 <span class=\"currency\">CAD</span>"
174
+ #
175
+ # @option *rules [Boolean] :sign_before_symbol (false) Whether the sign should be
176
+ # before the currency symbol.
177
+ #
178
+ # @example
179
+ # # You can specify to display the sign before the symbol for negative numbers
180
+ # Money.new(-100, "GBP").format(:sign_before_symbol => true) #=> "-£1.00"
181
+ # Money.new(-100, "GBP").format(:sign_before_symbol => false) #=> "£-1.00"
182
+ # Money.new(-100, "GBP").format #=> "£-1.00"
147
183
  def format(*rules)
148
184
  # support for old format parameters
149
185
  rules = normalize_formatting_rules(rules)
@@ -187,12 +223,19 @@ class Money
187
223
  :after
188
224
  end
189
225
 
226
+ sign = ""
227
+ if rules[:sign_before_symbol] == true && self.negative?
228
+ formatted.tr!("-", "")
229
+ sign = "-"
230
+ end
231
+
190
232
  if symbol_value && !symbol_value.empty?
191
233
  formatted = if symbol_position == :before
192
- "#{symbol_value}#{formatted}"
234
+ symbol_space = rules[:symbol_before_without_space] === false ? " " : ""
235
+ "#{sign}#{symbol_value}#{symbol_space}#{formatted}"
193
236
  else
194
237
  symbol_space = rules[:symbol_after_without_space] ? "" : " "
195
- "#{formatted}#{symbol_space}#{symbol_value}"
238
+ "#{sign}#{formatted}#{symbol_space}#{symbol_value}"
196
239
  end
197
240
  end
198
241
 
@@ -208,7 +251,8 @@ class Money
208
251
  end
209
252
 
210
253
  # Apply thousands_separator
211
- formatted.gsub!(regexp_format(formatted, rules, decimal_mark), "\\1#{thousands_separator_value}")
254
+ formatted.gsub!(regexp_format(formatted, rules, decimal_mark, symbol_value),
255
+ "\\1#{thousands_separator_value}")
212
256
 
213
257
  if rules[:with_currency]
214
258
  formatted << " "
@@ -244,12 +288,13 @@ class Money
244
288
  end
245
289
  end
246
290
 
247
- def regexp_format(formatted, rules, decimal_mark)
291
+ def regexp_format(formatted, rules, decimal_mark, symbol_value)
248
292
  regexp_decimal = Regexp.escape(decimal_mark)
249
293
  if rules[:south_asian_number_formatting]
250
294
  /(\d+?)(?=(\d\d)+(\d)(?:\.))/
251
295
  else
252
- if formatted =~ /#{regexp_decimal}/
296
+ # Symbols may contain decimal marks (E.g "դր.")
297
+ if formatted.sub(symbol_value, "") =~ /#{regexp_decimal}/
253
298
  /(\d)(?=(?:\d{3})+(?:#{regexp_decimal}))/
254
299
  else
255
300
  /(\d)(?=(?:\d{3})+(?:[^\d]{1}|$))/
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "money"
4
- s.version = "5.1.0"
4
+ s.version = "5.1.1"
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin",
7
7
  "Shane Emmons", "Simone Carletti"]
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_dependency "i18n", "~> 0.6.0"
17
17
 
18
- s.add_development_dependency "rspec", "~> 2.10.0"
18
+ s.add_development_dependency "rspec", "~> 2.11.0"
19
19
  s.add_development_dependency "yard", "~> 0.8.1"
20
- s.add_development_dependency "kramdown", "~> 0.13.7"
20
+ s.add_development_dependency "kramdown", "~> 0.14.0"
21
21
 
22
22
  s.files = Dir.glob("{config,lib,spec}/**/*")
23
23
  s.files += %w(CHANGELOG.md LICENSE README.md)
@@ -139,7 +139,7 @@ describe Money::Bank::VariableExchange do
139
139
 
140
140
  context "with unknown format" do
141
141
  it "raises Money::Bank::UnknownRateFormat" do
142
- expect { subject.export_rates(:foo)}.should raise_error Money::Bank::UnknownRateFormat
142
+ expect { subject.export_rates(:foo)}.to raise_error Money::Bank::UnknownRateFormat
143
143
  end
144
144
  end
145
145
 
@@ -184,7 +184,7 @@ describe Money::Bank::VariableExchange do
184
184
 
185
185
  context "with unknown format" do
186
186
  it "raises Money::Bank::UnknownRateFormat" do
187
- expect { subject.import_rates(:foo, "")}.should raise_error Money::Bank::UnknownRateFormat
187
+ expect { subject.import_rates(:foo, "")}.to raise_error Money::Bank::UnknownRateFormat
188
188
  end
189
189
  end
190
190
  end
@@ -214,13 +214,13 @@ describe Money::Bank::VariableExchange do
214
214
  end
215
215
 
216
216
  it "raises a Money::Currency::UnknownCurrency exception when an unknown currency is passed" do
217
- expect { subject.send(:rate_key_for, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
217
+ expect { subject.send(:rate_key_for, 'AAA', 'BBB')}.to raise_exception(Money::Currency::UnknownCurrency)
218
218
  end
219
219
  end
220
220
 
221
221
  describe "#marshal_dump" do
222
222
  it "does not raise an error" do
223
- expect { Marshal.dump(subject) }.should_not raise_error
223
+ expect { Marshal.dump(subject) }.to_not raise_error
224
224
  end
225
225
 
226
226
  it "works with Marshal.load" do
@@ -22,6 +22,27 @@ describe Money::Currency do
22
22
  end
23
23
  end
24
24
 
25
+ describe ".find_by_iso_numeric" do
26
+ it "returns currency matching given numeric code" do
27
+ Money::Currency.find_by_iso_numeric(978).should == Money::Currency.new(:eur)
28
+ Money::Currency.find_by_iso_numeric(208).should_not == Money::Currency.new(:eur)
29
+ Money::Currency.find_by_iso_numeric('840').should == Money::Currency.new(:usd)
30
+
31
+ class Mock
32
+ def to_s
33
+ '208'
34
+ end
35
+ end
36
+ Money::Currency.find_by_iso_numeric(Mock.new).should == Money::Currency.new(:dkk)
37
+ Money::Currency.find_by_iso_numeric(Mock.new).should_not == Money::Currency.new(:usd)
38
+ end
39
+
40
+ it "returns nil if no currency has the given numeric code" do
41
+ Money::Currency.find_by_iso_numeric('non iso 4217 numeric code').should == nil
42
+ Money::Currency.find_by_iso_numeric(0).should == nil
43
+ end
44
+ end
45
+
25
46
  describe ".wrap" do
26
47
  it "returns nil if object is nil" do
27
48
  Money::Currency.wrap(nil).should == nil
@@ -46,7 +67,7 @@ describe Money::Currency do
46
67
  end
47
68
 
48
69
  it "raises UnknownMoney::Currency with unknown currency" do
49
- lambda { Money::Currency.new("xxx") }.should raise_error(Money::Currency::UnknownCurrency, /xxx/)
70
+ expect { Money::Currency.new("xxx") }.to raise_error(Money::Currency::UnknownCurrency, /xxx/)
50
71
  end
51
72
  end
52
73
 
@@ -91,7 +112,7 @@ describe Money::Currency do
91
112
  describe "#inspect" do
92
113
  it "works as documented" do
93
114
  Money::Currency.new(:usd).inspect.should ==
94
- %Q{#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, iso_code: USD, iso_numeric: 840, subunit: Cent>}
115
+ %Q{#<Money::Currency id: usd, priority: 1, symbol_first: true, thousands_separator: ,, html_entity: $, decimal_mark: ., name: United States Dollar, symbol: $, subunit_to_unit: 100, exponent: 2.0, iso_code: USD, iso_numeric: 840, subunit: Cent>}
95
116
  end
96
117
  end
97
118
 
@@ -121,6 +142,14 @@ describe Money::Currency do
121
142
  end
122
143
  end
123
144
 
145
+ describe "#exponent" do
146
+ it "conforms to iso 4217" do
147
+ Money::Currency.new(:jpy).exponent == 0
148
+ Money::Currency.new(:usd).exponent == 2
149
+ Money::Currency.new(:iqd).exponent == 3
150
+ end
151
+ end
152
+
124
153
  describe "#decimal_places" do
125
154
  it "proper places for known currency" do
126
155
  Money::Currency.new(:mro).decimal_places == 1
@@ -156,10 +156,10 @@ describe Money do
156
156
 
157
157
  it "raises ArgumentError when used to compare with an object that doesn't respond to #to_money" do
158
158
  expected_message = /Comparison .+ failed/
159
- lambda{ Money.new(1_00) <=> Object.new }.should raise_error(ArgumentError, expected_message)
160
- lambda{ Money.new(1_00) <=> Class }.should raise_error(ArgumentError, expected_message)
161
- lambda{ Money.new(1_00) <=> Kernel }.should raise_error(ArgumentError, expected_message)
162
- lambda{ Money.new(1_00) <=> /foo/ }.should raise_error(ArgumentError, expected_message)
159
+ expect{ Money.new(1_00) <=> Object.new }.to raise_error(ArgumentError, expected_message)
160
+ expect{ Money.new(1_00) <=> Class }.to raise_error(ArgumentError, expected_message)
161
+ expect{ Money.new(1_00) <=> Kernel }.to raise_error(ArgumentError, expected_message)
162
+ expect{ Money.new(1_00) <=> /foo/ }.to raise_error(ArgumentError, expected_message)
163
163
  end
164
164
  end
165
165
 
@@ -229,11 +229,11 @@ describe Money do
229
229
  end
230
230
 
231
231
  it "does not multiply Money by Money (same currency)" do
232
- lambda { Money.new( 10, :USD) * Money.new( 4, :USD) }.should raise_error(ArgumentError)
232
+ expect { Money.new( 10, :USD) * Money.new( 4, :USD) }.to raise_error(ArgumentError)
233
233
  end
234
234
 
235
235
  it "does not multiply Money by Money (different currency)" do
236
- lambda { Money.new( 10, :USD) * Money.new( 4, :EUR) }.should raise_error(ArgumentError)
236
+ expect { Money.new( 10, :USD) * Money.new( 4, :EUR) }.to raise_error(ArgumentError)
237
237
  end
238
238
  end
239
239
 
@@ -165,6 +165,12 @@ describe Money, "formatting" do
165
165
  it "respects :subunit_to_unit currency property" do
166
166
  Money.new(10_00, "BHD").format(:no_cents => true).should == "ب.د1"
167
167
  end
168
+
169
+ it "inserts thousand separators if symbol contains decimal mark and no_cents is true" do
170
+ Money.new(100000000, "AMD").format(no_cents: true).should == "1,000,000 դր."
171
+ Money.new(100000000, "USD").format(no_cents: true).should == "$1,000,000"
172
+ Money.new(100000000, "RUB").format(no_cents: true).should == "1.000.000 р."
173
+ end
168
174
  end
169
175
 
170
176
  describe ":no_cents_if_whole option" do
@@ -343,6 +349,45 @@ describe Money, "formatting" do
343
349
  end
344
350
  end
345
351
 
352
+ describe ":sign_before_symbol option" do
353
+ specify "(:sign_before_symbol => true) works as documented" do
354
+ Money.us_dollar(-100000).format(:sign_before_symbol => true).should == "-$1,000.00"
355
+ end
356
+
357
+ specify "(:sign_before_symbol => false) works as documented" do
358
+ Money.us_dollar(-100000).format(:sign_before_symbol => false).should == "$-1,000.00"
359
+ Money.us_dollar(-100000).format(:sign_before_symbol => nil).should == "$-1,000.00"
360
+ end
361
+ end
362
+
363
+ describe ":symbol_before_without_space option" do
364
+ it "does not insert space between currency symbol and amount when set to true" do
365
+ Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => true).should == "€1.234.567,12"
366
+ end
367
+
368
+ it "inserts space between currency symbol and amount when set to false" do
369
+ Money.euro(1_234_567_12).format(:symbol_position => :before, :symbol_before_without_space => false).should == "€ 1.234.567,12"
370
+ end
371
+
372
+ it "defaults to true" do
373
+ Money.euro(1_234_567_12).format(:symbol_position => :before).should == "€1.234.567,12"
374
+ end
375
+ end
376
+
377
+ describe ":symbol_after_without_space option" do
378
+ it "does not insert space between amount and currency symbol when set to true" do
379
+ Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => true).should == "1.234.567,12€"
380
+ end
381
+
382
+ it "inserts space between amount and currency symbol when set to false" do
383
+ Money.euro(1_234_567_12).format(:symbol_position => :after, :symbol_after_without_space => false).should == "1.234.567,12 €"
384
+ end
385
+
386
+ it "defaults to false" do
387
+ Money.euro(1_234_567_12).format(:symbol_position => :after).should == "1.234.567,12 €"
388
+ end
389
+ end
390
+
346
391
  context "when the monetary value is 0" do
347
392
  let(:money) { Money.us_dollar(0) }
348
393
 
@@ -74,9 +74,9 @@ describe Money, "parsing" do
74
74
  end
75
75
 
76
76
  it "does not return a price if there is a price range" do
77
- lambda { Money.parse('$5.95-10.95') }.should raise_error ArgumentError
78
- lambda { Money.parse('$5.95 - 10.95') }.should raise_error ArgumentError
79
- lambda { Money.parse('$5.95 - $10.95') }.should raise_error ArgumentError
77
+ expect { Money.parse('$5.95-10.95') }.to raise_error ArgumentError
78
+ expect { Money.parse('$5.95 - 10.95') }.to raise_error ArgumentError
79
+ expect { Money.parse('$5.95 - $10.95') }.to raise_error ArgumentError
80
80
  end
81
81
 
82
82
  it "does not return a price for completely invalid input" do
@@ -98,7 +98,7 @@ describe Money, "parsing" do
98
98
  end
99
99
 
100
100
  it "raises ArgumentError when unable to detect polarity" do
101
- lambda { Money.parse('-$5.95-') }.should raise_error ArgumentError
101
+ expect { Money.parse('-$5.95-') }.to raise_error ArgumentError
102
102
  end
103
103
 
104
104
  it "parses correctly strings with exactly 3 decimal digits" do
@@ -260,7 +260,7 @@ describe Money, "parsing" do
260
260
  end
261
261
 
262
262
  it "raises ArgumentError with unsupported argument" do
263
- lambda { Money.from_numeric("100") }.should raise_error(ArgumentError)
263
+ expect { Money.from_numeric("100") }.to raise_error(ArgumentError)
264
264
  end
265
265
 
266
266
  it "optimizes workload" do
@@ -146,6 +146,36 @@ describe Money do
146
146
  m.fractional.should be_a(Fixnum)
147
147
  end
148
148
  end
149
+
150
+ context "loading a serialized Money via YAML" do
151
+ it "uses BigDecimal when rounding" do
152
+ serialized = <<YAML
153
+ !ruby/object:Money
154
+ fractional: 249.5
155
+ currency: !ruby/object:Money::Currency
156
+ id: :eur
157
+ priority: 2
158
+ iso_code: EUR
159
+ name: Euro
160
+ symbol: €
161
+ alternate_symbols: []
162
+ subunit: Cent
163
+ subunit_to_unit: 100
164
+ symbol_first: true
165
+ html_entity: ! '&#x20AC;'
166
+ decimal_mark: ! ','
167
+ thousands_separator: .
168
+ iso_numeric: '978'
169
+ mutex: !ruby/object:Mutex {}
170
+ last_updated: 2012-11-23 20:41:47.454438399 +02:00
171
+ YAML
172
+ m = YAML::load serialized
173
+ m.should be_a(Money)
174
+ m.class.infinite_precision.should == false
175
+ m.fractional.should == 250 # 249.5 rounded up
176
+ m.fractional.should be_a(Integer)
177
+ end
178
+ end
149
179
 
150
180
  context "user changes rounding_mode" do
151
181
  after do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-11-10 00:00:00.000000000 Z
16
+ date: 2013-02-20 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: i18n
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirements:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: 2.10.0
41
+ version: 2.11.0
42
42
  type: :development
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ~>
48
48
  - !ruby/object:Gem::Version
49
- version: 2.10.0
49
+ version: 2.11.0
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: yard
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ dependencies:
70
70
  requirements:
71
71
  - - ~>
72
72
  - !ruby/object:Gem::Version
73
- version: 0.13.7
73
+ version: 0.14.0
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
@@ -78,7 +78,7 @@ dependencies:
78
78
  requirements:
79
79
  - - ~>
80
80
  - !ruby/object:Gem::Version
81
- version: 0.13.7
81
+ version: 0.14.0
82
82
  description: This library aids one in handling money and different currencies.
83
83
  email:
84
84
  - semmons99+RubyMoney@gmail.com
@@ -86,30 +86,30 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
- - config/currency.json
90
89
  - config/currency_bc.json
91
- - lib/money/bank/base.rb
92
- - lib/money/bank/variable_exchange.rb
90
+ - config/currency.json
91
+ - lib/money.rb
92
+ - lib/money/money.rb
93
93
  - lib/money/core_extensions.rb
94
+ - lib/money/currency.rb
94
95
  - lib/money/currency/heuristics.rb
95
96
  - lib/money/currency/loader.rb
96
- - lib/money/currency.rb
97
- - lib/money/money/arithmetic.rb
98
97
  - lib/money/money/formatting.rb
98
+ - lib/money/money/arithmetic.rb
99
99
  - lib/money/money/parsing.rb
100
- - lib/money/money.rb
101
- - lib/money.rb
102
- - spec/bank/base_spec.rb
103
- - spec/bank/variable_exchange_spec.rb
104
- - spec/core_extensions_spec.rb
100
+ - lib/money/bank/variable_exchange.rb
101
+ - lib/money/bank/base.rb
102
+ - spec/money_spec.rb
103
+ - spec/spec_helper.rb
105
104
  - spec/currency/heuristics_spec.rb
106
105
  - spec/currency_spec.rb
107
106
  - spec/money/arithmetic_spec.rb
108
- - spec/money/formatting_spec.rb
109
107
  - spec/money/parsing_spec.rb
110
- - spec/money_spec.rb
111
- - spec/spec_helper.rb
108
+ - spec/money/formatting_spec.rb
112
109
  - spec/support/default_currency_helper.rb
110
+ - spec/bank/base_spec.rb
111
+ - spec/bank/variable_exchange_spec.rb
112
+ - spec/core_extensions_spec.rb
113
113
  - CHANGELOG.md
114
114
  - LICENSE
115
115
  - README.md
@@ -140,3 +140,4 @@ signing_key:
140
140
  specification_version: 3
141
141
  summary: Money and currency exchange support library.
142
142
  test_files: []
143
+ has_rdoc: