money 6.0.0 → 6.0.1

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/money_spec.rb CHANGED
@@ -43,6 +43,11 @@ describe Money do
43
43
  it { should eq initializing_value }
44
44
  end
45
45
 
46
+ context "given the initializing value doesn't respond to .to_d" do
47
+ let(:initializing_value) { :"1" }
48
+ it { should eq Money.new(1) }
49
+ end
50
+
46
51
  context 'given a currency is not provided' do
47
52
  subject(:money) { Money.new(initializing_value) }
48
53
  its(:currency) { should eq Money.default_currency }
@@ -123,6 +128,19 @@ describe Money do
123
128
  it "creates a new Money object of 0 cents" do
124
129
  Money.empty.should == Money.new(0)
125
130
  end
131
+
132
+ it "memoizes the result" do
133
+ Money.empty.object_id.should == Money.empty.object_id
134
+ end
135
+
136
+ it "memoizes a result for each currency" do
137
+ Money.empty(:cad).object_id.should == Money.empty(:cad).object_id
138
+ end
139
+ end
140
+
141
+ describe ".zero" do
142
+ subject { Money.zero }
143
+ it { should == Money.empty }
126
144
  end
127
145
 
128
146
  describe ".ca_dollar" do
@@ -196,7 +214,7 @@ describe Money do
196
214
  m.fractional.should be_a(Fixnum)
197
215
  end
198
216
  end
199
-
217
+
200
218
  context "loading a serialized Money via YAML" do
201
219
 
202
220
  let(:serialized) { <<YAML
@@ -250,12 +268,28 @@ YAML
250
268
  Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
251
269
  end
252
270
 
253
- it "respects the rounding_mode" do
254
- Money.rounding_mode = BigDecimal::ROUND_DOWN
255
- Money.new(1.9).fractional.should == 1
271
+ context "with the setter" do
272
+ it "respects the rounding_mode" do
273
+ Money.rounding_mode = BigDecimal::ROUND_DOWN
274
+ Money.new(1.9).fractional.should == 1
275
+
276
+ Money.rounding_mode = BigDecimal::ROUND_UP
277
+ Money.new(1.1).fractional.should == 2
278
+ end
279
+ end
280
+
281
+ context "with a block" do
282
+ it "respects the rounding_mode" do
283
+ Money.rounding_mode(BigDecimal::ROUND_DOWN) do
284
+ Money.new(1.9).fractional
285
+ end.should == 1
286
+
287
+ Money.rounding_mode(BigDecimal::ROUND_UP) do
288
+ Money.new(1.1).fractional
289
+ end.should == 2
256
290
 
257
- Money.rounding_mode = BigDecimal::ROUND_UP
258
- Money.new(1.1).fractional.should == 2
291
+ Money.rounding_mode.should == BigDecimal::ROUND_HALF_EVEN
292
+ end
259
293
  end
260
294
  end
261
295
 
@@ -312,7 +346,7 @@ YAML
312
346
  def m.amount
313
347
  5
314
348
  end
315
-
349
+
316
350
  m.dollars.should == 5
317
351
  end
318
352
  end
@@ -359,11 +393,11 @@ YAML
359
393
  it "works as documented" do
360
394
  currency = Money::Currency.new("EUR")
361
395
  currency.should_receive(:symbol).and_return("€")
362
- Money.empty(currency).symbol.should == "€"
396
+ Money.new(0, currency).symbol.should == "€"
363
397
 
364
398
  currency = Money::Currency.new("EUR")
365
399
  currency.should_receive(:symbol).and_return(nil)
366
- Money.empty(currency).symbol.should == "¤"
400
+ Money.new(0, currency).symbol.should == "¤"
367
401
  end
368
402
  end
369
403
 
@@ -407,6 +441,10 @@ YAML
407
441
  it "suppresses fractional cents when there is none" do
408
442
  Money.new(1.0, "USD").to_s.should == "0.01"
409
443
  end
444
+
445
+ it "shows fractional if needed when :subunut_to_unit == 1" do
446
+ Money.new(10_00.1, "CLP").to_s.should == "1000,1"
447
+ end
410
448
  end
411
449
  end
412
450
 
@@ -614,4 +652,32 @@ YAML
614
652
  (MoneyChild.new(1000) - Money.new(500)).should eq Money.new(500)
615
653
  end
616
654
  end
655
+
656
+ describe "#as_*" do
657
+ before do
658
+ Money.default_bank = Money::Bank::VariableExchange.new
659
+ Money.add_rate("EUR", "USD", 1)
660
+ Money.add_rate("EUR", "CAD", 1)
661
+ Money.add_rate("USD", "EUR", 1)
662
+ end
663
+
664
+ after do
665
+ Money.default_bank = Money::Bank::VariableExchange.instance
666
+ end
667
+
668
+ specify "as_us_dollar converts Money object to USD" do
669
+ obj = Money.new(1, "EUR")
670
+ obj.as_us_dollar.should == Money.new(1, "USD")
671
+ end
672
+
673
+ specify "as_ca_dollar converts Money object to CAD" do
674
+ obj = Money.new(1, "EUR")
675
+ obj.as_ca_dollar.should == Money.new(1, "CAD")
676
+ end
677
+
678
+ specify "as_euro converts Money object to EUR" do
679
+ obj = Money.new(1, "USD")
680
+ obj.as_euro.should == Money.new(1, "EUR")
681
+ end
682
+ end
617
683
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,13 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
1
4
  $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'rspec'
3
- require 'money'
4
- require 'support/default_currency_helper'
5
+ require "rspec"
6
+ require "money"
7
+ require "support/default_currency_helper"
5
8
 
6
9
  RSpec.configure do |c|
7
- c.order = "rand"
10
+ c.order = :random
8
11
  c.include DefaultCurrencyHelper
9
12
  end
10
13
 
metadata CHANGED
@@ -1,153 +1,208 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
5
- prerelease:
4
+ version: 6.0.1
6
5
  platform: ruby
7
6
  authors:
8
- - Tobias Luetke
9
- - Hongli Lai
10
- - Jeremy McNevin
11
7
  - Shane Emmons
12
- - Simone Carletti
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
17
12
  dependencies:
18
13
  - !ruby/object:Gem::Dependency
19
14
  name: i18n
20
15
  requirement: !ruby/object:Gem::Requirement
21
- none: false
22
16
  requirements:
23
- - - ~>
17
+ - - "~>"
24
18
  - !ruby/object:Gem::Version
25
19
  version: 0.6.4
26
20
  type: :runtime
27
21
  prerelease: false
28
22
  version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
23
  requirements:
31
- - - ~>
24
+ - - "~>"
32
25
  - !ruby/object:Gem::Version
33
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
34
69
  - !ruby/object:Gem::Dependency
35
70
  name: rspec
36
71
  requirement: !ruby/object:Gem::Requirement
37
- none: false
38
72
  requirements:
39
- - - ~>
73
+ - - "~>"
40
74
  - !ruby/object:Gem::Version
41
75
  version: '2.14'
42
76
  type: :development
43
77
  prerelease: false
44
78
  version_requirements: !ruby/object:Gem::Requirement
45
- none: false
46
79
  requirements:
47
- - - ~>
80
+ - - "~>"
48
81
  - !ruby/object:Gem::Version
49
82
  version: '2.14'
50
83
  - !ruby/object:Gem::Dependency
51
84
  name: yard
52
85
  requirement: !ruby/object:Gem::Requirement
53
- none: false
54
86
  requirements:
55
- - - ~>
87
+ - - "~>"
56
88
  - !ruby/object:Gem::Version
57
89
  version: '0.8'
58
90
  type: :development
59
91
  prerelease: false
60
92
  version_requirements: !ruby/object:Gem::Requirement
61
- none: false
62
93
  requirements:
63
- - - ~>
94
+ - - "~>"
64
95
  - !ruby/object:Gem::Version
65
96
  version: '0.8'
66
97
  - !ruby/object:Gem::Dependency
67
98
  name: kramdown
68
99
  requirement: !ruby/object:Gem::Requirement
69
- none: false
70
100
  requirements:
71
- - - ~>
101
+ - - "~>"
72
102
  - !ruby/object:Gem::Version
73
103
  version: '1.1'
74
104
  type: :development
75
105
  prerelease: false
76
106
  version_requirements: !ruby/object:Gem::Requirement
77
- none: false
78
107
  requirements:
79
- - - ~>
108
+ - - "~>"
80
109
  - !ruby/object:Gem::Version
81
110
  version: '1.1'
82
- description: This library aids one in handling money and different currencies.
111
+ description: A Ruby Library for dealing with money and currency conversion.
83
112
  email:
84
- - semmons99+RubyMoney@gmail.com
113
+ - shane@emmons.io
85
114
  executables: []
86
115
  extensions: []
87
116
  extra_rdoc_files: []
88
117
  files:
89
- - config/currency_iso.json
118
+ - ".coveralls.yml"
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - AUTHORS
122
+ - CHANGELOG.md
123
+ - CONTRIBUTING.md
124
+ - Gemfile
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
90
128
  - config/currency_backwards_compatible.json
129
+ - config/currency_iso.json
91
130
  - config/currency_non_iso.json
92
- - lib/money/currency.rb
93
- - lib/money/money/arithmetic.rb
94
- - lib/money/money/parsing.rb
95
- - lib/money/money/formatting.rb
96
- - lib/money/core_extensions.rb
97
- - lib/money/deprecations.rb
98
- - lib/money/currency/loader.rb
99
- - lib/money/currency/heuristics.rb
100
- - lib/money/bank/variable_exchange.rb
131
+ - lib/money.rb
101
132
  - lib/money/bank/base.rb
102
133
  - lib/money/bank/single_currency.rb
134
+ - 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
+ - lib/money/currency.rb
140
+ - lib/money/currency/heuristics.rb
141
+ - lib/money/currency/loader.rb
142
+ - lib/money/deprecations.rb
103
143
  - lib/money/money.rb
104
- - lib/money.rb
105
- - spec/support/default_currency_helper.rb
106
- - spec/currency_spec.rb
144
+ - lib/money/money/arithmetic.rb
145
+ - lib/money/money/formatting.rb
146
+ - lib/money/money/parsing.rb
147
+ - lib/money/version.rb
148
+ - money.gemspec
149
+ - spec/bank/base_spec.rb
150
+ - spec/bank/single_currency_spec.rb
151
+ - spec/bank/variable_exchange_spec.rb
107
152
  - spec/core_extensions_spec.rb
108
- - spec/money/parsing_spec.rb
153
+ - spec/currency/heuristics_spec.rb
154
+ - spec/currency_spec.rb
109
155
  - spec/money/arithmetic_spec.rb
156
+ - spec/money/deprecations_spec.rb
110
157
  - spec/money/formatting_spec.rb
158
+ - spec/money/parsing_spec.rb
111
159
  - spec/money_spec.rb
112
- - spec/currency/heuristics_spec.rb
113
160
  - spec/spec_helper.rb
114
- - spec/bank/single_currency_spec.rb
115
- - spec/bank/variable_exchange_spec.rb
116
- - spec/bank/base_spec.rb
117
- - CHANGELOG.md
118
- - LICENSE
119
- - README.md
120
- - Rakefile
121
- - money.gemspec
122
- homepage: http://rubymoney.github.com/money
161
+ - spec/support/default_currency_helper.rb
162
+ homepage: http://rubymoney.github.io/money
123
163
  licenses:
124
164
  - MIT
125
- post_install_message: ! "\nPlease note the following API changes in Money version
126
- 6\n\n - Money#amount, Money#dollars methods now return instances of BigDecimal (rather
127
- than Float).\n\nPlease read the migration notes at https://github.com/RubyMoney/money#migration-notes\nand
128
- choose the migration that best suits your application.\n\nTest responsibly :-)\n"
165
+ metadata: {}
166
+ post_install_message: |
167
+ Please note the following API changes in Money version 6
168
+
169
+ - Money#amount, Money#dollars methods now return instances of BigDecimal (rather than Float).
170
+
171
+ Please read the migration notes at https://github.com/RubyMoney/money#migration-notes
172
+ and choose the migration that best suits your application.
173
+
174
+ Test responsibly :-)
129
175
  rdoc_options: []
130
176
  require_paths:
131
177
  - lib
132
178
  required_ruby_version: !ruby/object:Gem::Requirement
133
- none: false
134
179
  requirements:
135
- - - ! '>='
180
+ - - ">="
136
181
  - !ruby/object:Gem::Version
137
- version: 1.8.7
182
+ version: '0'
138
183
  required_rubygems_version: !ruby/object:Gem::Requirement
139
- none: false
140
184
  requirements:
141
- - - ! '>='
185
+ - - ">="
142
186
  - !ruby/object:Gem::Version
143
187
  version: '0'
144
- segments:
145
- - 0
146
- hash: 2830931323134829129
147
188
  requirements: []
148
189
  rubyforge_project:
149
- rubygems_version: 1.8.23
190
+ rubygems_version: 2.2.0
150
191
  signing_key:
151
- specification_version: 3
152
- summary: Money and currency exchange support library.
153
- test_files: []
192
+ specification_version: 4
193
+ summary: A Ruby Library for dealing with money and currency conversion.
194
+ test_files:
195
+ - spec/bank/base_spec.rb
196
+ - spec/bank/single_currency_spec.rb
197
+ - spec/bank/variable_exchange_spec.rb
198
+ - spec/core_extensions_spec.rb
199
+ - spec/currency/heuristics_spec.rb
200
+ - spec/currency_spec.rb
201
+ - spec/money/arithmetic_spec.rb
202
+ - spec/money/deprecations_spec.rb
203
+ - spec/money/formatting_spec.rb
204
+ - spec/money/parsing_spec.rb
205
+ - spec/money_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/support/default_currency_helper.rb
208
+ has_rdoc: