money 6.0.1 → 6.1.0.beta1

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.
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
- require "support/default_currency_helper"
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.1
4
+ version: 6.1.0.beta1
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-01-17 00:00:00.000000000 Z
11
+ date: 2014-01-21 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
@@ -182,9 +158,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
158
  version: '0'
183
159
  required_rubygems_version: !ruby/object:Gem::Requirement
184
160
  requirements:
185
- - - ">="
161
+ - - ">"
186
162
  - !ruby/object:Gem::Version
187
- version: '0'
163
+ version: 1.3.1
188
164
  requirements: []
189
165
  rubyforge_project:
190
166
  rubygems_version: 2.2.0
@@ -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
- 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
@@ -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,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
@@ -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
@@ -1,333 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Money, "parsing" do
6
-
7
- 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": "," }'
8
- 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": "." }'
9
-
10
- describe ".parse" do
11
- it "is deprecated" do
12
- Money.should_receive(:deprecate).at_least(1).times
13
- Money.parse("1.95")
14
- end
15
-
16
- it "parses european-formatted inputs under 10EUR" do
17
- five_ninety_five = Money.new(595, 'EUR')
18
-
19
- Money.parse('EUR 5,95').should == five_ninety_five
20
- end
21
-
22
- it "parses european-formatted inputs with multiple thousands-seperators" do
23
- Money.parse('EUR 1.234.567,89').should == Money.new(123456789, 'EUR')
24
- Money.parse('EUR 1.111.234.567,89').should == Money.new(111123456789, 'EUR')
25
- end
26
-
27
- describe 'currency assumption' do
28
- context 'opted in' do
29
- before do
30
- Money.assume_from_symbol = true
31
- end
32
- it "parses formatted inputs with the currency passed as a symbol" do
33
- with_default_currency("EUR") do
34
- Money.parse("$5.95").should == Money.new(595, 'USD')
35
- end
36
- Money.parse("€5.95").should == Money.new(595, 'EUR')
37
- Money.parse(" €5.95 ").should == Money.new(595, 'EUR')
38
- Money.parse("£9.99").should == Money.new(999, 'GBP')
39
- end
40
- it 'should assume default currency if not a recognised symbol' do
41
- Money.parse("L9.99").should == Money.new(999, 'USD')
42
- end
43
- end
44
- context 'opted out' do
45
- before do
46
- Money.assume_from_symbol = false
47
- end
48
- it "parses formatted inputs with the currency passed as a symbol but ignores the symbol" do
49
- Money.parse("$5.95").should == Money.new(595, 'USD')
50
- Money.parse("€5.95").should == Money.new(595, 'USD')
51
- Money.parse(" €5.95 ").should == Money.new(595, 'USD')
52
- Money.parse("£9.99").should == Money.new(999, 'USD')
53
-
54
- end
55
- end
56
- it 'should opt out by default' do
57
- Money.assume_from_symbol.should be_false
58
- end
59
- end
60
-
61
- it "parses USD-formatted inputs under $10" do
62
- five_ninety_five = Money.new(595, 'USD')
63
-
64
- Money.parse(5.95).should == five_ninety_five
65
- Money.parse('5.95').should == five_ninety_five
66
- Money.parse('$5.95').should == five_ninety_five
67
- Money.parse("\n $5.95 \n").should == five_ninety_five
68
- Money.parse('$ 5.95').should == five_ninety_five
69
- Money.parse('$5.95 ea.').should == five_ninety_five
70
- Money.parse('$5.95, each').should == five_ninety_five
71
- end
72
-
73
- it "parses USD-formatted inputs with multiple thousands-seperators" do
74
- Money.parse('1,234,567.89').should == Money.new(123456789, 'USD')
75
- Money.parse('1,111,234,567.89').should == Money.new(111123456789, 'USD')
76
- end
77
-
78
- it "does not return a price if there is a price range" do
79
- expect { Money.parse('$5.95-10.95') }.to raise_error ArgumentError
80
- expect { Money.parse('$5.95 - 10.95') }.to raise_error ArgumentError
81
- expect { Money.parse('$5.95 - $10.95') }.to raise_error ArgumentError
82
- end
83
-
84
- it "does not return a price for completely invalid input" do
85
- # TODO: shouldn't these throw an error instead of being considered
86
- # equal to $0.0?
87
- empty_price = Money.new(0, 'USD')
88
-
89
- Money.parse(nil).should == empty_price
90
- Money.parse('hellothere').should == empty_price
91
- Money.parse('').should == empty_price
92
- end
93
-
94
- it "handles negative inputs" do
95
- five_ninety_five = Money.new(595, 'USD')
96
-
97
- Money.parse("$-5.95").should == -five_ninety_five
98
- Money.parse("-$5.95").should == -five_ninety_five
99
- Money.parse("$5.95-").should == -five_ninety_five
100
- end
101
-
102
- it "raises ArgumentError when unable to detect polarity" do
103
- expect { Money.parse('-$5.95-') }.to raise_error ArgumentError
104
- end
105
-
106
- it "parses correctly strings with exactly 3 decimal digits" do
107
- Money.parse("6,534", "EUR").should == Money.new(653, "EUR")
108
- end
109
-
110
- context "custom currencies with 4 decimal places" do
111
- before :each do
112
- Money::Currency.register(JSON.parse(bar, :symbolize_names => true))
113
- Money::Currency.register(JSON.parse(eu4, :symbolize_names => true))
114
- end
115
-
116
- after :each do
117
- Money::Currency.unregister(JSON.parse(bar, :symbolize_names => true))
118
- Money::Currency.unregister(JSON.parse(eu4, :symbolize_names => true))
119
- end
120
-
121
- # String#to_money(Currency) is equivalent to Money.parse(String, Currency)
122
- it "parses strings respecting subunit to unit, decimal and thousands separator" do
123
- "$0.4".to_money("BAR").should == Money.new(4000, "BAR")
124
- "€0,4".to_money("EU4").should == Money.new(4000, "EU4")
125
-
126
- "$0.04".to_money("BAR").should == Money.new(400, "BAR")
127
- "€0,04".to_money("EU4").should == Money.new(400, "EU4")
128
-
129
- "$0.004".to_money("BAR").should == Money.new(40, "BAR")
130
- "€0,004".to_money("EU4").should == Money.new(40, "EU4")
131
-
132
- "$0.0004".to_money("BAR").should == Money.new(4, "BAR")
133
- "€0,0004".to_money("EU4").should == Money.new(4, "EU4")
134
-
135
- "$0.0024".to_money("BAR").should == Money.new(24, "BAR")
136
- "€0,0024".to_money("EU4").should == Money.new(24, "EU4")
137
-
138
- "$0.0324".to_money("BAR").should == Money.new(324, "BAR")
139
- "€0,0324".to_money("EU4").should == Money.new(324, "EU4")
140
-
141
- "$0.5324".to_money("BAR").should == Money.new(5324, "BAR")
142
- "€0,5324".to_money("EU4").should == Money.new(5324, "EU4")
143
-
144
- "$6.5324".to_money("BAR").should == Money.new(65324, "BAR")
145
- "€6,5324".to_money("EU4").should == Money.new(65324, "EU4")
146
-
147
- "$86.5324".to_money("BAR").should == Money.new(865324, "BAR")
148
- "€86,5324".to_money("EU4").should == Money.new(865324, "EU4")
149
-
150
- "$186.5324".to_money("BAR").should == Money.new(1865324, "BAR")
151
- "€186,5324".to_money("EU4").should == Money.new(1865324, "EU4")
152
-
153
- "$3,331.0034".to_money("BAR").should == Money.new(33310034, "BAR")
154
- "€3.331,0034".to_money("EU4").should == Money.new(33310034, "EU4")
155
-
156
- "$8,883,331.0034".to_money("BAR").should == Money.new(88833310034, "BAR")
157
- "€8.883.331,0034".to_money("EU4").should == Money.new(88833310034, "EU4")
158
- end
159
- end
160
- end
161
-
162
- describe ".from_string" do
163
- it "converts given amount to cents" do
164
- Money.from_string("1").should == Money.new(1_00)
165
- Money.from_string("1").should == Money.new(1_00, "USD")
166
- Money.from_string("1", "EUR").should == Money.new(1_00, "EUR")
167
- end
168
-
169
- it "respects :subunit_to_unit currency property" do
170
- Money.from_string("1", "USD").should == Money.new(1_00, "USD")
171
- Money.from_string("1", "TND").should == Money.new(1_000, "TND")
172
- Money.from_string("1", "CLP").should == Money.new(1, "CLP")
173
- end
174
-
175
- it "accepts a currency options" do
176
- m = Money.from_string("1")
177
- m.currency.should == Money.default_currency
178
-
179
- m = Money.from_string("1", Money::Currency.wrap("EUR"))
180
- m.currency.should == Money::Currency.wrap("EUR")
181
-
182
- m = Money.from_string("1", "EUR")
183
- m.currency.should == Money::Currency.wrap("EUR")
184
- end
185
- end
186
-
187
- describe ".from_fixnum" do
188
- it "converts given amount to cents" do
189
- Money.from_fixnum(1).should == Money.new(1_00)
190
- Money.from_fixnum(1).should == Money.new(1_00, "USD")
191
- Money.from_fixnum(1, "EUR").should == Money.new(1_00, "EUR")
192
- end
193
-
194
- it "should respect :subunit_to_unit currency property" do
195
- Money.from_fixnum(1, "USD").should == Money.new(1_00, "USD")
196
- Money.from_fixnum(1, "TND").should == Money.new(1_000, "TND")
197
- Money.from_fixnum(1, "CLP").should == Money.new(1, "CLP")
198
- end
199
-
200
- it "accepts a currency options" do
201
- m = Money.from_fixnum(1)
202
- m.currency.should == Money.default_currency
203
-
204
- m = Money.from_fixnum(1, Money::Currency.wrap("EUR"))
205
- m.currency.should == Money::Currency.wrap("EUR")
206
-
207
- m = Money.from_fixnum(1, "EUR")
208
- m.currency.should == Money::Currency.wrap("EUR")
209
- end
210
- end
211
-
212
- describe ".from_float" do
213
- it "converts given amount to cents" do
214
- Money.from_float(1.2).should == Money.new(1_20)
215
- Money.from_float(1.2).should == Money.new(1_20, "USD")
216
- Money.from_float(1.2, "EUR").should == Money.new(1_20, "EUR")
217
- end
218
-
219
- it "respects :subunit_to_unit currency property" do
220
- Money.from_float(1.2, "USD").should == Money.new(1_20, "USD")
221
- Money.from_float(1.2, "TND").should == Money.new(1_200, "TND")
222
- Money.from_float(1.2, "CLP").should == Money.new(1, "CLP")
223
- end
224
-
225
- it "accepts a currency options" do
226
- m = Money.from_float(1.2)
227
- m.currency.should == Money.default_currency
228
-
229
- m = Money.from_float(1.2, Money::Currency.wrap("EUR"))
230
- m.currency.should == Money::Currency.wrap("EUR")
231
-
232
- m = Money.from_float(1.2, "EUR")
233
- m.currency.should == Money::Currency.wrap("EUR")
234
- end
235
- end
236
-
237
- describe ".from_bigdecimal" do
238
- it "converts given amount to cents" do
239
- Money.from_bigdecimal(BigDecimal.new("1")).should == Money.new(1_00)
240
- Money.from_bigdecimal(BigDecimal.new("1")).should == Money.new(1_00, "USD")
241
- Money.from_bigdecimal(BigDecimal.new("1"), "EUR").should == Money.new(1_00, "EUR")
242
- end
243
-
244
- it "respects :subunit_to_unit currency property" do
245
- Money.from_bigdecimal(BigDecimal.new("1"), "USD").should == Money.new(1_00, "USD")
246
- Money.from_bigdecimal(BigDecimal.new("1"), "TND").should == Money.new(1_000, "TND")
247
- Money.from_bigdecimal(BigDecimal.new("1"), "CLP").should == Money.new(1, "CLP")
248
- end
249
-
250
- it "accepts a currency options" do
251
- m = Money.from_bigdecimal(BigDecimal.new("1"))
252
- m.currency.should == Money.default_currency
253
-
254
- m = Money.from_bigdecimal(BigDecimal.new("1"), Money::Currency.wrap("EUR"))
255
- m.currency.should == Money::Currency.wrap("EUR")
256
-
257
- m = Money.from_bigdecimal(BigDecimal.new("1"), "EUR")
258
- m.currency.should == Money::Currency.wrap("EUR")
259
- end
260
-
261
- context "infinite_precision = true" do
262
- before do
263
- Money.infinite_precision = true
264
- end
265
-
266
- after do
267
- Money.infinite_precision = false
268
- end
269
-
270
- it "keeps precision" do
271
- Money.from_bigdecimal(BigDecimal.new("1.23456")).should == Money.new(123.456)
272
- Money.from_bigdecimal(BigDecimal.new("-1.23456")).should == Money.new(-123.456)
273
- Money.from_bigdecimal(BigDecimal.new("1.23456")).should == Money.new(123.456, "USD")
274
- Money.from_bigdecimal(BigDecimal.new("1.23456"), "EUR").should == Money.new(123.456, "EUR")
275
- end
276
- end
277
- end
278
-
279
- describe ".from_numeric" do
280
- it "converts given amount to cents" do
281
- Money.from_numeric(1).should == Money.new(1_00)
282
- Money.from_numeric(1.0).should == Money.new(1_00)
283
- Money.from_numeric(BigDecimal.new("1")).should == Money.new(1_00)
284
- end
285
-
286
- it "raises ArgumentError with unsupported argument" do
287
- expect { Money.from_numeric("100") }.to raise_error(ArgumentError)
288
- end
289
-
290
- it "optimizes workload" do
291
- Monetize.should_receive(:from_fixnum).with(1, "USD").and_return(Money.new(1_00, "USD"))
292
- Money.from_numeric(1, "USD").should == Money.new(1_00, "USD")
293
- Monetize.should_receive(:from_bigdecimal).with(BigDecimal.new("1.0"), "USD").and_return(Money.new(1_00, "USD"))
294
- Money.from_numeric(1.0, "USD").should == Money.new(1_00, "USD")
295
- end
296
-
297
- it "respects :subunit_to_unit currency property" do
298
- Money.from_numeric(1, "USD").should == Money.new(1_00, "USD")
299
- Money.from_numeric(1, "TND").should == Money.new(1_000, "TND")
300
- Money.from_numeric(1, "CLP").should == Money.new(1, "CLP")
301
- end
302
-
303
- it "accepts a bank option" do
304
- Money.from_numeric(1).should == Money.new(1_00)
305
- Money.from_numeric(1).should == Money.new(1_00, "USD")
306
- Money.from_numeric(1, "EUR").should == Money.new(1_00, "EUR")
307
- end
308
-
309
- it "accepts a currency options" do
310
- m = Money.from_numeric(1)
311
- m.currency.should == Money.default_currency
312
-
313
- m = Money.from_numeric(1, Money::Currency.wrap("EUR"))
314
- m.currency.should == Money::Currency.wrap("EUR")
315
-
316
- m = Money.from_numeric(1, "EUR")
317
- m.currency.should == Money::Currency.wrap("EUR")
318
- end
319
- end
320
-
321
- describe ".extract_cents" do
322
- it "correctly treats pipe marks '|' in input (regression test)" do
323
- Money.extract_cents('100|0').should == Money.extract_cents('100!0')
324
- end
325
- end
326
-
327
- context "given the same inputs to .parse and .from_*" do
328
- it "gives the same results" do
329
- 4.635.to_money.should == "4.635".to_money
330
- end
331
- end
332
-
333
- end