money 6.0.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHORS +1 -0
- data/CHANGELOG.md +5 -4
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/config/currency_iso.json +3 -3
- data/lib/money/bank/single_currency.rb +1 -1
- data/lib/money/money/arithmetic.rb +4 -17
- data/lib/money/money/formatting.rb +3 -1
- data/lib/money/money.rb +45 -64
- data/lib/money/version.rb +1 -1
- data/lib/money.rb +0 -4
- data/money.gemspec +0 -1
- data/spec/bank/single_currency_spec.rb +1 -1
- data/spec/money/arithmetic_spec.rb +0 -87
- data/spec/money/formatting_spec.rb +11 -9
- data/spec/money_spec.rb +50 -65
- data/spec/spec_helper.rb +2 -2
- metadata +3 -31
- data/lib/money/core_extensions/numeric.rb +0 -7
- data/lib/money/core_extensions/string.rb +0 -13
- data/lib/money/core_extensions/symbol.rb +0 -7
- data/lib/money/core_extensions.rb +0 -7
- data/lib/money/deprecations.rb +0 -15
- data/lib/money/money/parsing.rb +0 -46
- data/spec/core_extensions_spec.rb +0 -160
- data/spec/money/deprecations_spec.rb +0 -51
- data/spec/money/parsing_spec.rb +0 -333
- data/spec/support/default_currency_helper.rb +0 -13
data/spec/money_spec.rb
CHANGED
|
@@ -71,59 +71,6 @@ describe Money do
|
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
describe ".new_with_dollars" do
|
|
75
|
-
it "is synonym of #new_with_amount" do
|
|
76
|
-
MoneyExpectation = Class.new(Money)
|
|
77
|
-
def MoneyExpectation.new_with_amount *args
|
|
78
|
-
args
|
|
79
|
-
end
|
|
80
|
-
MoneyExpectation.new_with_dollars("expectation").should == ["expectation"]
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
describe ".new_with_amount" do
|
|
85
|
-
it "converts given amount to cents" do
|
|
86
|
-
Money.new_with_amount(1).should == Money.new(100)
|
|
87
|
-
Money.new_with_amount(1, "USD").should == Money.new(100, "USD")
|
|
88
|
-
Money.new_with_amount(1, "EUR").should == Money.new(100, "EUR")
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "respects :subunit_to_unit currency property" do
|
|
92
|
-
Money.new_with_amount(1, "USD").should == Money.new(1_00, "USD")
|
|
93
|
-
Money.new_with_amount(1, "TND").should == Money.new(1_000, "TND")
|
|
94
|
-
Money.new_with_amount(1, "CLP").should == Money.new(1, "CLP")
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "does not loose precision" do
|
|
98
|
-
Money.new_with_amount(1234).cents.should == 1234_00
|
|
99
|
-
Money.new_with_amount(100.37).cents.should == 100_37
|
|
100
|
-
Money.new_with_amount(BigDecimal.new('1234')).cents.should == 1234_00
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "accepts optional currency" do
|
|
104
|
-
m = Money.new_with_amount(1)
|
|
105
|
-
m.currency.should == Money.default_currency
|
|
106
|
-
|
|
107
|
-
m = Money.new_with_amount(1, Money::Currency.wrap("EUR"))
|
|
108
|
-
m.currency.should == Money::Currency.wrap("EUR")
|
|
109
|
-
|
|
110
|
-
m = Money.new_with_amount(1, "EUR")
|
|
111
|
-
m.currency.should == Money::Currency.wrap("EUR")
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "accepts optional bank" do
|
|
115
|
-
m = Money.new_with_amount(1)
|
|
116
|
-
m.bank.should == Money.default_bank
|
|
117
|
-
|
|
118
|
-
m = Money.new_with_amount(1, "EUR", bank = Object.new)
|
|
119
|
-
m.bank.should == bank
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "is associated to the singleton instance of Bank::VariableExchange by default" do
|
|
123
|
-
Money.new_with_amount(0).bank.should be(Money::Bank::VariableExchange.instance)
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
74
|
describe ".empty" do
|
|
128
75
|
it "creates a new Money object of 0 cents" do
|
|
129
76
|
Money.empty.should == Money.new(0)
|
|
@@ -205,14 +152,12 @@ describe Money do
|
|
|
205
152
|
describe "#fractional" do
|
|
206
153
|
it "returns the amount in fractional unit" do
|
|
207
154
|
Money.new(1_00).fractional.should == 1_00
|
|
208
|
-
Money.new_with_amount(1).fractional.should == 1_00
|
|
209
155
|
end
|
|
210
156
|
|
|
211
157
|
it "stores fractional as an integer regardless of what is passed into the constructor" do
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
end
|
|
158
|
+
m = Money.new(100)
|
|
159
|
+
m.fractional.should == 100
|
|
160
|
+
m.fractional.should be_a(Fixnum)
|
|
216
161
|
end
|
|
217
162
|
|
|
218
163
|
context "loading a serialized Money via YAML" do
|
|
@@ -290,6 +235,18 @@ YAML
|
|
|
290
235
|
|
|
291
236
|
Money.rounding_mode.should == BigDecimal::ROUND_HALF_EVEN
|
|
292
237
|
end
|
|
238
|
+
|
|
239
|
+
it "works for multiplication within a block" do
|
|
240
|
+
Money.rounding_mode(BigDecimal::ROUND_DOWN) do
|
|
241
|
+
(Money.new(1_00) * "0.019".to_d).fractional.should == 1
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
Money.rounding_mode(BigDecimal::ROUND_UP) do
|
|
245
|
+
(Money.new(1_00) * "0.011".to_d).fractional.should == 2
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
Money.rounding_mode.should == BigDecimal::ROUND_HALF_EVEN
|
|
249
|
+
end
|
|
293
250
|
end
|
|
294
251
|
end
|
|
295
252
|
|
|
@@ -304,14 +261,12 @@ YAML
|
|
|
304
261
|
|
|
305
262
|
it "returns the amount in fractional unit" do
|
|
306
263
|
Money.new(1_00).fractional.should == BigDecimal("100")
|
|
307
|
-
Money.new_with_amount(1).fractional.should == BigDecimal("100")
|
|
308
264
|
end
|
|
309
265
|
|
|
310
266
|
it "stores in fractional unit as an integer regardless of what is passed into the constructor" do
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
end
|
|
267
|
+
m = Money.new(100)
|
|
268
|
+
m.fractional.should == BigDecimal("100")
|
|
269
|
+
m.fractional.should be_a(BigDecimal)
|
|
315
270
|
end
|
|
316
271
|
end
|
|
317
272
|
end
|
|
@@ -319,7 +274,6 @@ YAML
|
|
|
319
274
|
describe "#amount" do
|
|
320
275
|
it "returns the amount of cents as dollars" do
|
|
321
276
|
Money.new(1_00).amount.should == 1
|
|
322
|
-
Money.new_with_amount(1).amount.should == 1
|
|
323
277
|
end
|
|
324
278
|
|
|
325
279
|
it "respects :subunit_to_unit currency property" do
|
|
@@ -330,7 +284,6 @@ YAML
|
|
|
330
284
|
|
|
331
285
|
it "does not loose precision" do
|
|
332
286
|
Money.new(100_37).amount.should == 100.37
|
|
333
|
-
Money.new_with_amount(100.37).amount.should == 100.37
|
|
334
287
|
end
|
|
335
288
|
|
|
336
289
|
it 'produces a BigDecimal' do
|
|
@@ -503,6 +456,18 @@ YAML
|
|
|
503
456
|
money.bank.should_receive(:exchange_with).with(Money.new(100_00, Money::Currency.new("USD")), Money::Currency.new("EUR")).and_return(Money.new(200_00, Money::Currency.new('EUR')))
|
|
504
457
|
money.exchange_to("EUR").should == Money.new(200_00, "EUR")
|
|
505
458
|
end
|
|
459
|
+
|
|
460
|
+
it 'uses the block given as rounding method' do
|
|
461
|
+
money = Money.new(100_00, 'USD')
|
|
462
|
+
money.bank.should_receive(:exchange_with).and_yield(300_00)
|
|
463
|
+
expect { |block| money.exchange_to(Money::Currency.new('EUR'), &block) }.to yield_successive_args(300_00)
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
it "does no exchange when the currencies are the same" do
|
|
467
|
+
money = Money.new(100_00, "USD")
|
|
468
|
+
money.bank.should_not_receive(:exchange_with)
|
|
469
|
+
money.exchange_to("USD").should == money
|
|
470
|
+
end
|
|
506
471
|
end
|
|
507
472
|
|
|
508
473
|
describe "#allocate" do
|
|
@@ -680,4 +645,24 @@ YAML
|
|
|
680
645
|
obj.as_euro.should == Money.new(1, "EUR")
|
|
681
646
|
end
|
|
682
647
|
end
|
|
648
|
+
|
|
649
|
+
describe ".default_currency" do
|
|
650
|
+
before do
|
|
651
|
+
@default_currency = Money.default_currency
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
it "accepts a lambda" do
|
|
655
|
+
Money.default_currency = lambda { :eur }
|
|
656
|
+
Money.default_currency.should == Money::Currency.new(:eur)
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
it "accepts a symbol" do
|
|
660
|
+
Money.default_currency = :eur
|
|
661
|
+
Money.default_currency.should == Money::Currency.new(:eur)
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
after do
|
|
665
|
+
Money.default_currency = @default_currency
|
|
666
|
+
end
|
|
667
|
+
end
|
|
683
668
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -4,11 +4,11 @@ Coveralls.wear!
|
|
|
4
4
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
|
5
5
|
require "rspec"
|
|
6
6
|
require "money"
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
I18n.enforce_available_locales = false
|
|
8
9
|
|
|
9
10
|
RSpec.configure do |c|
|
|
10
11
|
c.order = :random
|
|
11
|
-
c.include DefaultCurrencyHelper
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def silence_warnings
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: money
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.0
|
|
4
|
+
version: 6.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shane Emmons
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: i18n
|
|
@@ -24,20 +24,6 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.6.4
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: monetize
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.1.3
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.1.3
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
28
|
name: bundler
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -132,33 +118,23 @@ files:
|
|
|
132
118
|
- lib/money/bank/base.rb
|
|
133
119
|
- lib/money/bank/single_currency.rb
|
|
134
120
|
- lib/money/bank/variable_exchange.rb
|
|
135
|
-
- lib/money/core_extensions.rb
|
|
136
|
-
- lib/money/core_extensions/numeric.rb
|
|
137
|
-
- lib/money/core_extensions/string.rb
|
|
138
|
-
- lib/money/core_extensions/symbol.rb
|
|
139
121
|
- lib/money/currency.rb
|
|
140
122
|
- lib/money/currency/heuristics.rb
|
|
141
123
|
- lib/money/currency/loader.rb
|
|
142
|
-
- lib/money/deprecations.rb
|
|
143
124
|
- lib/money/money.rb
|
|
144
125
|
- lib/money/money/arithmetic.rb
|
|
145
126
|
- lib/money/money/formatting.rb
|
|
146
|
-
- lib/money/money/parsing.rb
|
|
147
127
|
- lib/money/version.rb
|
|
148
128
|
- money.gemspec
|
|
149
129
|
- spec/bank/base_spec.rb
|
|
150
130
|
- spec/bank/single_currency_spec.rb
|
|
151
131
|
- spec/bank/variable_exchange_spec.rb
|
|
152
|
-
- spec/core_extensions_spec.rb
|
|
153
132
|
- spec/currency/heuristics_spec.rb
|
|
154
133
|
- spec/currency_spec.rb
|
|
155
134
|
- spec/money/arithmetic_spec.rb
|
|
156
|
-
- spec/money/deprecations_spec.rb
|
|
157
135
|
- spec/money/formatting_spec.rb
|
|
158
|
-
- spec/money/parsing_spec.rb
|
|
159
136
|
- spec/money_spec.rb
|
|
160
137
|
- spec/spec_helper.rb
|
|
161
|
-
- spec/support/default_currency_helper.rb
|
|
162
138
|
homepage: http://rubymoney.github.io/money
|
|
163
139
|
licenses:
|
|
164
140
|
- MIT
|
|
@@ -187,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
187
163
|
version: '0'
|
|
188
164
|
requirements: []
|
|
189
165
|
rubyforge_project:
|
|
190
|
-
rubygems_version: 2.2.
|
|
166
|
+
rubygems_version: 2.2.2
|
|
191
167
|
signing_key:
|
|
192
168
|
specification_version: 4
|
|
193
169
|
summary: A Ruby Library for dealing with money and currency conversion.
|
|
@@ -195,14 +171,10 @@ test_files:
|
|
|
195
171
|
- spec/bank/base_spec.rb
|
|
196
172
|
- spec/bank/single_currency_spec.rb
|
|
197
173
|
- spec/bank/variable_exchange_spec.rb
|
|
198
|
-
- spec/core_extensions_spec.rb
|
|
199
174
|
- spec/currency/heuristics_spec.rb
|
|
200
175
|
- spec/currency_spec.rb
|
|
201
176
|
- spec/money/arithmetic_spec.rb
|
|
202
|
-
- spec/money/deprecations_spec.rb
|
|
203
177
|
- spec/money/formatting_spec.rb
|
|
204
|
-
- spec/money/parsing_spec.rb
|
|
205
178
|
- spec/money_spec.rb
|
|
206
179
|
- spec/spec_helper.rb
|
|
207
|
-
- spec/support/default_currency_helper.rb
|
|
208
180
|
has_rdoc:
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
class Numeric
|
|
2
|
-
alias_method :_to_money, :to_money
|
|
3
|
-
def to_money(*args)
|
|
4
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use Numeric#to_money. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so"
|
|
5
|
-
_to_money(*args)
|
|
6
|
-
end
|
|
7
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class String
|
|
2
|
-
alias_method :_to_money, :to_money
|
|
3
|
-
def to_money(*args)
|
|
4
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use String#to_money. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so"
|
|
5
|
-
_to_money(*args)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
alias_method :_to_currency, :to_currency
|
|
9
|
-
def to_currency(*args)
|
|
10
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use String#to_currency. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so"
|
|
11
|
-
_to_currency(*args)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
class Symbol
|
|
2
|
-
alias_method :_to_currency, :to_currency
|
|
3
|
-
def to_currency(*args)
|
|
4
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use Symbol#to_currency. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so"
|
|
5
|
-
_to_currency(*args)
|
|
6
|
-
end
|
|
7
|
-
end
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
require "money/core_extensions/numeric"
|
|
2
|
-
require "money/core_extensions/string"
|
|
3
|
-
require "money/core_extensions/symbol"
|
|
4
|
-
|
|
5
|
-
Money.deprecate "as of Money 6.1.0 you must `require 'monetize/core_extensions'` to use core extensions. Please start using the Monetize gem from https://github.com/RubyMoney/monetize if you are not already doing so."
|
|
6
|
-
|
|
7
|
-
Money.silence_core_extensions_deprecations = true
|
data/lib/money/deprecations.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class Money
|
|
2
|
-
# Displays a deprecation warning message.
|
|
3
|
-
#
|
|
4
|
-
# @param [String] message The message to display.
|
|
5
|
-
#
|
|
6
|
-
# @return [nil]
|
|
7
|
-
def self.deprecate(message)
|
|
8
|
-
unless Money.silence_core_extensions_deprecations
|
|
9
|
-
file, line = caller(2).first.split(':', 2)
|
|
10
|
-
line = line.to_i
|
|
11
|
-
|
|
12
|
-
warn "DEPRECATION WARNING: #{message} (called from: #{file}:#{line})"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/money/money/parsing.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#encoding: utf-8
|
|
2
|
-
|
|
3
|
-
class Money
|
|
4
|
-
module Parsing
|
|
5
|
-
def self.included(base)
|
|
6
|
-
base.extend ClassMethods
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
module ClassMethods
|
|
10
|
-
def parse(input, currency = nil)
|
|
11
|
-
Money.deprecate ".parse is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
12
|
-
Monetize.parse(input, currency)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def from_string(value, currency = Money.default_currency)
|
|
16
|
-
Money.deprecate ".from_string is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
17
|
-
Monetize.from_string(value, currency)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def from_fixnum(value, currency = Money.default_currency)
|
|
21
|
-
Money.deprecate ".from_fixnum is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
22
|
-
Monetize.from_fixnum(value, currency)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def from_float(value, currency = Money.default_currency)
|
|
26
|
-
Money.deprecate ".from_float is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
27
|
-
Monetize.from_float(value, currency)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def from_bigdecimal(value, currency = Money.default_currency)
|
|
31
|
-
Money.deprecate ".from_bigdecimal is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
32
|
-
Monetize.from_bigdecimal(value, currency)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def from_numeric(value, currency = Money.default_currency)
|
|
36
|
-
Money.deprecate ".from_numeric is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
37
|
-
Monetize.from_numeric(value, currency)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def extract_cents(input, currency = Money.default_currency)
|
|
41
|
-
Money.deprecate ".extract_cents is deprecated and will be removed in 6.1.0. Please use the `monetize` gem."
|
|
42
|
-
Monetize.extract_cents(input, currency)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Money, "core extensions" do
|
|
4
|
-
|
|
5
|
-
describe Numeric do
|
|
6
|
-
describe "#to_money" do
|
|
7
|
-
it "work as documented" do
|
|
8
|
-
money = 1234.to_money
|
|
9
|
-
money.cents.should == 1234_00
|
|
10
|
-
money.currency.should == Money.default_currency
|
|
11
|
-
|
|
12
|
-
money = 100.37.to_money
|
|
13
|
-
money.cents.should == 100_37
|
|
14
|
-
money.currency.should == Money.default_currency
|
|
15
|
-
|
|
16
|
-
money = BigDecimal.new('1234').to_money
|
|
17
|
-
money.cents.should == 1234_00
|
|
18
|
-
money.currency.should == Money.default_currency
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "accepts optional currency" do
|
|
22
|
-
1234.to_money('USD').should == Money.new(123400, 'USD')
|
|
23
|
-
1234.to_money('EUR').should == Money.new(123400, 'EUR')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "respects :subunit_to_unit currency property" do
|
|
27
|
-
10.to_money('USD').should == Money.new(10_00, 'USD')
|
|
28
|
-
10.to_money('TND').should == Money.new(10_000, 'TND')
|
|
29
|
-
10.to_money('CLP').should == Money.new(10, 'CLP')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
specify "GH-15" do
|
|
33
|
-
amount = 555.55.to_money
|
|
34
|
-
amount.should == Money.new(55555)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe String do
|
|
40
|
-
describe "#to_money" do
|
|
41
|
-
|
|
42
|
-
STRING_TO_MONEY = {
|
|
43
|
-
"20.15" => Money.new(20_15) ,
|
|
44
|
-
"100" => Money.new(100_00) ,
|
|
45
|
-
"100.37" => Money.new(100_37) ,
|
|
46
|
-
"100,37" => Money.new(100_37) ,
|
|
47
|
-
"100 000" => Money.new(100_000_00) ,
|
|
48
|
-
"100,000.00" => Money.new(100_000_00) ,
|
|
49
|
-
"1,000" => Money.new(1_000_00) ,
|
|
50
|
-
"-1,000" => Money.new(-1_000_00) ,
|
|
51
|
-
"1,000.5" => Money.new(1_000_50) ,
|
|
52
|
-
"1,000.51" => Money.new(1_000_51) ,
|
|
53
|
-
"1,000.505" => Money.new(1_000_51) ,
|
|
54
|
-
"1,000.504" => Money.new(1_000_50) ,
|
|
55
|
-
"1,000.0000" => Money.new(1_000_00) ,
|
|
56
|
-
"1,000.5000" => Money.new(1_000_50) ,
|
|
57
|
-
"1,000.5099" => Money.new(1_000_51) ,
|
|
58
|
-
"1.550" => Money.new(1_55) ,
|
|
59
|
-
"25." => Money.new(25_00) ,
|
|
60
|
-
".75" => Money.new(75) ,
|
|
61
|
-
|
|
62
|
-
"100 USD" => Money.new(100_00, "USD") ,
|
|
63
|
-
"-100 USD" => Money.new(-100_00, "USD") ,
|
|
64
|
-
"100 EUR" => Money.new(100_00, "EUR") ,
|
|
65
|
-
"100.37 EUR" => Money.new(100_37, "EUR") ,
|
|
66
|
-
"100,37 EUR" => Money.new(100_37, "EUR") ,
|
|
67
|
-
"100,000.00 USD" => Money.new(100_000_00, "USD") ,
|
|
68
|
-
"100.000,00 EUR" => Money.new(100_000_00, "EUR") ,
|
|
69
|
-
"1,000 USD" => Money.new(1_000_00, "USD") ,
|
|
70
|
-
"-1,000 USD" => Money.new(-1_000_00, "USD") ,
|
|
71
|
-
"1,000.5500 USD" => Money.new(1_000_55, "USD") ,
|
|
72
|
-
"-1,000.6500 USD" => Money.new(-1_000_65, "USD") ,
|
|
73
|
-
"1.550 USD" => Money.new(1_55, "USD") ,
|
|
74
|
-
|
|
75
|
-
"USD 100" => Money.new(100_00, "USD") ,
|
|
76
|
-
"EUR 100" => Money.new(100_00, "EUR") ,
|
|
77
|
-
"EUR 100.37" => Money.new(100_37, "EUR") ,
|
|
78
|
-
"CAD -100.37" => Money.new(-100_37, "CAD") ,
|
|
79
|
-
"EUR 100,37" => Money.new(100_37, "EUR") ,
|
|
80
|
-
"EUR -100,37" => Money.new(-100_37, "EUR") ,
|
|
81
|
-
"USD 100,000.00" => Money.new(100_000_00, "USD") ,
|
|
82
|
-
"EUR 100.000,00" => Money.new(100_000_00, "EUR") ,
|
|
83
|
-
"USD 1,000" => Money.new(1_000_00, "USD") ,
|
|
84
|
-
"USD -1,000" => Money.new(-1_000_00, "USD") ,
|
|
85
|
-
"USD 1,000.9000" => Money.new(1_000_90, "USD") ,
|
|
86
|
-
"USD -1,000.090" => Money.new(-1_000_09, "USD") ,
|
|
87
|
-
"USD 1.5500" => Money.new(1_55, "USD") ,
|
|
88
|
-
|
|
89
|
-
"$100 USD" => Money.new(100_00, "USD") ,
|
|
90
|
-
"$1,194.59 USD" => Money.new(1_194_59, "USD") ,
|
|
91
|
-
"$-1,955 USD" => Money.new(-1_955_00, "USD") ,
|
|
92
|
-
"$1,194.5900 USD" => Money.new(1_194_59, "USD") ,
|
|
93
|
-
"$-1,955.000 USD" => Money.new(-1_955_00, "USD") ,
|
|
94
|
-
"$1.99000 USD" => Money.new(1_99, "USD") ,
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
it "works as documented" do
|
|
98
|
-
STRING_TO_MONEY.each do |string, money|
|
|
99
|
-
string.to_money.should == money
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "coerces input to string" do
|
|
104
|
-
Money.parse(20, "USD").should == Money.new(20_00, "USD")
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it "accepts optional currency" do
|
|
108
|
-
"10.10".to_money('USD').should == Money.new(1010, 'USD')
|
|
109
|
-
"10.10".to_money('EUR').should == Money.new(1010, 'EUR')
|
|
110
|
-
"10.10 USD".to_money('USD').should == Money.new(1010, 'USD')
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "uses the parsed currency even if a currency was specified by the method" do
|
|
114
|
-
expect("10.10 USD".to_money("EUR")).to eq Money.new(1010, "USD")
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "ignores unrecognized data" do
|
|
118
|
-
"hello 2000 world".to_money.should == Money.new(2000_00)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it "respects :subunit_to_unit currency property" do
|
|
122
|
-
"1".to_money("USD").should == Money.new(1_00, "USD")
|
|
123
|
-
"1".to_money("TND").should == Money.new(1_000, "TND")
|
|
124
|
-
"1".to_money("CLP").should == Money.new(1, "CLP")
|
|
125
|
-
"1.5".to_money("KWD").cents.should == 1500
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe "#to_currency" do
|
|
130
|
-
it "converts String to Currency" do
|
|
131
|
-
"USD".to_currency.should == Money::Currency.new("USD")
|
|
132
|
-
"EUR".to_currency.should == Money::Currency.new("EUR")
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it "raises Money::Currency::UnknownCurrency with unknown Currency" do
|
|
136
|
-
expect { "XXX".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
|
137
|
-
expect { " ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
describe Symbol do
|
|
143
|
-
describe "#to_currency" do
|
|
144
|
-
it "converts Symbol to Currency" do
|
|
145
|
-
:usd.to_currency.should == Money::Currency.new("USD")
|
|
146
|
-
:ars.to_currency.should == Money::Currency.new("ARS")
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it "is case-insensitive" do
|
|
150
|
-
:EUR.to_currency.should == Money::Currency.new("EUR")
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it "raises Money::Currency::UnknownCurrency with unknown Currency" do
|
|
154
|
-
expect { :XXX.to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
|
155
|
-
expect { :" ".to_currency }.to raise_error(Money::Currency::UnknownCurrency)
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
describe Money do
|
|
6
|
-
describe "::deprecate" do
|
|
7
|
-
it "should send a deprecation message with caller" do
|
|
8
|
-
error_message = "Deprecated method triggered here"
|
|
9
|
-
|
|
10
|
-
Money.should_receive(:warn).with do |message|
|
|
11
|
-
message.should =~ /DEPRECATION WARNING: #{error_message} \(called from:.*:\d+\)/
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
Money.deprecate(error_message)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "when silenced" do
|
|
18
|
-
it "should not warn" do
|
|
19
|
-
Money.should_not_receive(:warn)
|
|
20
|
-
|
|
21
|
-
while_silenced { Money.deprecate("anything") }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "core extensions" do
|
|
27
|
-
it "does not print deprecations when silenced" do
|
|
28
|
-
while_silenced do
|
|
29
|
-
expect_no_deprecation_for { "$1.00".to_money }
|
|
30
|
-
expect_no_deprecation_for { "USD".to_currency }
|
|
31
|
-
expect_no_deprecation_for { 1.to_money }
|
|
32
|
-
expect_no_deprecation_for { :USD.to_currency }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def expect_no_deprecation_for(&block)
|
|
37
|
-
Money.should_not_receive(:warn)
|
|
38
|
-
yield
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def while_silenced(&block)
|
|
43
|
-
begin
|
|
44
|
-
old_setting = Money.silence_core_extensions_deprecations
|
|
45
|
-
Money.silence_core_extensions_deprecations = true
|
|
46
|
-
yield
|
|
47
|
-
ensure
|
|
48
|
-
Money.silence_core_extensions_deprecations = old_setting
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|