simple_currency 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -26,7 +26,9 @@ module CurrencyConvertible
26
26
  raise unless @original # Must be called after a _from have set the @original currency
27
27
 
28
28
  original = @original
29
- amount = self
29
+
30
+ negative = (self < 0)
31
+ amount = self.abs
30
32
 
31
33
  # Check if there's a cached exchange rate for today
32
34
  if defined?(Rails) && cached_amount = check_cache(original, target, amount)
@@ -53,6 +55,7 @@ module CurrencyConvertible
53
55
  _to(target)
54
56
  end unless self.respond_to?(:"to_#{target}")
55
57
 
58
+ return -(result) if negative
56
59
  result
57
60
  end
58
61
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_currency}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
@@ -41,6 +41,12 @@ describe "SimpleCurrency" do
41
41
  expect {1_000_000_000.usd.to_eur}.to raise_error("The amount should be between 0 and 999999999")
42
42
  end
43
43
 
44
+ it "handles a negative value returning a negative as well" do
45
+ mock_uri('usd', 'eur', 1, 1.5)
46
+
47
+ -1.usd.to_eur.should == -1.5
48
+ end
49
+
44
50
  context "when Rails is present" do
45
51
 
46
52
  before(:all) do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Oriol Gual