exchange 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,10 +40,16 @@ describe "Exchange::Currency" do
40
40
  it "should be able to add a float" do
41
41
  (subject + 40.5).value.should == 80.5
42
42
  end
43
+ it "should not modify the base value" do
44
+ (subject + 40.5).value.should == 80.5
45
+ subject.value.should == 40.0
46
+ end
43
47
  it "should be able to add another currency value" do
44
48
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
45
49
  (subject + Exchange::Currency.new(30, :chf)).value.round(2).should == 72.87
46
50
  (subject + Exchange::Currency.new(30, :sek)).currency.should == :usd
51
+ subject.value.round(2).should == 40
52
+ subject.currency.should == :usd
47
53
  end
48
54
  it "should raise when currencies get mixed and the configuration does not allow it" do
49
55
  Exchange.configuration.allow_mixed_operations = false
@@ -56,19 +62,58 @@ describe "Exchange::Currency" do
56
62
  lambda { subject + Exchange::Currency.new(30, :usd) }.should_not raise_error
57
63
  Exchange.configuration.allow_mixed_operations = true
58
64
  end
65
+ context "modifying the base value" do
66
+ before(:each) do
67
+ # subject does not eval correctly when used with modifiers
68
+ @instantiated = subject
69
+ end
70
+ it "should be able to add an integer" do
71
+ (@instantiated += 40).value.should == 80
72
+ end
73
+ it "should be able to add a float" do
74
+ (@instantiated += 40.5).value.should == 80.5
75
+ end
76
+ it "should modify the base value" do
77
+ (@instantiated += 40.5).value.should == 80.5
78
+ @instantiated.value.should == 80.5
79
+ end
80
+ it "should be able to add another currency value" do
81
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
82
+ added = (@instantiated += Exchange::Currency.new(30, :chf))
83
+ added.value.round(2).should == 72.87
84
+ added.currency.should == :usd
85
+ @instantiated.value.round(2).should == 72.87
86
+ @instantiated.currency.should == :usd
87
+ end
88
+ it "should raise when currencies get mixed and the configuration does not allow it" do
89
+ Exchange.configuration.allow_mixed_operations = false
90
+ lambda { @instantiated += Exchange::Currency.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
91
+ Exchange.configuration.allow_mixed_operations = true
92
+ end
93
+ it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
94
+ Exchange.configuration.allow_mixed_operations = false
95
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
96
+ lambda { @instantiated += Exchange::Currency.new(30, :usd) }.should_not raise_error
97
+ Exchange.configuration.allow_mixed_operations = true
98
+ end
99
+ end
59
100
  end
60
101
  describe "- other" do
61
102
  it "should be able to subtract an integer" do
62
- (subject + 40).value.should == 80
103
+ (subject - 40).value.should == 0
63
104
  end
64
105
  it "should be able to subtract a float" do
65
- (subject + 40.5).value.should == 80.5
106
+ (subject - 40.5).value.should == -0.5
107
+ end
108
+ it "should not modify the base value" do
109
+ (subject - 40).value.should == 0
110
+ subject.value.should == 40.0
66
111
  end
67
112
  it "should be able to subtract another currency value" do
68
113
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
69
114
  Exchange.configuration.allow_mixed_operations = true
70
- (subject + Exchange::Currency.new(10, :chf)).value.round(2).should == 50.96
71
- (subject + Exchange::Currency.new(23.3, :eur)).currency.should == :usd
115
+ (subject - Exchange::Currency.new(10, :chf)).value.round(2).should == 29.04
116
+ (subject - Exchange::Currency.new(23.3, :eur)).currency.should == :usd
72
117
  end
73
118
  it "should raise when currencies get mixed and the configuration does not allow it" do
74
119
  Exchange.configuration.allow_mixed_operations = false
@@ -81,6 +126,42 @@ describe "Exchange::Currency" do
81
126
  lambda { subject - Exchange::Currency.new(30, :usd) }.should_not raise_error
82
127
  Exchange.configuration.allow_mixed_operations = true
83
128
  end
129
+ context "modifying the base value" do
130
+ before(:each) do
131
+ # subject does not eval correctly when used with modifiers
132
+ @instantiated = subject
133
+ end
134
+ it "should be able to subtract an integer" do
135
+ (@instantiated -= 40).value.should == 0
136
+ end
137
+ it "should be able to subtract a float" do
138
+ (@instantiated -= 40.5).value.should == -0.5
139
+ end
140
+ it "should modify the base value" do
141
+ (@instantiated -= 40.5).value.should == -0.5
142
+ @instantiated.value.should == -0.5
143
+ end
144
+ it "should be able to subtract another currency value" do
145
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
146
+ Exchange.configuration.allow_mixed_operations = true
147
+ added = (@instantiated -= Exchange::Currency.new(10, :chf))
148
+ added.value.round(2).should == 29.04
149
+ added.currency.should == :usd
150
+ @instantiated.value.round(2).should == 29.04
151
+ @instantiated.currency.should == :usd
152
+ end
153
+ it "should raise when currencies get mixed and the configuration does not allow it" do
154
+ Exchange.configuration.allow_mixed_operations = false
155
+ lambda { @instantiated -= Exchange::Currency.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
156
+ Exchange.configuration.allow_mixed_operations = true
157
+ end
158
+ it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
159
+ Exchange.configuration.allow_mixed_operations = false
160
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
161
+ lambda { @instantiated -= Exchange::Currency.new(30, :usd) }.should_not raise_error
162
+ Exchange.configuration.allow_mixed_operations = true
163
+ end
164
+ end
84
165
  end
85
166
  describe "* other" do
86
167
  it "should be able to multiply by an integer" do
@@ -89,6 +170,10 @@ describe "Exchange::Currency" do
89
170
  it "should be able to multiply a float" do
90
171
  (subject * 40.5).value.should == 1620
91
172
  end
173
+ it "should not modify the base value" do
174
+ (subject * 40).value.should == 1600
175
+ subject.value.should == 40.0
176
+ end
92
177
  it "should be able to multiply by another currency value" do
93
178
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
94
179
  Exchange.configuration.allow_mixed_operations = true
@@ -106,15 +191,60 @@ describe "Exchange::Currency" do
106
191
  lambda { subject * Exchange::Currency.new(30, :usd) }.should_not raise_error
107
192
  Exchange.configuration.allow_mixed_operations = true
108
193
  end
194
+ context "modifying the base value" do
195
+ before(:each) do
196
+ # subject does not eval correctly when used with modifiers
197
+ @instantiated = subject
198
+ end
199
+ it "should be able to multiply by an integer" do
200
+ (@instantiated *= 40).value.should == 1600
201
+ end
202
+ it "should be able to multiply a float" do
203
+ (@instantiated *= 40.5).value.should == 1620
204
+ end
205
+ it "should modify the base value" do
206
+ (@instantiated *= 40.5).value.should == 1620
207
+ @instantiated.value.should == 1620
208
+ end
209
+ it "should be able to multiply by another currency value" do
210
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
211
+ Exchange.configuration.allow_mixed_operations = true
212
+ added = (@instantiated *= Exchange::Currency.new(9, :chf))
213
+ added.value.round(1).should == 394.50
214
+ added.currency.should == :usd
215
+ @instantiated.value.round(1).should == 394.50
216
+ @instantiated.currency.should == :usd
217
+ end
218
+ it "should raise when currencies get mixed and the configuration does not allow it" do
219
+ Exchange.configuration.allow_mixed_operations = false
220
+ lambda { @instantiated *= Exchange::Currency.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
221
+ Exchange.configuration.allow_mixed_operations = true
222
+ end
223
+ it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
224
+ Exchange.configuration.allow_mixed_operations = false
225
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
226
+ lambda { @instantiated *= Exchange::Currency.new(30, :usd) }.should_not raise_error
227
+ Exchange.configuration.allow_mixed_operations = true
228
+ end
229
+ end
109
230
  end
110
231
  describe "/ other" do
111
- it "should be able to multiply by an integer" do
232
+ it "should be able to divide by an integer" do
112
233
  (subject / 40).value.should == 1
113
234
  end
114
- it "should be able to multiply a float" do
235
+ it "should be able to divide by a float" do
115
236
  BigDecimal.new((subject / 40.5).value.to_s).round(4).should == 0.9877
116
237
  end
117
- it "should be able to multiply by another currency value" do
238
+ it "should not modify the base value" do
239
+ (subject / 40).value.should == 1
240
+ subject.value.should == 40.0
241
+ end
242
+ it "should modify the base value if the operator is used with =" do
243
+ instantiated = subject
244
+ (instantiated /= 40).value.should == 1
245
+ instantiated.value.should == 1
246
+ end
247
+ it "should be able to divide by another currency value" do
118
248
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
119
249
  Exchange.configuration.allow_mixed_operations = true
120
250
  (subject / Exchange::Currency.new(10, :chf)).value.round(2).should == BigDecimal.new("3.65")
@@ -131,6 +261,42 @@ describe "Exchange::Currency" do
131
261
  lambda { subject / Exchange::Currency.new(30, :usd) }.should_not raise_error
132
262
  Exchange.configuration.allow_mixed_operations = true
133
263
  end
264
+ context "modifying the base value" do
265
+ before(:each) do
266
+ # subject does not eval correctly when used with modifiers
267
+ @instantiated = subject
268
+ end
269
+ it "should be able to add an integer" do
270
+ (@instantiated /= 40).value.should == 1
271
+ end
272
+ it "should be able to multiply a float" do
273
+ (@instantiated /= 13.3).value.round(2).should == 3.01
274
+ end
275
+ it "should modify the base value" do
276
+ (@instantiated /= 13.3).value.round(2).should == 3.01
277
+ @instantiated.value.round(2).should == 3.01
278
+ end
279
+ it "should be able to divide by another currency value" do
280
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
281
+ Exchange.configuration.allow_mixed_operations = true
282
+ added = (@instantiated /= Exchange::Currency.new(10, :chf))
283
+ added.value.round(2).should == 3.65
284
+ added.currency.should == :usd
285
+ @instantiated.value.round(2).should == 3.65
286
+ @instantiated.currency.should == :usd
287
+ end
288
+ it "should raise when currencies get mixed and the configuration does not allow it" do
289
+ Exchange.configuration.allow_mixed_operations = false
290
+ lambda { @instantiated /= Exchange::Currency.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
291
+ Exchange.configuration.allow_mixed_operations = true
292
+ end
293
+ it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
294
+ Exchange.configuration.allow_mixed_operations = false
295
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
296
+ lambda { @instantiated /= Exchange::Currency.new(30, :usd) }.should_not raise_error
297
+ Exchange.configuration.allow_mixed_operations = true
298
+ end
299
+ end
134
300
  end
135
301
  describe "comparison" do
136
302
  subject { Exchange::Currency.new(40.123, :usd) }
@@ -185,6 +351,10 @@ describe "Exchange::Currency" do
185
351
  subject.round.currency.should == :usd
186
352
  subject.round.should be_kind_of Exchange::Currency
187
353
  end
354
+ it "should not modify the base value" do
355
+ subject.round.value.should == 40.12
356
+ subject.value.should == 40.123
357
+ end
188
358
  end
189
359
  context "with arguments" do
190
360
  it "should apply it to its number" do
@@ -207,6 +377,10 @@ describe "Exchange::Currency" do
207
377
  subject.ceil.currency.should == :omr
208
378
  subject.ceil.should be_kind_of Exchange::Currency
209
379
  end
380
+ it "should not modify the base value" do
381
+ subject.ceil.value.should == 40.124
382
+ subject.value.should == 40.1236
383
+ end
210
384
  end
211
385
  context "with arguments" do
212
386
  it "should apply it to its number" do
@@ -229,6 +403,10 @@ describe "Exchange::Currency" do
229
403
  subject.floor.currency.should == :jpy
230
404
  subject.floor.should be_kind_of Exchange::Currency
231
405
  end
406
+ it "should not modify the base value" do
407
+ subject.floor.value.should == 40
408
+ subject.value.should == 40.723
409
+ end
232
410
  end
233
411
  context "with arguments" do
234
412
  it "should apply it to its number" do
@@ -50,7 +50,7 @@ describe "Exchange::ExternalAPI::Call" do
50
50
  end
51
51
  it "should call the api and yield a block with the result" do
52
52
  Exchange::ExternalAPI::Call.new('XML_API', :format => :xml) do |result|
53
- result.to_s.should == Nokogiri.parse(fixture('api_responses/example_xml_api.xml')).to_s
53
+ result.to_s.should == Nokogiri::XML.parse(fixture('api_responses/example_xml_api.xml').sub("\n", '')).to_s
54
54
  end
55
55
  end
56
56
  context "with http errors" do
@@ -61,7 +61,7 @@ describe "Exchange::ExternalAPI::Call" do
61
61
  @count == 3 ? mock('opened', :read => fixture('api_responses/example_xml_api.xml')) : raise(OpenURI::HTTPError.new('404', 'URI'))
62
62
  end
63
63
  Exchange::ExternalAPI::Call.new('XML_API', :format => :xml) do |result|
64
- result.to_s.should == Nokogiri.parse(fixture('api_responses/example_xml_api.xml')).to_s
64
+ result.to_s.should == Nokogiri::XML.parse(fixture('api_responses/example_xml_api.xml').sub("\n", '')).to_s
65
65
  end
66
66
  end
67
67
  it "should raise if the maximum recall size is reached" do
@@ -11,7 +11,6 @@ rescue Bundler::BundlerError => e
11
11
  exit e.status_code
12
12
  end
13
13
 
14
- require 'shoulda'
15
14
  require 'exchange'
16
15
 
17
16
  module HelperMethods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: exchange
15
+ name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,13 +26,13 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: yard
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: 0.7.4
38
38
  type: :development
@@ -40,7 +40,7 @@ dependencies:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.7.4
46
46
  - !ruby/object:Gem::Dependency
@@ -59,22 +59,6 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.0.0
62
- - !ruby/object:Gem::Dependency
63
- name: jeweler
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 1.8.3
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: 1.8.3
78
62
  description: ! "The Exchange Gem gives you easy access to currency functions directly
79
63
  on your Numbers. Imagine a conversion as easy as \n 1.eur.to_usd\n or even better
80
64
  \n 1.eur.to_usd(:at => Time.now - 84600)\n which gets you an exchange at the
@@ -82,11 +66,10 @@ description: ! "The Exchange Gem gives you easy access to currency functions dir
82
66
  email: exchange_gem@gmail.com
83
67
  executables: []
84
68
  extensions: []
85
- extra_rdoc_files:
86
- - LICENSE.txt
87
- - README.rdoc
69
+ extra_rdoc_files: []
88
70
  files:
89
71
  - .document
72
+ - .gitignore
90
73
  - .rspec
91
74
  - .travis.yml
92
75
  - Gemfile
@@ -94,8 +77,9 @@ files:
94
77
  - LICENSE.txt
95
78
  - README.rdoc
96
79
  - Rakefile
97
- - VERSION
98
80
  - changelog.rdoc
81
+ - exchange-0.7.5.gem
82
+ - exchange-0.7.6.gem
99
83
  - exchange.gemspec
100
84
  - iso4217.yml
101
85
  - lib/core_extensions/conversability.rb
@@ -158,9 +142,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
142
  - - ! '>='
159
143
  - !ruby/object:Gem::Version
160
144
  version: '0'
161
- segments:
162
- - 0
163
- hash: 595056188354575082
164
145
  required_rubygems_version: !ruby/object:Gem::Requirement
165
146
  none: false
166
147
  requirements:
@@ -173,4 +154,29 @@ rubygems_version: 1.8.24
173
154
  signing_key:
174
155
  specification_version: 3
175
156
  summary: Simple Exchange Rate operations for your ruby app
176
- test_files: []
157
+ test_files:
158
+ - spec/core_extensions/conversability_spec.rb
159
+ - spec/exchange/cache/base_spec.rb
160
+ - spec/exchange/cache/file_spec.rb
161
+ - spec/exchange/cache/memcached_spec.rb
162
+ - spec/exchange/cache/no_cache_spec.rb
163
+ - spec/exchange/cache/rails_spec.rb
164
+ - spec/exchange/cache/redis_spec.rb
165
+ - spec/exchange/configuration_spec.rb
166
+ - spec/exchange/currency_spec.rb
167
+ - spec/exchange/external_api/base_spec.rb
168
+ - spec/exchange/external_api/call_spec.rb
169
+ - spec/exchange/external_api/currency_bot_spec.rb
170
+ - spec/exchange/external_api/ecb_spec.rb
171
+ - spec/exchange/external_api/xavier_media_spec.rb
172
+ - spec/exchange/gem_loader_spec.rb
173
+ - spec/exchange/helper_spec.rb
174
+ - spec/exchange/iso_4217_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/api_responses/example_ecb_xml_90d.xml
177
+ - spec/support/api_responses/example_ecb_xml_daily.xml
178
+ - spec/support/api_responses/example_ecb_xml_history.xml
179
+ - spec/support/api_responses/example_historic_json.json
180
+ - spec/support/api_responses/example_json_api.json
181
+ - spec/support/api_responses/example_xml_api.xml
182
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.0