format_validators 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/VERSION +1 -1
- data/app/validators/currency_format_validator.rb +7 -0
- data/format_validators.gemspec +3 -1
- data/spec/validators/currency_format_validator_spec.rb +51 -0
- metadata +4 -2
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class CurrencyFormatValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each record, attribute, value
|
3
|
+
format = /^\d+(\.\d{2})?$/
|
4
|
+
message = attribute.to_s.humanize + " must contain dollars and cents, seperated by a period"
|
5
|
+
record.errors[attribute] << (options[:message] || message) unless value =~ format
|
6
|
+
end
|
7
|
+
end
|
data/format_validators.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "format_validators"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremiah Hemphill"]
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.rdoc",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
+
"app/validators/currency_format_validator.rb",
|
29
30
|
"app/validators/florida_counties_validator.rb",
|
30
31
|
"app/validators/ssn_format_validator.rb",
|
31
32
|
"format_validators.gemspec",
|
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
|
|
71
72
|
"spec/format_validators_spec.rb",
|
72
73
|
"spec/spec_helper.rb",
|
73
74
|
"spec/support/basic_record.rb",
|
75
|
+
"spec/validators/currency_format_validator_spec.rb",
|
74
76
|
"spec/validators/florida_counties_integration_spec.rb",
|
75
77
|
"spec/validators/florida_counties_spec.rb",
|
76
78
|
"spec/validators/ssn_format_validator_spec.rb"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurrencyFormatValidator do
|
4
|
+
describe ".validate_each" do
|
5
|
+
before(:each) do
|
6
|
+
@options = {:attributes => {}}
|
7
|
+
@validator = CurrencyFormatValidator.new(@options)
|
8
|
+
@record = BasicRecord.new(:cost)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should validate the format for ###.##" do
|
12
|
+
@record.errors[:cost].should_not_receive("<<")
|
13
|
+
@validator.validate_each(@record, :cost, "123.45")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should validate the format for ##.##" do
|
17
|
+
@record.errors[:cost].should_not_receive("<<")
|
18
|
+
@validator.validate_each(@record, :cost, "23.45")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should validate the format for 0.##" do
|
22
|
+
@record.errors[:cost].should_not_receive("<<")
|
23
|
+
@validator.validate_each(@record, :cost, "0.45")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should validate the format for ##" do
|
27
|
+
@record.errors[:cost].should_not_receive("<<")
|
28
|
+
@validator.validate_each(@record, :cost, "45")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not validate the format for #.#.#" do
|
32
|
+
@record.errors[:cost].should_receive("<<")
|
33
|
+
@validator.validate_each(@record, :cost, "4.5.6")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not validate the format for string" do
|
37
|
+
@record.errors[:cost].should_receive("<<")
|
38
|
+
@validator.validate_each(@record, :cost, "word")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not validate the format for #.#" do
|
42
|
+
@record.errors[:cost].should_receive("<<")
|
43
|
+
@validator.validate_each(@record, :cost, "1.2")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not validate the format for .##" do
|
47
|
+
@record.errors[:cost].should_receive("<<")
|
48
|
+
@validator.validate_each(@record, :cost, ".99")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: format_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremiah Hemphill
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- README.rdoc
|
164
164
|
- Rakefile
|
165
165
|
- VERSION
|
166
|
+
- app/validators/currency_format_validator.rb
|
166
167
|
- app/validators/florida_counties_validator.rb
|
167
168
|
- app/validators/ssn_format_validator.rb
|
168
169
|
- format_validators.gemspec
|
@@ -208,6 +209,7 @@ files:
|
|
208
209
|
- spec/format_validators_spec.rb
|
209
210
|
- spec/spec_helper.rb
|
210
211
|
- spec/support/basic_record.rb
|
212
|
+
- spec/validators/currency_format_validator_spec.rb
|
211
213
|
- spec/validators/florida_counties_integration_spec.rb
|
212
214
|
- spec/validators/florida_counties_spec.rb
|
213
215
|
- spec/validators/ssn_format_validator_spec.rb
|
@@ -224,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
226
|
requirements:
|
225
227
|
- - ">="
|
226
228
|
- !ruby/object:Gem::Version
|
227
|
-
hash:
|
229
|
+
hash: 4008772419598118185
|
228
230
|
segments:
|
229
231
|
- 0
|
230
232
|
version: "0"
|