exchange 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -231,11 +231,11 @@ The options available are
231
231
  :app_id (default nil) The app id to use with your api request
232
232
  :protocol (default :http) The protocol to use with the request
233
233
 
234
- :allow_mixed_opterations (default true) If set to false, Operations with with different currencies raise errors.
234
+ :implicit_conversions (default true) If set to false, Operations with with different currencies raise errors.
235
235
 
236
- If you're afraid of mixed currency operations, just don't allow them
237
- Exchange.configuration.allow_mixed_operations = false
238
- 1.in(:usd) + 1.in(:eur) #=> MixedCurrencyError
236
+ If you want to maintain control over when a currency is converted, turn implicit conversions off
237
+ Exchange.configuration.implicit_conversions = false
238
+ 1.in(:usd) + 1.in(:eur) #=> raises ImplicitConversionDenied
239
239
 
240
240
  === Caching Options
241
241
 
@@ -1,5 +1,8 @@
1
1
  = Changes to Exchange
2
2
 
3
+ == 0.11.0
4
+ - Better implementation for preventing implicit conversions, if wished for: Now all operations including comparisons throw errors when implicit conversions are not allowed and currencies are to be converted implicitly.
5
+
3
6
  == 0.10.0
4
7
  - Changed the gem API to be less invasive in the numeric classes. The deprecated API had issues with three letter methods defined in active support, mainly the try method. The new API has just two methods, in(currency) and to(currency). There are no known conflicts at this time.
5
8
 
@@ -2,7 +2,7 @@ module Exchange
2
2
 
3
3
  # The current version of the exchange gem
4
4
  #
5
- VERSION = '0.10.2'
5
+ VERSION = '0.11.0'
6
6
 
7
7
  # The root installation path of the gem
8
8
  # @version 0.5
@@ -84,7 +84,7 @@ module Exchange
84
84
  :host => nil,
85
85
  :port => nil
86
86
  },
87
- :allow_mixed_operations => true
87
+ :implicit_conversions => true
88
88
  }
89
89
 
90
90
  # Initialize a new configuration. Takes a hash and/or a block. Lets you easily set the configuration the way you want it to be
@@ -93,10 +93,10 @@ module Exchange
93
93
  # @param [Hash] configuration The configuration as a hash
94
94
  # @param [Proc] block A block to yield the configuration with
95
95
  # @example Define the configuration with a hash
96
- # Exchange::Configuration.new(:allow_mixed_operations => false, :api => {:subclass => :open_exchange_rates, :retries => 2})
96
+ # Exchange::Configuration.new(:implicit_conversions => false, :api => {:subclass => :open_exchange_rates, :retries => 2})
97
97
  # @example Define the configuration with a block
98
98
  # Exchange::Configuration.new do |c|
99
- # c.allow_mixed_operations = false
99
+ # c.implicit_conversions = false
100
100
  # c.cache = {
101
101
  # :subclass => Exhange::Cache::Redis,
102
102
  # :expire => :hourly
@@ -115,28 +115,28 @@ module Exchange
115
115
  def reset
116
116
  api.reset
117
117
  cache.reset
118
- self.allow_mixed_operations = DEFAULTS[:allow_mixed_operations]
118
+ self.implicit_conversions = DEFAULTS[:implicit_conversions]
119
119
  end
120
120
 
121
- # Getter for the mixed operations configuration. If set to true, operations with mixed currencies will not raise errors
122
- # If set to false, mixed operations will raise errors
121
+ # Getter for the implicit Conversions configuration. If set to true, implicit conversions will not raise errors
122
+ # If set to false, implicit conversions will raise errors
123
123
  # @since 0.6
124
124
  # @version 0.6
125
- # @return [Boolean] True if mixed operations are allowed, false if not
125
+ # @return [Boolean] True if implicit conversions are allowed, false if not
126
126
  #
127
- def allow_mixed_operations
128
- @config[:allow_mixed_operations]
127
+ def implicit_conversions
128
+ @config[:implicit_conversions]
129
129
  end
130
130
 
131
- # Setter for the mixed operations configuration. If set to true, operations with mixed currencies will not raise errors
132
- # If set to false, mixed operations will raise errors
131
+ # Setter for the implicit conversions configuration. If set to true, implicit conversions will not raise errors
132
+ # If set to false, implicit conversions will raise errors
133
133
  # @since 0.6
134
134
  # @version 0.6
135
135
  # @param [Boolean] data The configuration to set
136
136
  # @return [Boolean] The configuration set
137
137
  #
138
- def allow_mixed_operations= data
139
- @config[:allow_mixed_operations] = data
138
+ def implicit_conversions= data
139
+ @config[:implicit_conversions] = data
140
140
  end
141
141
 
142
142
  # Setter for the api configuration.
@@ -169,11 +169,11 @@ module Exchange
169
169
  # Add value to the currency
170
170
  # @param [Integer, Float, Exchange::Money] other The value to be added to the currency. If an Exchange::Money, it is converted to the instance's currency and then the converted value is added.
171
171
  # @return [Exchange::Money] The currency with the added value
172
- # @raise [CurrencyMixError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
172
+ # @raise [ImplicitConversionError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
173
173
  # @example Configuration disallows mixed operations
174
- # Exchange.configuration.allow_mixed_operations = false
174
+ # Exchange.configuration.implicit_conversions = false
175
175
  # Exchange::Money.new(20,:nok) + Exchange::Money.new(20,:sek)
176
- # #=> #<CurrencyMixError "You tried to mix currencies">
176
+ # #=> #<ImplicitConversionError "You tried to mix currencies">
177
177
  # @example Configuration allows mixed operations (default)
178
178
  # Exchange::Money.new(20,:nok) + Exchange::Money.new(20,:sek)
179
179
  # #=> #<Exchange::Money @value=37.56 @currency=:nok>
@@ -185,11 +185,11 @@ module Exchange
185
185
  # Subtract a value from the currency
186
186
  # @param [Integer, Float, Exchange::Money] other The value to be subtracted from the currency. If an Exchange::Money, it is converted to the instance's currency and then subtracted from the converted value.
187
187
  # @return [Exchange::Money] The currency with the added value
188
- # @raise [CurrencyMixError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
189
- # @example Configuration disallows mixed operations
190
- # Exchange.configuration.allow_mixed_operations = false
188
+ # @raise [ImplicitConversionError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
189
+ # @example Configuration disallows implicit conversions
190
+ # Exchange.configuration.implicit_conversions = false
191
191
  # Exchange::Money.new(20,:nok) - Exchange::Money.new(20,:sek)
192
- # #=> #<CurrencyMixError "You tried to mix currencies">
192
+ # #=> #<ImplicitConversionError "You tried to mix currencies">
193
193
  # @example Configuration allows mixed operations (default)
194
194
  # Exchange::Money.new(20,:nok) - Exchange::Money.new(20,:sek)
195
195
  # #=> #<Exchange::Money @value=7.56 @currency=:nok>
@@ -201,11 +201,11 @@ module Exchange
201
201
  # Multiply a value with the currency
202
202
  # @param [Integer, Float, Exchange::Money] other The value to be multiplied with the currency. If an Exchange::Money, it is converted to the instance's currency and multiplied with the converted value.
203
203
  # @return [Exchange::Money] The currency with the multiplied value
204
- # @raise [CurrencyMixError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
204
+ # @raise [ImplicitConversionError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
205
205
  # @example Configuration disallows mixed operations
206
- # Exchange.configuration.allow_mixed_operations = false
206
+ # Exchange.configuration.implicit_conversions = false
207
207
  # Exchange::Money.new(20,:nok) * Exchange::Money.new(20,:sek)
208
- # #=> #<CurrencyMixError "You tried to mix currencies">
208
+ # #=> #<ImplicitConversionError "You tried to mix currencies">
209
209
  # @example Configuration allows mixed operations (default)
210
210
  # Exchange::Money.new(20,:nok) * Exchange::Money.new(20,:sek)
211
211
  # #=> #<Exchange::Money @value=70.56 @currency=:nok>
@@ -217,11 +217,11 @@ module Exchange
217
217
  # Divide the currency by a value
218
218
  # @param [Integer, Float, Exchange::Money] other The value to be divided by the currency. If an Exchange::Money, it is converted to the instance's currency and divided by the converted value.
219
219
  # @return [Exchange::Money] The currency with the divided value
220
- # @raise [CurrencyMixError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
220
+ # @raise [ImplicitConversionError] If the configuration does not allow mixed operations, this method will raise an error if two different currencies are used in the operation
221
221
  # @example Configuration disallows mixed operations
222
- # Exchange.configuration.allow_mixed_operations = false
222
+ # Exchange.configuration.implicit_conversions = false
223
223
  # Exchange::Money.new(20,:nok) / Exchange::Money.new(20,:sek)
224
- # #=> #<CurrencyMixError "You tried to mix currencies">
224
+ # #=> #<ImplicitConversionError "You tried to mix currencies">
225
225
  # @example Configuration allows mixed operations (default)
226
226
  # Exchange::Money.new(20,:nok) / Exchange::Money.new(20,:sek)
227
227
  # #=> #<Exchange::Money @value=1.56 @currency=:nok>
@@ -241,12 +241,13 @@ module Exchange
241
241
  # @example Compare a currency with a number, the value of the currency will get compared
242
242
  # Exchange::Money.new(35, :usd) == 35 #=> true
243
243
  # @since 0.1
244
- # @version 0.6
244
+ # @version 0.11
245
245
  #
246
246
  def == other
247
247
  if is_same_currency?(other)
248
248
  other.round.value == self.round.value
249
- elsif is_currency?(other)
249
+ elsif is_other_currency?(other)
250
+ test_for_currency_mix_error(other)
250
251
  other.to(currency, :at => other.time).round.value == self.round.value
251
252
  else
252
253
  value == other
@@ -258,7 +259,7 @@ module Exchange
258
259
  # @param [Whatever you want to throw at it] other The counterpart to compare
259
260
  # @return [Fixed] a number which can be used for sorting
260
261
  # @since 0.3
261
- # @version 0.6
262
+ # @version 0.11
262
263
  # @todo which historic conversion should be used when two are present?
263
264
  # @example Compare two currencies in terms of value
264
265
  # Exchange::Money.new(40, :usd) <=> Exchange::Money.new(28, :usd) #=> -1
@@ -271,6 +272,7 @@ module Exchange
271
272
  if is_same_currency?(other)
272
273
  value <=> other.value
273
274
  elsif is_other_currency?(other)
275
+ test_for_currency_mix_error(other)
274
276
  value <=> other.to(currency, :at => other.time).value
275
277
  else
276
278
  value <=> other
@@ -341,12 +343,12 @@ module Exchange
341
343
 
342
344
  # Test if another currency is used in an operation, and if so, if the operation is allowed
343
345
  # @param [Numeric, Exchange::Money] other The counterpart in the operation
344
- # @raise [CurrencyMixError] an error if mixing currencies is not allowed and currencies where mixed
346
+ # @raise [ImplicitConversionError] an error if mixing currencies is not allowed and currencies where mixed
345
347
  # @since 0.6
346
348
  # @version 0.6
347
349
  #
348
350
  def test_for_currency_mix_error other
349
- raise CurrencyMixError.new("You\'re trying to mix up #{currency} with #{other.currency}. You denied mixing currencies in the configuration, allow it or convert the currencies before mixing") if !Exchange.configuration.allow_mixed_operations && other.is_a?(Money) && other.currency != currency
351
+ raise ImplicitConversionError.new("You\'re trying to mix up #{currency} with #{other.currency}. You denied mixing currencies in the configuration, allow it or convert the currencies before mixing") if !Exchange.configuration.implicit_conversions && other.is_a?(Money) && other.currency != currency
350
352
  end
351
353
 
352
354
  # Helper method to raise a no rate error for a given currency if no rate is given
@@ -361,8 +363,8 @@ module Exchange
361
363
 
362
364
  end
363
365
 
364
- # The error that will get thrown when currencies get mixed up in base operations
366
+ # The error that will get thrown when implicit conversions take place and are not allowed
365
367
  #
366
- CurrencyMixError = Class.new(ArgumentError)
368
+ ImplicitConversionError = Class.new(StandardError)
367
369
 
368
370
  end
@@ -11,7 +11,7 @@ describe "Exchange::Configuration" do
11
11
  subject.cache.expire.should == :daily
12
12
  end
13
13
  it "should respond to all configuration getters and setters" do
14
- [:api, :allow_mixed_operations, :cache].each do |k|
14
+ [:api, :implicit_conversions, :cache].each do |k|
15
15
  subject.should be_respond_to(k)
16
16
  subject.should be_respond_to(:"#{k}=")
17
17
  end
@@ -59,7 +59,7 @@ describe "Exchange::Configuration" do
59
59
  :port => 112211,
60
60
  :path => 'PATH'
61
61
  }
62
- c.allow_mixed_operations = false
62
+ c.implicit_conversions = false
63
63
  }
64
64
  it "should restore the defaults" do
65
65
  subject.reset
@@ -70,7 +70,7 @@ describe "Exchange::Configuration" do
70
70
  subject.cache.host.should be_nil
71
71
  subject.cache.port.should be_nil
72
72
  subject.cache.path.should be_nil
73
- subject.allow_mixed_operations.should be_true
73
+ subject.implicit_conversions.should be_true
74
74
  end
75
75
  end
76
76
  after(:all) do
@@ -10,7 +10,7 @@ describe "Exchange::Money" do
10
10
  c.cache = {
11
11
  :subclass => :no_cache
12
12
  }
13
- c.allow_mixed_operations = true
13
+ c.implicit_conversions = true
14
14
  end
15
15
  end
16
16
  after(:all) do
@@ -60,15 +60,15 @@ describe "Exchange::Money" do
60
60
  subject.currency.should == :usd
61
61
  end
62
62
  it "should raise when currencies get mixed and the configuration does not allow it" do
63
- Exchange.configuration.allow_mixed_operations = false
64
- lambda { subject + Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
65
- Exchange.configuration.allow_mixed_operations = true
63
+ Exchange.configuration.implicit_conversions = false
64
+ lambda { subject + Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
65
+ Exchange.configuration.implicit_conversions = true
66
66
  end
67
67
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
68
- Exchange.configuration.allow_mixed_operations = false
68
+ Exchange.configuration.implicit_conversions = false
69
69
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
70
70
  lambda { subject + Exchange::Money.new(30, :usd) }.should_not raise_error
71
- Exchange.configuration.allow_mixed_operations = true
71
+ Exchange.configuration.implicit_conversions = true
72
72
  end
73
73
  context "modifying the base value" do
74
74
  before(:each) do
@@ -94,15 +94,15 @@ describe "Exchange::Money" do
94
94
  @instantiated.currency.should == :usd
95
95
  end
96
96
  it "should raise when currencies get mixed and the configuration does not allow it" do
97
- Exchange.configuration.allow_mixed_operations = false
98
- lambda { @instantiated += Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
99
- Exchange.configuration.allow_mixed_operations = true
97
+ Exchange.configuration.implicit_conversions = false
98
+ lambda { @instantiated += Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
99
+ Exchange.configuration.implicit_conversions = true
100
100
  end
101
101
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
102
- Exchange.configuration.allow_mixed_operations = false
102
+ Exchange.configuration.implicit_conversions = false
103
103
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
104
104
  lambda { @instantiated += Exchange::Money.new(30, :usd) }.should_not raise_error
105
- Exchange.configuration.allow_mixed_operations = true
105
+ Exchange.configuration.implicit_conversions = true
106
106
  end
107
107
  end
108
108
  end
@@ -119,20 +119,20 @@ describe "Exchange::Money" do
119
119
  end
120
120
  it "should be able to subtract another currency value" do
121
121
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
122
- Exchange.configuration.allow_mixed_operations = true
122
+ Exchange.configuration.implicit_conversions = true
123
123
  (subject - Exchange::Money.new(10, :chf)).value.round(2).should == 29.04
124
124
  (subject - Exchange::Money.new(23.3, :eur)).currency.should == :usd
125
125
  end
126
126
  it "should raise when currencies get mixed and the configuration does not allow it" do
127
- Exchange.configuration.allow_mixed_operations = false
128
- lambda { subject - Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
129
- Exchange.configuration.allow_mixed_operations = true
127
+ Exchange.configuration.implicit_conversions = false
128
+ lambda { subject - Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
129
+ Exchange.configuration.implicit_conversions = true
130
130
  end
131
131
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
132
- Exchange.configuration.allow_mixed_operations = false
132
+ Exchange.configuration.implicit_conversions = false
133
133
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
134
134
  lambda { subject - Exchange::Money.new(30, :usd) }.should_not raise_error
135
- Exchange.configuration.allow_mixed_operations = true
135
+ Exchange.configuration.implicit_conversions = true
136
136
  end
137
137
  context "modifying the base value" do
138
138
  before(:each) do
@@ -151,7 +151,7 @@ describe "Exchange::Money" do
151
151
  end
152
152
  it "should be able to subtract another currency value" do
153
153
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
154
- Exchange.configuration.allow_mixed_operations = true
154
+ Exchange.configuration.implicit_conversions = true
155
155
  added = (@instantiated -= Exchange::Money.new(10, :chf))
156
156
  added.value.round(2).should == 29.04
157
157
  added.currency.should == :usd
@@ -159,15 +159,15 @@ describe "Exchange::Money" do
159
159
  @instantiated.currency.should == :usd
160
160
  end
161
161
  it "should raise when currencies get mixed and the configuration does not allow it" do
162
- Exchange.configuration.allow_mixed_operations = false
163
- lambda { @instantiated -= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
164
- Exchange.configuration.allow_mixed_operations = true
162
+ Exchange.configuration.implicit_conversions = false
163
+ lambda { @instantiated -= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
164
+ Exchange.configuration.implicit_conversions = true
165
165
  end
166
166
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
167
- Exchange.configuration.allow_mixed_operations = false
167
+ Exchange.configuration.implicit_conversions = false
168
168
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
169
169
  lambda { @instantiated -= Exchange::Money.new(30, :usd) }.should_not raise_error
170
- Exchange.configuration.allow_mixed_operations = true
170
+ Exchange.configuration.implicit_conversions = true
171
171
  end
172
172
  end
173
173
  end
@@ -189,20 +189,20 @@ describe "Exchange::Money" do
189
189
  end
190
190
  it "should be able to multiply by another currency value" do
191
191
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
192
- Exchange.configuration.allow_mixed_operations = true
192
+ Exchange.configuration.implicit_conversions = true
193
193
  (subject * Exchange::Money.new(10, :chf)).value.round(1).should == 438.3
194
194
  (subject * Exchange::Money.new(23.3, :eur)).currency.should == :usd
195
195
  end
196
196
  it "should raise when currencies get mixed and the configuration does not allow it" do
197
- Exchange.configuration.allow_mixed_operations = false
198
- lambda { subject * Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
199
- Exchange.configuration.allow_mixed_operations = true
197
+ Exchange.configuration.implicit_conversions = false
198
+ lambda { subject * Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
199
+ Exchange.configuration.implicit_conversions = true
200
200
  end
201
201
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
202
- Exchange.configuration.allow_mixed_operations = false
202
+ Exchange.configuration.implicit_conversions = false
203
203
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
204
204
  lambda { subject * Exchange::Money.new(30, :usd) }.should_not raise_error
205
- Exchange.configuration.allow_mixed_operations = true
205
+ Exchange.configuration.implicit_conversions = true
206
206
  end
207
207
  context "modifying the base value" do
208
208
  before(:each) do
@@ -221,7 +221,7 @@ describe "Exchange::Money" do
221
221
  end
222
222
  it "should be able to multiply by another currency value" do
223
223
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
224
- Exchange.configuration.allow_mixed_operations = true
224
+ Exchange.configuration.implicit_conversions = true
225
225
  added = (@instantiated *= Exchange::Money.new(9, :chf))
226
226
  added.value.round(1).should == 394.50
227
227
  added.currency.should == :usd
@@ -229,15 +229,15 @@ describe "Exchange::Money" do
229
229
  @instantiated.currency.should == :usd
230
230
  end
231
231
  it "should raise when currencies get mixed and the configuration does not allow it" do
232
- Exchange.configuration.allow_mixed_operations = false
233
- lambda { @instantiated *= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
234
- Exchange.configuration.allow_mixed_operations = true
232
+ Exchange.configuration.implicit_conversions = false
233
+ lambda { @instantiated *= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
234
+ Exchange.configuration.implicit_conversions = true
235
235
  end
236
236
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
237
- Exchange.configuration.allow_mixed_operations = false
237
+ Exchange.configuration.implicit_conversions = false
238
238
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
239
239
  lambda { @instantiated *= Exchange::Money.new(30, :usd) }.should_not raise_error
240
- Exchange.configuration.allow_mixed_operations = true
240
+ Exchange.configuration.implicit_conversions = true
241
241
  end
242
242
  end
243
243
  end
@@ -266,20 +266,20 @@ describe "Exchange::Money" do
266
266
  end
267
267
  it "should be able to divide by another currency value" do
268
268
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
269
- Exchange.configuration.allow_mixed_operations = true
269
+ Exchange.configuration.implicit_conversions = true
270
270
  (subject / Exchange::Money.new(10, :chf)).value.round(2).should == BigDecimal.new("3.65")
271
271
  (subject / Exchange::Money.new(23.3, :eur)).currency.should == :usd
272
272
  end
273
273
  it "should raise when currencies get mixed and the configuration does not allow it" do
274
- Exchange.configuration.allow_mixed_operations = false
275
- lambda { subject / Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
276
- Exchange.configuration.allow_mixed_operations = true
274
+ Exchange.configuration.implicit_conversions = false
275
+ lambda { subject / Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
276
+ Exchange.configuration.implicit_conversions = true
277
277
  end
278
278
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
279
- Exchange.configuration.allow_mixed_operations = false
279
+ Exchange.configuration.implicit_conversions = false
280
280
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
281
281
  lambda { subject / Exchange::Money.new(30, :usd) }.should_not raise_error
282
- Exchange.configuration.allow_mixed_operations = true
282
+ Exchange.configuration.implicit_conversions = true
283
283
  end
284
284
  context "modifying the base value" do
285
285
  before(:each) do
@@ -298,7 +298,7 @@ describe "Exchange::Money" do
298
298
  end
299
299
  it "should be able to divide by another currency value" do
300
300
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
301
- Exchange.configuration.allow_mixed_operations = true
301
+ Exchange.configuration.implicit_conversions = true
302
302
  added = (@instantiated /= Exchange::Money.new(10, :chf))
303
303
  added.value.round(2).should == 3.65
304
304
  added.currency.should == :usd
@@ -306,15 +306,15 @@ describe "Exchange::Money" do
306
306
  @instantiated.currency.should == :usd
307
307
  end
308
308
  it "should raise when currencies get mixed and the configuration does not allow it" do
309
- Exchange.configuration.allow_mixed_operations = false
310
- lambda { @instantiated /= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::CurrencyMixError)
311
- Exchange.configuration.allow_mixed_operations = true
309
+ Exchange.configuration.implicit_conversions = false
310
+ lambda { @instantiated /= Exchange::Money.new(30, :chf) }.should raise_error(Exchange::ImplicitConversionError)
311
+ Exchange.configuration.implicit_conversions = true
312
312
  end
313
313
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
314
- Exchange.configuration.allow_mixed_operations = false
314
+ Exchange.configuration.implicit_conversions = false
315
315
  mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
316
316
  lambda { @instantiated /= Exchange::Money.new(30, :usd) }.should_not raise_error
317
- Exchange.configuration.allow_mixed_operations = true
317
+ Exchange.configuration.implicit_conversions = true
318
318
  end
319
319
  end
320
320
  end
@@ -348,6 +348,17 @@ describe "Exchange::Money" do
348
348
  mock_api("http://openexchangerates.org/api/historical/2011-01-01.json?app_id=", fixture('api_responses/example_historic_json.json'), 2)
349
349
  (comp3 == comp6).should be_false
350
350
  end
351
+ context "with implicit conversion turned off" do
352
+ before(:each) do
353
+ Exchange.configuration.implicit_conversions = false
354
+ end
355
+ after(:each) do
356
+ Exchange.configuration.implicit_conversions = true
357
+ end
358
+ it "should raise an error" do
359
+ lambda { comp3 == comp5 }.should raise_error(Exchange::ImplicitConversionError)
360
+ end
361
+ end
351
362
  end
352
363
  end
353
364
  describe "sorting" do
@@ -362,6 +373,17 @@ describe "Exchange::Money" do
362
373
  it "should sort and by doing conversions" do
363
374
  [subject, comp1, comp2, comp3, comp4].sort.should == [comp2, subject, comp1, comp4, comp3]
364
375
  end
376
+ context "with implicit conversion turned off" do
377
+ before(:each) do
378
+ Exchange.configuration.implicit_conversions = false
379
+ end
380
+ after(:each) do
381
+ Exchange.configuration.implicit_conversions = true
382
+ end
383
+ it "should raise an error" do
384
+ lambda { [subject, comp1, comp2, comp3, comp4].sort }.should raise_error(Exchange::ImplicitConversionError)
385
+ end
386
+ end
365
387
  end
366
388
  describe "round" do
367
389
  subject { Exchange::Money.new(40.123, :usd) }
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 10
9
- - 2
10
- version: 0.10.2
8
+ - 11
9
+ - 0
10
+ version: 0.11.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Beat Richartz