money 3.1.0.pre3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile DELETED
@@ -1,49 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
-
5
- CLOBBER << 'pkg'
6
-
7
- begin
8
- require 'jeweler'
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = "money"
11
- gem.summary = "Money and currency exchange support library"
12
- gem.description = "Money and currency exchange support library."
13
- gem.email = "hongli@phusion.nl"
14
- gem.homepage = "http://money.rubyforge.org/"
15
- gem.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin", "Shane Emmons", "Simone Carletti"]
16
- gem.rubyforge_project = "money"
17
- gem.add_development_dependency "rspec", ">= 1.2.9"
18
- gem.add_development_dependency "hanna", ">= 0.1.12"
19
- end
20
- Jeweler::GemcutterTasks.new
21
- Jeweler::RubyforgeTasks.new do |gem|
22
- gem.remote_doc_path = ""
23
- end
24
- rescue LoadError
25
- puts "Jeweler not available. Install it with: gem install jeweler"
26
- end
27
-
28
- require 'spec/rake/spectask'
29
- Spec::Rake::SpecTask.new(:test) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.spec_files = Dir['spec/**/*_spec.rb']
32
- spec.spec_opts << '--color'
33
- end
34
-
35
- task :spec => :check_dependencies
36
-
37
- task :default => :spec
38
-
39
- require 'hanna/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
-
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.main = 'README.rdoc'
45
- rdoc.title = "money #{version}"
46
- rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc')
47
- rdoc.rdoc_files.include('lib/**/*.rb')
48
- rdoc.options << '-U'
49
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 3.1.0.pre3
data/money.gemspec DELETED
@@ -1,77 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{money}
8
- s.version = "3.1.0.pre3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Tobias Luetke", "Hongli Lai", "Jeremy McNevin", "Shane Emmons", "Simone Carletti"]
12
- s.date = %q{2010-08-31}
13
- s.description = %q{Money and currency exchange support library.}
14
- s.email = %q{hongli@phusion.nl}
15
- s.extra_rdoc_files = [
16
- "CHANGELOG.rdoc",
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".gitignore",
23
- "CHANGELOG.rdoc",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "lib/money.rb",
29
- "lib/money/bank/base.rb",
30
- "lib/money/bank/variable_exchange.rb",
31
- "lib/money/core_extensions.rb",
32
- "lib/money/currency.rb",
33
- "lib/money/defaults.rb",
34
- "lib/money/deprecations.rb",
35
- "lib/money/money.rb",
36
- "money.gemspec",
37
- "spec/bank/base_spec.rb",
38
- "spec/bank/variable_exchange_spec.rb",
39
- "spec/core_extensions_spec.rb",
40
- "spec/currency_spec.rb",
41
- "spec/deprecations_spec.rb",
42
- "spec/money_spec.rb",
43
- "spec/spec_helper.rb"
44
- ]
45
- s.homepage = %q{http://money.rubyforge.org/}
46
- s.rdoc_options = ["--charset=UTF-8"]
47
- s.require_paths = ["lib"]
48
- s.rubyforge_project = %q{money}
49
- s.rubygems_version = %q{1.3.7}
50
- s.summary = %q{Money and currency exchange support library}
51
- s.test_files = [
52
- "spec/bank/base_spec.rb",
53
- "spec/bank/variable_exchange_spec.rb",
54
- "spec/core_extensions_spec.rb",
55
- "spec/currency_spec.rb",
56
- "spec/deprecations_spec.rb",
57
- "spec/money_spec.rb",
58
- "spec/spec_helper.rb"
59
- ]
60
-
61
- if s.respond_to? :specification_version then
62
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
- s.specification_version = 3
64
-
65
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
67
- s.add_development_dependency(%q<hanna>, [">= 0.1.12"])
68
- else
69
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
- s.add_dependency(%q<hanna>, [">= 0.1.12"])
71
- end
72
- else
73
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
74
- s.add_dependency(%q<hanna>, [">= 0.1.12"])
75
- end
76
- end
77
-
@@ -1,78 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Money::Bank::Base do
4
- before :each do
5
- @bank = Money::Bank::Base.new
6
- end
7
-
8
- describe '#new with &block' do
9
- it 'should store @rounding_method' do
10
- proc = Proc.new{|n| n.ceil}
11
- bank = Money::Bank::Base.new(&proc)
12
- bank.rounding_method.should == proc
13
- end
14
- end
15
-
16
- describe '#setup' do
17
- it 'should call #setup after #initialize' do
18
- class MyBank < Money::Bank::Base
19
- attr_reader :setup_called
20
-
21
- def setup
22
- @setup_called = true
23
- end
24
- end
25
-
26
- bank = MyBank.new
27
- bank.setup_called.should == true
28
- end
29
- end
30
-
31
- describe '#exchange' do
32
- it 'should raise NotImplementedError' do
33
- lambda { @bank.exchange(100, 'USD', 'EUR') }.should raise_exception(NotImplementedError)
34
- end
35
- end
36
-
37
- describe '#exchange_with' do
38
- it 'should raise NotImplementedError' do
39
- lambda { @bank.exchange_with(Money.new(100, 'USD'), 'EUR') }.should raise_exception(NotImplementedError)
40
- end
41
- end
42
-
43
- describe '#same_currency?' do
44
- it 'should accept str/str' do
45
- lambda{@bank.send(:same_currency?, 'USD', 'EUR')}.should_not raise_exception
46
- end
47
-
48
- it 'should accept currency/str' do
49
- lambda{@bank.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR')}.should_not raise_exception
50
- end
51
-
52
- it 'should accept str/currency' do
53
- lambda{@bank.send(:same_currency?, 'USD', Money::Currency.wrap('EUR'))}.should_not raise_exception
54
- end
55
-
56
- it 'should accept currency/currency' do
57
- lambda{@bank.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR'))}.should_not raise_exception
58
- end
59
-
60
- it 'should return `true` when currencies match' do
61
- @bank.send(:same_currency?, 'USD', 'USD').should == true
62
- @bank.send(:same_currency?, Money::Currency.wrap('USD'), 'USD').should == true
63
- @bank.send(:same_currency?, 'USD', Money::Currency.wrap('USD')).should == true
64
- @bank.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('USD')).should == true
65
- end
66
-
67
- it 'should return `false` when currencies do not match' do
68
- @bank.send(:same_currency?, 'USD', 'EUR').should == false
69
- @bank.send(:same_currency?, Money::Currency.wrap('USD'), 'EUR').should == false
70
- @bank.send(:same_currency?, 'USD', Money::Currency.wrap('EUR')).should == false
71
- @bank.send(:same_currency?, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')).should == false
72
- end
73
-
74
- it 'should raise an UnknownCurrency exception when an unknown currency is passed' do
75
- lambda{@bank.send(:same_currency?, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
76
- end
77
- end
78
- end
@@ -1,311 +0,0 @@
1
- require "spec_helper"
2
- require "json"
3
- require "yaml"
4
-
5
- describe Money::Bank::VariableExchange do
6
-
7
- describe '#new without block' do
8
- before :each do
9
- @bank = Money::Bank::VariableExchange.new
10
- end
11
-
12
- describe '#exchange' do
13
- before :each do
14
- @bank.send(:set_rate, 'USD', 'EUR', 1.33)
15
- end
16
-
17
- it 'should accept str/str' do
18
- lambda{@bank.exchange(100, 'USD', 'EUR')}.should_not raise_exception
19
- end
20
-
21
- it 'should accept currency/str' do
22
- lambda{@bank.exchange(100, Money::Currency.wrap('USD'), 'EUR')}.should_not raise_exception
23
- end
24
-
25
- it 'should accept str/currency' do
26
- lambda{@bank.exchange(100, 'USD', Money::Currency.wrap('EUR'))}.should_not raise_exception
27
- end
28
-
29
- it 'should accept currency/currency' do
30
- lambda{@bank.exchange(100, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR'))}.should_not raise_exception
31
- end
32
-
33
- it 'should exchange one currency to another' do
34
- @bank.exchange(100, 'USD', 'EUR').should == 133
35
- end
36
-
37
- it 'should truncate extra digits' do
38
- @bank.exchange(10, 'USD', 'EUR').should == 13
39
- end
40
-
41
- it 'should raise an UnknownCurrency exception when an unknown currency is requested' do
42
- lambda{@bank.exchange(100, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
43
- end
44
-
45
- it 'should raise an UnknownRate exception when an unknown rate is requested' do
46
- lambda{@bank.exchange(100, 'USD', 'JPY')}.should raise_exception(Money::Bank::UnknownRate)
47
- end
48
-
49
- it 'should round the exchanged result down' do
50
- @bank.add_rate("USD", "EUR", 0.788332676)
51
- @bank.add_rate("EUR", "YEN", 122.631477)
52
- @bank.exchange(10_00, "USD", "EUR").should == 788
53
- @bank.exchange(500_00, "EUR", "YEN").should == 6131573
54
- end
55
-
56
- it 'should accept a custom truncation method' do
57
- proc = Proc.new { |n| n.ceil }
58
- @bank.exchange(10, 'USD', 'EUR', &proc).should == 14
59
- end
60
-
61
-
62
- context 'sterling to euros using a rate of 1.39' do
63
- it 'returns the correct amount' do
64
- @bank.add_rate('GBP', 'EUR', 1.38)
65
- @bank.exchange(10000, 'GBP', 'EUR').should == 13800
66
- end
67
- end
68
-
69
- context 'dollars to euros using a rate of 0.86' do
70
- it 'returns the correct amount' do
71
- @bank.add_rate('USD', 'EUR', 0.86)
72
- @bank.exchange(10000, 'USD', 'EUR').should == 8600
73
- end
74
- end
75
-
76
- context 'TND to USD using a rate of 0.67138' do
77
- it 'returns the correct amount' do
78
- @bank.add_rate('TND', 'USD', 0.67138)
79
- @bank.exchange(1000, 'TND', 'USD').should == 67
80
- end
81
- end
82
-
83
- context 'USD to TND using a rate of 1.32862' do
84
- it 'returns the correct amount' do
85
- @bank.add_rate('USD', 'TND', 1.32862)
86
- @bank.exchange(1000, 'USD', 'TND').should == 13286
87
- end
88
- end
89
- end
90
-
91
- describe '#exchange_with' do
92
- before :each do
93
- @bank.send(:set_rate, 'USD', 'EUR', 1.33)
94
- end
95
-
96
- it 'should accept str' do
97
- lambda{@bank.exchange_with(Money.new(100, 'USD'), 'EUR')}.should_not raise_exception
98
- end
99
-
100
- it 'should accept currency' do
101
- lambda{@bank.exchange_with(Money.new(100, 'USD'), Money::Currency.wrap('EUR'))}.should_not raise_exception
102
- end
103
-
104
- it 'should exchange one currency to another' do
105
- @bank.exchange_with(Money.new(100, 'USD'), 'EUR').should == Money.new(133, 'EUR')
106
- end
107
-
108
- it 'should truncate extra digits' do
109
- @bank.exchange_with(Money.new(10, 'USD'), 'EUR').should == Money.new(13, 'EUR')
110
- end
111
-
112
- it 'should raise an UnknownCurrency exception when an unknown currency is requested' do
113
- lambda{@bank.exchange_with(Money.new(100, 'USD'), 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
114
- end
115
-
116
- it 'should raise an UnknownRate exception when an unknown rate is requested' do
117
- lambda{@bank.exchange_with(Money.new(100, 'USD'), 'JPY')}.should raise_exception(Money::Bank::UnknownRate)
118
- end
119
-
120
- #it 'should round the exchanged result down' do
121
- # @bank.add_rate("USD", "EUR", 0.788332676)
122
- # @bank.add_rate("EUR", "YEN", 122.631477)
123
- # @bank.exchange_with(Money.new(10_00, "USD"), "EUR").should == Money.new(788, "EUR")
124
- # @bank.exchange_with(Money.new(500_00, "EUR"), "YEN").should == Money.new(6131573, "YEN")
125
- #end
126
-
127
- it 'should accept a custom truncation method' do
128
- proc = Proc.new { |n| n.ceil }
129
- @bank.exchange_with(Money.new(10, 'USD'), 'EUR', &proc).should == Money.new(14, 'EUR')
130
- end
131
- end
132
-
133
- describe "#add_rate" do
134
- it "should add rates correctly" do
135
- @bank.add_rate("USD", "EUR", 0.788332676)
136
- @bank.add_rate("EUR", "YEN", 122.631477)
137
-
138
- @bank.instance_variable_get(:@rates)['USD_TO_EUR'].should == 0.788332676
139
- @bank.instance_variable_get(:@rates)['EUR_TO_JPY'].should == 122.631477
140
- end
141
-
142
- it "should treat currency names case-insensitively" do
143
- @bank.add_rate("usd", "eur", 1)
144
- @bank.instance_variable_get(:@rates)['USD_TO_EUR'].should == 1
145
- end
146
- end
147
-
148
- describe '#set_rate' do
149
- it 'should set a rate' do
150
- @bank.set_rate('USD', 'EUR', 1.25)
151
- @bank.instance_variable_get(:@rates)['USD_TO_EUR'].should == 1.25
152
- end
153
-
154
- it 'should raise an UnknownCurrency exception when an unknown currency is passed' do
155
- lambda{ @bank.set_rate('AAA', 'BBB', 1.25) }.should raise_exception(Money::Currency::UnknownCurrency)
156
- end
157
- end
158
-
159
- describe '#get_rate' do
160
- it 'should return a rate' do
161
- @bank.set_rate('USD', 'EUR', 1.25)
162
- @bank.get_rate('USD', 'EUR').should == 1.25
163
- end
164
-
165
- it 'should raise an UnknownCurrency exception when an unknown currency is requested' do
166
- lambda{ @bank.get_rate('AAA', 'BBB') }.should raise_exception(Money::Currency::UnknownCurrency)
167
- end
168
- end
169
-
170
- describe '#export_rates' do
171
- before :each do
172
- @bank.set_rate('USD', 'EUR', 1.25)
173
- @bank.set_rate('USD', 'JPY', 2.55)
174
- end
175
-
176
- describe 'with format == :json' do
177
- it 'should return rates formatted as json' do
178
- rates_as_json = '{"USD_TO_EUR":1.25,"USD_TO_JPY":2.55}'
179
- @bank.export_rates(:json).should == rates_as_json
180
- end
181
- end
182
-
183
- describe 'with format == :ruby' do
184
- it 'should return rates formatted as ruby objects' do
185
- rates = {"USD_TO_EUR"=>1.25,"USD_TO_JPY"=>2.55}
186
- @bank.export_rates(:ruby).should == Marshal.dump(rates)
187
- end
188
- end
189
-
190
- describe 'with format == :yaml' do
191
- it 'should return rates formatted as yaml' do
192
- rates_as_yaml = "--- \nUSD_TO_EUR: 1.25\nUSD_TO_JPY: 2.55\n"
193
- @bank.export_rates(:yaml).should == rates_as_yaml
194
- end
195
- end
196
-
197
- describe 'with unknown format' do
198
- it 'should raise `UnknownRateFormat`' do
199
- lambda{@bank.export_rates(:foo)}.should raise_error Money::Bank::UnknownRateFormat
200
- end
201
- end
202
-
203
- describe 'with :file provided' do
204
- it 'should write rates to file' do
205
- f = mock('IO')
206
- File.should_receive(:open).with('null', 'w').and_return(f)
207
- f.should_receive(:write).with('{"USD_TO_EUR":1.25,"USD_TO_JPY":2.55}')
208
-
209
- @bank.export_rates(:json, 'null')
210
- end
211
- end
212
- end
213
-
214
- describe '#import_rates' do
215
- describe 'with format == :json' do
216
- it 'should load the rates provided' do
217
- s = '{"USD_TO_EUR":1.25,"USD_TO_JPY":2.55}'
218
- @bank.import_rates(:json, s)
219
- @bank.get_rate('USD', 'EUR').should == 1.25
220
- @bank.get_rate('USD', 'JPY').should == 2.55
221
- end
222
- end
223
-
224
- describe 'with format == :ruby' do
225
- it 'should load the rates provided' do
226
- s = Marshal.dump({"USD_TO_EUR"=>1.25,"USD_TO_JPY"=>2.55})
227
- @bank.import_rates(:ruby, s)
228
- @bank.get_rate('USD', 'EUR').should == 1.25
229
- @bank.get_rate('USD', 'JPY').should == 2.55
230
- end
231
- end
232
-
233
- describe 'with format == :yaml' do
234
- it 'should load the rates provided' do
235
- s = "--- \nUSD_TO_EUR: 1.25\nUSD_TO_JPY: 2.55\n"
236
- @bank.import_rates(:yaml, s)
237
- @bank.get_rate('USD', 'EUR').should == 1.25
238
- @bank.get_rate('USD', 'JPY').should == 2.55
239
- end
240
- end
241
-
242
- describe 'with unknown format' do
243
- it 'should raise `UnknownRateFormat`' do
244
- lambda{@bank.import_rates(:foo, "")}.should raise_error Money::Bank::UnknownRateFormat
245
- end
246
- end
247
- end
248
-
249
- describe '#rate_key_for' do
250
- it 'should accept str/str' do
251
- lambda{@bank.send(:rate_key_for, 'USD', 'EUR')}.should_not raise_exception
252
- end
253
-
254
- it 'should accept currency/str' do
255
- lambda{@bank.send(:rate_key_for, Money::Currency.wrap('USD'), 'EUR')}.should_not raise_exception
256
- end
257
-
258
- it 'should accept str/currency' do
259
- lambda{@bank.send(:rate_key_for, 'USD', Money::Currency.wrap('EUR'))}.should_not raise_exception
260
- end
261
-
262
- it 'should accept currency/currency' do
263
- lambda{@bank.send(:rate_key_for, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR'))}.should_not raise_exception
264
- end
265
-
266
- it 'should return a hashkey based on the passed arguments' do
267
- @bank.send(:rate_key_for, 'USD', 'EUR').should == 'USD_TO_EUR'
268
- @bank.send(:rate_key_for, Money::Currency.wrap('USD'), 'EUR').should == 'USD_TO_EUR'
269
- @bank.send(:rate_key_for, 'USD', Money::Currency.wrap('EUR')).should == 'USD_TO_EUR'
270
- @bank.send(:rate_key_for, Money::Currency.wrap('USD'), Money::Currency.wrap('EUR')).should == 'USD_TO_EUR'
271
- end
272
-
273
- it 'should raise an UnknownCurrency exception when an unknown currency is passed' do
274
- lambda{@bank.send(:rate_key_for, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
275
- end
276
- end
277
-
278
- end
279
-
280
-
281
- describe '#new with &block' do
282
- before :each do
283
- proc = Proc.new { |n| n.ceil }
284
- @bank = Money::Bank::VariableExchange.new(&proc)
285
- @bank.add_rate('USD', 'EUR', 1.33)
286
- end
287
-
288
- describe '#exchange' do
289
- it 'should use a stored truncation method' do
290
- @bank.exchange(10, 'USD', 'EUR').should == 14
291
- end
292
-
293
- it 'should use a custom truncation method over a stored one' do
294
- proc = Proc.new { |n| n.ceil + 1 }
295
- @bank.exchange(10, 'USD', 'EUR', &proc).should == 15
296
- end
297
- end
298
-
299
- describe '#exchange_with' do
300
- it 'should use a stored truncation method' do
301
- @bank.exchange_with(Money.new(10, 'USD'), 'EUR').should == Money.new(14, 'EUR')
302
- end
303
-
304
- it 'should use a custom truncation method over a stored one' do
305
- proc = Proc.new { |n| n.ceil + 1 }
306
- @bank.exchange_with(Money.new(10, 'USD'), 'EUR', &proc).should == Money.new(15, 'EUR')
307
- end
308
- end
309
- end
310
-
311
- end