has_money_fields 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
6
  Gemfile.lock
7
+ sqlite3
data/History.md CHANGED
@@ -1,11 +1,17 @@
1
1
 
2
- 0.0.2 / 2011-07-14
2
+ 0.0.3 / 2012-05-17
3
+ ==================
4
+
5
+ * Fix bug appearing when field include text like "0.99 + VAT"
6
+ * Fix tests not running on ruby 1.9.2
7
+
8
+ 0.0.2 / 2011-07-14
3
9
  ==================
4
10
 
5
11
  * Added possibility to use some AR validations
6
12
  * Added changelog
7
13
 
8
- 0.0.1 / 2011-07-14
14
+ 0.0.1 / 2011-07-14
9
15
  ==================
10
16
 
11
17
  * Added TODO for future version
data/README.md CHANGED
@@ -56,7 +56,7 @@ p = Product.new :price => Money.new(1000, "EUR"), :name => "T-shirt"
56
56
  p.price # => #<Money cents:1000 currency:EUR>
57
57
  p.price.format # => "10.00 €"
58
58
  p.price.cents # => 1000
59
- p.price.currency_as_string => "€"
59
+ p.price.currency_as_string # => "€"
60
60
  ```
61
61
 
62
62
  To use the default currency from the money gem, you'd rather drop the
@@ -68,6 +68,21 @@ class Product < ActiveRecord::Base
68
68
  end
69
69
  ```
70
70
 
71
+ ## Validations
72
+
73
+ You can use ActiveRecord validations, as the following example:
74
+
75
+ ```ruby
76
+ class Product < ActiveRecord::Base
77
+ has_money_fields :price
78
+ validates :price, :presence => true
79
+ end
80
+
81
+ product = Product.new :price => nil
82
+ product.save # => false
83
+ product.valid? # => false
84
+ ```
85
+
71
86
  # TODO
72
87
 
73
- * Make dirty attributes and validations work
88
+ * Make dirty attributes work
@@ -26,7 +26,7 @@ currency data in a safe and clean way.
26
26
  s.add_dependency "money"
27
27
  s.add_development_dependency "sqlite3"
28
28
  s.add_development_dependency "rspec", "~> 2"
29
- s.add_development_dependency "ruby-debug"
29
+ s.add_development_dependency "ruby-debug19"
30
30
  s.add_development_dependency "guard"
31
31
  s.add_development_dependency "guard-rspec"
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module HasMoneyFields
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -10,6 +10,8 @@ module HasMoneyFields
10
10
 
11
11
  args.each do |attr|
12
12
  converter = Proc.new do |value|
13
+ # remove all non digit and period characters from the price
14
+ value.gsub! /[^\.|\d]/, ""
13
15
  if value.respond_to? :to_money
14
16
  value.to_money
15
17
  else
@@ -1,4 +1,4 @@
1
- require "spec/spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe "Model with money fields" do
4
4
  context "for cents and currency" do
@@ -39,6 +39,16 @@ describe "Model with money fields" do
39
39
  its(:money_price_in_usd) { should be_nil }
40
40
  end
41
41
 
42
+ context "with price combining text and numbers" do
43
+ before do
44
+ @product = Product.create! :price => "$1000 + VAT"
45
+ end
46
+ subject {@product}
47
+
48
+ its(:money_price){ should == 100000 }
49
+ its(:currency_price){ should == "USD" }
50
+ end
51
+
42
52
  context "with validations" do
43
53
  before do
44
54
  Product.class_eval do
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ ActiveRecord::Base.establish_connection({
8
8
  :database => ":memory:",
9
9
  })
10
10
 
11
- require 'lib/has_money_fields'
12
- require 'spec/models'
11
+ require 'has_money_fields'
12
+ require 'models'
metadata CHANGED
@@ -1,135 +1,140 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: has_money_fields
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Francisco J. Casas
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-14 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activerecord
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: money
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
40
25
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: money
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
48
38
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: sqlite3
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
54
49
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
62
54
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: rspec
66
55
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
68
65
  none: false
69
- requirements:
66
+ requirements:
70
67
  - - ~>
71
- - !ruby/object:Gem::Version
72
- hash: 7
73
- segments:
74
- - 2
75
- version: "2"
68
+ - !ruby/object:Gem::Version
69
+ version: '2'
76
70
  type: :development
77
- version_requirements: *id004
78
- - !ruby/object:Gem::Dependency
79
- name: ruby-debug
80
71
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
82
73
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: ruby-debug19
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
90
86
  type: :development
91
- version_requirements: *id005
92
- - !ruby/object:Gem::Dependency
93
- name: guard
94
87
  prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
96
89
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
104
102
  type: :development
105
- version_requirements: *id006
106
- - !ruby/object:Gem::Dependency
107
- name: guard-rspec
108
103
  prerelease: false
109
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
110
105
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
118
  type: :development
119
- version_requirements: *id007
120
- description: |
121
- Use the Money gem and ActiveRecord's composed_of to store fields wich contains
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: ! 'Use the Money gem and ActiveRecord''s composed_of to store fields
127
+ wich contains
128
+
122
129
  currency data in a safe and clean way.
123
130
 
124
- email:
131
+ '
132
+ email:
125
133
  - fran@zorros.be
126
134
  executables: []
127
-
128
135
  extensions: []
129
-
130
136
  extra_rdoc_files: []
131
-
132
- files:
137
+ files:
133
138
  - .gitignore
134
139
  - Gemfile
135
140
  - Guardfile
@@ -143,41 +148,31 @@ files:
143
148
  - spec/has_money_fields_spec.rb
144
149
  - spec/models.rb
145
150
  - spec/spec_helper.rb
146
- has_rdoc: true
147
151
  homepage: http://zorros.be
148
152
  licenses: []
149
-
150
153
  post_install_message:
151
154
  rdoc_options: []
152
-
153
- require_paths:
155
+ require_paths:
154
156
  - lib
155
- required_ruby_version: !ruby/object:Gem::Requirement
157
+ required_ruby_version: !ruby/object:Gem::Requirement
156
158
  none: false
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- hash: 3
161
- segments:
162
- - 0
163
- version: "0"
164
- required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
164
  none: false
166
- requirements:
167
- - - ">="
168
- - !ruby/object:Gem::Version
169
- hash: 3
170
- segments:
171
- - 0
172
- version: "0"
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
173
169
  requirements: []
174
-
175
170
  rubyforge_project: has_money_fields
176
- rubygems_version: 1.5.3
171
+ rubygems_version: 1.8.24
177
172
  signing_key:
178
173
  specification_version: 3
179
174
  summary: Persist your money on a clean and easy way with Money gem
180
- test_files:
175
+ test_files:
181
176
  - spec/has_money_fields_spec.rb
182
177
  - spec/models.rb
183
178
  - spec/spec_helper.rb