sevenwire-money 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/money/errors.rb +1 -0
- data/lib/money/money.rb +3 -0
- data/money.gemspec +1 -1
- data/test/money_spec.rb +15 -0
- metadata +1 -1
data/lib/money/errors.rb
CHANGED
data/lib/money/money.rb
CHANGED
|
@@ -55,6 +55,9 @@ class Money
|
|
|
55
55
|
# By default, it will accept money in cents, however,
|
|
56
56
|
# you can also pass millicents by specifying :units => :millicents.
|
|
57
57
|
def initialize(money, *args)
|
|
58
|
+
raise Money::UnknownMonetaryValue, %{There is no way to turn "#{money}" into money} if !money.nil? && !money.is_a?(Numeric)
|
|
59
|
+
|
|
60
|
+
money = 0 if money.nil?
|
|
58
61
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
59
62
|
|
|
60
63
|
if options[:units] == :millicents
|
data/money.gemspec
CHANGED
data/test/money_spec.rb
CHANGED
|
@@ -5,6 +5,21 @@ require 'money/currencies'
|
|
|
5
5
|
|
|
6
6
|
describe Money do
|
|
7
7
|
|
|
8
|
+
it "returns 0 if nil is passed in" do
|
|
9
|
+
Money.new(nil).should == 0.to_money
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "raises Money::UnknownMonetaryValue if passed something other than nil or a Numeric" do
|
|
13
|
+
block = lambda { Money.new("") }
|
|
14
|
+
block.should raise_error(Money::UnknownMonetaryValue)
|
|
15
|
+
|
|
16
|
+
block = lambda { Money.new("asdf") }
|
|
17
|
+
block.should raise_error(Money::UnknownMonetaryValue)
|
|
18
|
+
|
|
19
|
+
block = lambda { Money.new("100") }
|
|
20
|
+
block.should raise_error(Money::UnknownMonetaryValue)
|
|
21
|
+
end
|
|
22
|
+
|
|
8
23
|
it "is associated to the singleton instance of VariableExchangeBank by default" do
|
|
9
24
|
Money.new(0).bank.object_id.should == Money::VariableExchangeBank.instance.object_id
|
|
10
25
|
end
|