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 +1 -1
- data/lib/simple_currency/currency_convertible.rb +4 -1
- data/simple_currency.gemspec +1 -1
- data/spec/simple_currency_spec.rb +6 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
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
|
-
|
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
|
|
data/simple_currency.gemspec
CHANGED
@@ -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.
|
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
|