has_money_fields 0.0.4 → 0.0.5
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/has_money_fields/version.rb +1 -1
- data/lib/has_money_fields.rb +2 -2
- data/spec/has_money_fields_spec.rb +22 -1
- metadata +2 -2
data/lib/has_money_fields.rb
CHANGED
@@ -10,8 +10,8 @@ module HasMoneyFields
|
|
10
10
|
|
11
11
|
args.each do |attr|
|
12
12
|
converter = Proc.new do |value|
|
13
|
-
# remove all non digit
|
14
|
-
value.gsub! /[
|
13
|
+
# remove all non digit characters from the price
|
14
|
+
value.gsub! /[^\d|\.|\,]/, "" if value.instance_of? String
|
15
15
|
if value.respond_to? :to_money
|
16
16
|
value.to_money
|
17
17
|
else
|
@@ -46,8 +46,29 @@ describe "Model with money fields" do
|
|
46
46
|
subject {@product}
|
47
47
|
|
48
48
|
its(:money_price){ should == 100000 }
|
49
|
-
its(:currency_price){ should == "USD" }
|
49
|
+
its(:currency_price){ should == "USD" }
|
50
50
|
end
|
51
|
+
|
52
|
+
context "with price with commas" do
|
53
|
+
before do
|
54
|
+
@product = Product.create! :price => "$1000,50 + VAT"
|
55
|
+
end
|
56
|
+
subject {@product}
|
57
|
+
|
58
|
+
its(:money_price){ should == 100050 }
|
59
|
+
its(:currency_price){ should == "USD" }
|
60
|
+
end
|
61
|
+
|
62
|
+
context "with price with periods" do
|
63
|
+
before do
|
64
|
+
@product = Product.create! :price => "$1000.50 + VAT"
|
65
|
+
end
|
66
|
+
subject {@product}
|
67
|
+
|
68
|
+
its(:money_price){ should == 100050 }
|
69
|
+
its(:currency_price){ should == "USD" }
|
70
|
+
end
|
71
|
+
|
51
72
|
|
52
73
|
context "with number only prices" do
|
53
74
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_money_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|