exchange 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7183dab51d6b41d1572ba98dcaf30d2be590ade
4
- data.tar.gz: 345945166e17a720eb7cb04f41e4571d8d4f3403
3
+ metadata.gz: bf3c864cb71b80fb76c0640c830188755db7656f
4
+ data.tar.gz: c1eba4fec08d8a6b832df66d1dbe6c7149a5db9c
5
5
  SHA512:
6
- metadata.gz: b99284cae296720f914a5e4acc10a35c2852f041e0edf3a542a90554ada02696549ac879e95c98aeedd9668a59f409717401279167da1cca868bb0af95fdaaef
7
- data.tar.gz: c111ad35f96feea8915f815f911c9fcd408055851c8d1a2f03172ee09312b8f265bf93961457d70c85c0decd44dd2eb8123af2bc32fa9032961684f9615a52f6
6
+ metadata.gz: 18dc3ab48911a9d38f400326c3b46fc05ac437082fcd90931d036f8ee65ebb0dafc6ca974704253d8dcb6297d23389fa69a148712c8d0c4c9770f5d5d9917570
7
+ data.tar.gz: 38562921308eea56eec9dbde8eb9d69aa146dbbcf7466e7d644339ed84ec0492d8628a7c0973edfdb9cf64312f78a815b5578d21772fd0c294714ffbe49a573f
@@ -8,7 +8,7 @@ module Exchange
8
8
 
9
9
  # The current version of the exchange gem
10
10
  #
11
- VERSION = '1.2.1'.freeze
11
+ VERSION = '1.2.2'.freeze
12
12
 
13
13
  # The root installation path of the gem
14
14
  # @version 0.5
@@ -77,15 +77,17 @@ module Exchange
77
77
  #
78
78
  def install_money_setter attribute, options={}
79
79
  define_method :"#{attribute}_with_exchange_typecasting=" do |data|
80
- att = send(attribute)
80
+ att = send(attribute)
81
+ currency = evaluate_money_option(options[:currency])
82
+
81
83
  attribute_setter = :"#{attribute}_without_exchange_typecasting="
82
84
 
83
85
  send(attribute_setter, if !data.respond_to?(:currency)
84
86
  data
85
- elsif att.currency == data.currency
87
+ elsif currency == data.currency
86
88
  data.value
87
- elsif att.currency != data.currency
88
- data.to(att.currency).value
89
+ elsif currency != data.currency
90
+ data.to(currency).value
89
91
  end)
90
92
  end
91
93
  exchange_typecasting_alias_method_chain attribute, '='
@@ -99,6 +99,25 @@ describe "Exchange::Typecasting" do
99
99
  subject.price = 0.83.in(:usd)
100
100
  subject.price.should == 0.62.in(:eur)
101
101
  end
102
+ context "when the preset value is nil" do
103
+ before(:each) do
104
+ subject.price = nil
105
+ subject.manager.currency = :eur
106
+ end
107
+ it "should set the value if the given value is numeric" do
108
+ subject.price = 0.83
109
+ subject.price.should == 0.83.in(:eur)
110
+ end
111
+ it "should not convert the value if the given value is in the same currency" do
112
+ subject.price = 0.83.in(:eur)
113
+ subject.price.should == 0.83.in(:eur)
114
+ end
115
+ it "should convert the value if the given value is in another currency" do
116
+ mock_api("http://api.finance.xaviermedia.com/api/#{Time.now.strftime("%Y/%m/%d")}.xml", fixture('api_responses/example_xml_api.xml'))
117
+ subject.price = 0.83.in(:usd)
118
+ subject.price.should == 0.62.in(:eur)
119
+ end
120
+ end
102
121
  end
103
122
 
104
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beat Richartz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
- rubygems_version: 2.1.11
194
+ rubygems_version: 2.2.1
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Simple Money handling for your ruby app