format_validators 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/VERSION +1 -1
- data/app/validators/florida_counties_validator.rb +86 -0
- data/format_validators.gemspec +10 -6
- data/spec/dummy/app/models/building.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20120321134932_create_buildings.rb +14 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/support/basic_record.rb +11 -0
- data/spec/validators/florida_counties_integration_spec.rb +23 -0
- data/spec/validators/florida_counties_spec.rb +42 -0
- data/spec/validators/ssn_format_validator_spec.rb +1 -11
- metadata +11 -7
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/log/test.log +0 -99
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# counties use abbreviations and will not validate otherwise
|
2
|
+
# example: Saint Lucie must be St. Lucie
|
3
|
+
class FloridaCountiesValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each record, attribute, value
|
5
|
+
value = value.to_s.downcase.split(' ').map {|w| w.capitalize }.join(' ')
|
6
|
+
|
7
|
+
if value.include?("County")
|
8
|
+
message = value + ' should not contain the word county.'
|
9
|
+
record.errors[attribute] << (options[:message] || message )
|
10
|
+
value = value.gsub("County", "").strip
|
11
|
+
end
|
12
|
+
|
13
|
+
message = value + ' is not a county in Florida'
|
14
|
+
record.errors[attribute] << (options[:message] || message ) unless COUNTIES.include? value
|
15
|
+
end
|
16
|
+
|
17
|
+
COUNTIES = [
|
18
|
+
"Alachua",
|
19
|
+
"Baker",
|
20
|
+
"Bay",
|
21
|
+
"Bradford",
|
22
|
+
"Brevard",
|
23
|
+
"Broward",
|
24
|
+
"Calhoun",
|
25
|
+
"Charlotte",
|
26
|
+
"Citrus",
|
27
|
+
"Clay",
|
28
|
+
"Collier",
|
29
|
+
"Columbia",
|
30
|
+
"De Soto",
|
31
|
+
"Suncoast",
|
32
|
+
"Dixie",
|
33
|
+
"Duval",
|
34
|
+
"Escambia",
|
35
|
+
"Flagler",
|
36
|
+
"Franklin",
|
37
|
+
"Gadsden",
|
38
|
+
"Gilchrist",
|
39
|
+
"Glades",
|
40
|
+
"Gulf",
|
41
|
+
"Hamilton",
|
42
|
+
"Hardee",
|
43
|
+
"Hendry",
|
44
|
+
"Hernando",
|
45
|
+
"Highlands",
|
46
|
+
"Hillsborough Suncoast",
|
47
|
+
"Holmes",
|
48
|
+
"Indian River",
|
49
|
+
"Jackson",
|
50
|
+
"Jefferson",
|
51
|
+
"Lafayette",
|
52
|
+
"Lake",
|
53
|
+
"Lee",
|
54
|
+
"Leon",
|
55
|
+
"Levy",
|
56
|
+
"Liberty",
|
57
|
+
"Madison",
|
58
|
+
"Manatee",
|
59
|
+
"Marion",
|
60
|
+
"Martin",
|
61
|
+
"Miami-Dade",
|
62
|
+
"Monroe",
|
63
|
+
"Nassau",
|
64
|
+
"Okaloosa",
|
65
|
+
"Okeechobee",
|
66
|
+
"Orange",
|
67
|
+
"Osceloa",
|
68
|
+
"Palm Beach",
|
69
|
+
"Pasco",
|
70
|
+
"Pinellas",
|
71
|
+
"Polk",
|
72
|
+
"Putnam",
|
73
|
+
"Santa Rosa",
|
74
|
+
"Sarasota",
|
75
|
+
"Seminole",
|
76
|
+
"St. Johns",
|
77
|
+
"St. Lucie",
|
78
|
+
"Sumter",
|
79
|
+
"Suwannee",
|
80
|
+
"Taylor",
|
81
|
+
"Union",
|
82
|
+
"Volusia",
|
83
|
+
"Wakulla",
|
84
|
+
"Walton",
|
85
|
+
"Washington"]
|
86
|
+
end
|
data/format_validators.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.3"
|
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"]
|
12
|
-
s.date = "2012-03-
|
12
|
+
s.date = "2012-03-21"
|
13
13
|
s.description = "Complex format validators"
|
14
14
|
s.email = "jeremiah@cloudspace.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.rdoc",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
+
"app/validators/florida_counties_validator.rb",
|
29
30
|
"app/validators/ssn_format_validator.rb",
|
30
31
|
"format_validators.gemspec",
|
31
32
|
"lib/format_validators.rb",
|
@@ -34,6 +35,7 @@ Gem::Specification.new do |s|
|
|
34
35
|
"spec/dummy/Rakefile",
|
35
36
|
"spec/dummy/app/controllers/application_controller.rb",
|
36
37
|
"spec/dummy/app/helpers/application_helper.rb",
|
38
|
+
"spec/dummy/app/models/building.rb",
|
37
39
|
"spec/dummy/app/views/layouts/application.html.erb",
|
38
40
|
"spec/dummy/config.ru",
|
39
41
|
"spec/dummy/config/application.rb",
|
@@ -50,11 +52,10 @@ Gem::Specification.new do |s|
|
|
50
52
|
"spec/dummy/config/initializers/session_store.rb",
|
51
53
|
"spec/dummy/config/locales/en.yml",
|
52
54
|
"spec/dummy/config/routes.rb",
|
55
|
+
"spec/dummy/db/development.sqlite3",
|
56
|
+
"spec/dummy/db/migrate/20120321134932_create_buildings.rb",
|
57
|
+
"spec/dummy/db/schema.rb",
|
53
58
|
"spec/dummy/db/test.sqlite3",
|
54
|
-
"spec/dummy/log/development.log",
|
55
|
-
"spec/dummy/log/production.log",
|
56
|
-
"spec/dummy/log/server.log",
|
57
|
-
"spec/dummy/log/test.log",
|
58
59
|
"spec/dummy/public/404.html",
|
59
60
|
"spec/dummy/public/422.html",
|
60
61
|
"spec/dummy/public/500.html",
|
@@ -69,6 +70,9 @@ Gem::Specification.new do |s|
|
|
69
70
|
"spec/dummy/script/rails",
|
70
71
|
"spec/format_validators_spec.rb",
|
71
72
|
"spec/spec_helper.rb",
|
73
|
+
"spec/support/basic_record.rb",
|
74
|
+
"spec/validators/florida_counties_integration_spec.rb",
|
75
|
+
"spec/validators/florida_counties_spec.rb",
|
72
76
|
"spec/validators/ssn_format_validator_spec.rb"
|
73
77
|
]
|
74
78
|
s.homepage = "http://github.com/jeremiahishere/format_validators"
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20120321134932) do
|
15
|
+
|
16
|
+
create_table "buildings", :force => true do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.string "county"
|
19
|
+
t.datetime "created_at"
|
20
|
+
t.datetime "updated_at"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Building do
|
4
|
+
before(:each) do
|
5
|
+
@building = Building.new
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
it "should fail validations on an empty county" do
|
10
|
+
@building.county = nil
|
11
|
+
@building.should have(1).error_on(:county)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should fail validations on a bad county" do
|
15
|
+
@building.county = "Orlando"
|
16
|
+
@building.should have(1).error_on(:county)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should pass validations on a good county" do
|
20
|
+
@building.county = "Orange"
|
21
|
+
@building.should have(0).error_on(:county)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FloridaCountiesValidator do
|
4
|
+
|
5
|
+
describe ".validate_each" do
|
6
|
+
before(:all) do
|
7
|
+
@options = {:attributes => {}}
|
8
|
+
@validator = FloridaCountiesValidator.new(@options)
|
9
|
+
@record = BasicRecord.new(:county)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return false for invalid county" do
|
13
|
+
@record.errors[:county].should_receive("<<")
|
14
|
+
@validator.validate_each(@record, :county, "123456789")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return true for valid county" do
|
18
|
+
@record.errors[:county].should_not_receive("<<")
|
19
|
+
@validator.validate_each(@record, :county, "Orange")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should validate lowercase county name" do
|
23
|
+
@record.errors[:county].should_not_receive("<<")
|
24
|
+
@validator.validate_each(@record, :county, "orange")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should validate all uppercase county name" do
|
28
|
+
@record.errors[:county].should_not_receive("<<")
|
29
|
+
@validator.validate_each(@record, :county, "ORANGE")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should validate multi word count" do
|
33
|
+
@record.errors[:county].should_not_receive("<<")
|
34
|
+
@validator.validate_each(@record, :county, "St. Lucie")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set a county error if the input includes the word 'county'" do
|
38
|
+
@record.errors[:county].should_receive("<<").with("Orange County should not contain the word county.")
|
39
|
+
@validator.validate_each(@record, :county, "Orange County")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,21 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class BasicRecord
|
4
|
-
def initialize
|
5
|
-
@errors = {:ssn => []}
|
6
|
-
end
|
7
|
-
|
8
|
-
def errors
|
9
|
-
@errors
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
describe SsnFormatValidator do
|
14
4
|
describe ".validate_each" do
|
15
5
|
before(:each) do
|
16
6
|
@options = {:attributes => {}}
|
17
7
|
@validator = SsnFormatValidator.new(@options)
|
18
|
-
@record = BasicRecord.new
|
8
|
+
@record = BasicRecord.new(:ssn)
|
19
9
|
end
|
20
10
|
|
21
11
|
it "should validate the format for ###-##-####" do
|
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.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremiah Hemphill
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- README.rdoc
|
164
164
|
- Rakefile
|
165
165
|
- VERSION
|
166
|
+
- app/validators/florida_counties_validator.rb
|
166
167
|
- app/validators/ssn_format_validator.rb
|
167
168
|
- format_validators.gemspec
|
168
169
|
- lib/format_validators.rb
|
@@ -171,6 +172,7 @@ files:
|
|
171
172
|
- spec/dummy/Rakefile
|
172
173
|
- spec/dummy/app/controllers/application_controller.rb
|
173
174
|
- spec/dummy/app/helpers/application_helper.rb
|
175
|
+
- spec/dummy/app/models/building.rb
|
174
176
|
- spec/dummy/app/views/layouts/application.html.erb
|
175
177
|
- spec/dummy/config.ru
|
176
178
|
- spec/dummy/config/application.rb
|
@@ -187,11 +189,10 @@ files:
|
|
187
189
|
- spec/dummy/config/initializers/session_store.rb
|
188
190
|
- spec/dummy/config/locales/en.yml
|
189
191
|
- spec/dummy/config/routes.rb
|
192
|
+
- spec/dummy/db/development.sqlite3
|
193
|
+
- spec/dummy/db/migrate/20120321134932_create_buildings.rb
|
194
|
+
- spec/dummy/db/schema.rb
|
190
195
|
- spec/dummy/db/test.sqlite3
|
191
|
-
- spec/dummy/log/development.log
|
192
|
-
- spec/dummy/log/production.log
|
193
|
-
- spec/dummy/log/server.log
|
194
|
-
- spec/dummy/log/test.log
|
195
196
|
- spec/dummy/public/404.html
|
196
197
|
- spec/dummy/public/422.html
|
197
198
|
- spec/dummy/public/500.html
|
@@ -206,6 +207,9 @@ files:
|
|
206
207
|
- spec/dummy/script/rails
|
207
208
|
- spec/format_validators_spec.rb
|
208
209
|
- spec/spec_helper.rb
|
210
|
+
- spec/support/basic_record.rb
|
211
|
+
- spec/validators/florida_counties_integration_spec.rb
|
212
|
+
- spec/validators/florida_counties_spec.rb
|
209
213
|
- spec/validators/ssn_format_validator_spec.rb
|
210
214
|
homepage: http://github.com/jeremiahishere/format_validators
|
211
215
|
licenses:
|
@@ -220,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
224
|
requirements:
|
221
225
|
- - ">="
|
222
226
|
- !ruby/object:Gem::Version
|
223
|
-
hash:
|
227
|
+
hash: -4594523528245136505
|
224
228
|
segments:
|
225
229
|
- 0
|
226
230
|
version: "0"
|
File without changes
|
File without changes
|
data/spec/dummy/log/server.log
DELETED
File without changes
|
data/spec/dummy/log/test.log
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
[1m[36mSQL (4.1ms)[0m [1m SELECT name
|
2
|
-
FROM sqlite_master
|
3
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
4
|
-
[0m
|
5
|
-
[1m[35mSQL (0.1ms)[0m select sqlite_version(*)
|
6
|
-
[1m[36mSQL (35.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
7
|
-
[1m[35mSQL (0.1ms)[0m PRAGMA index_list("schema_migrations")
|
8
|
-
[1m[36mSQL (21.3ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
9
|
-
[1m[35mSQL (0.2ms)[0m SELECT name
|
10
|
-
FROM sqlite_master
|
11
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
12
|
-
[1m[36mSQL (1.5ms)[0m [1m SELECT name
|
13
|
-
FROM sqlite_master
|
14
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
15
|
-
[0m
|
16
|
-
[1m[36mSQL (1.2ms)[0m [1m SELECT name
|
17
|
-
FROM sqlite_master
|
18
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
19
|
-
[0m
|
20
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
21
|
-
FROM sqlite_master
|
22
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
23
|
-
[0m
|
24
|
-
[1m[36mSQL (0.4ms)[0m [1m SELECT name
|
25
|
-
FROM sqlite_master
|
26
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
27
|
-
[0m
|
28
|
-
[1m[36mSQL (1.0ms)[0m [1m SELECT name
|
29
|
-
FROM sqlite_master
|
30
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
31
|
-
[0m
|
32
|
-
[1m[36mSQL (1.4ms)[0m [1m SELECT name
|
33
|
-
FROM sqlite_master
|
34
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
35
|
-
[0m
|
36
|
-
[1m[36mSQL (1.4ms)[0m [1m SELECT name
|
37
|
-
FROM sqlite_master
|
38
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
39
|
-
[0m
|
40
|
-
[1m[36mSQL (1.4ms)[0m [1m SELECT name
|
41
|
-
FROM sqlite_master
|
42
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
43
|
-
[0m
|
44
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
45
|
-
FROM sqlite_master
|
46
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
47
|
-
[0m
|
48
|
-
[1m[36mSQL (2.0ms)[0m [1m SELECT name
|
49
|
-
FROM sqlite_master
|
50
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
51
|
-
[0m
|
52
|
-
[1m[36mSQL (2.0ms)[0m [1m SELECT name
|
53
|
-
FROM sqlite_master
|
54
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
55
|
-
[0m
|
56
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
57
|
-
FROM sqlite_master
|
58
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
59
|
-
[0m
|
60
|
-
[1m[36mSQL (1.5ms)[0m [1m SELECT name
|
61
|
-
FROM sqlite_master
|
62
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
63
|
-
[0m
|
64
|
-
[1m[36mSQL (1.5ms)[0m [1m SELECT name
|
65
|
-
FROM sqlite_master
|
66
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
67
|
-
[0m
|
68
|
-
[1m[36mSQL (1.1ms)[0m [1m SELECT name
|
69
|
-
FROM sqlite_master
|
70
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
71
|
-
[0m
|
72
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
73
|
-
FROM sqlite_master
|
74
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
75
|
-
[0m
|
76
|
-
[1m[36mSQL (1.7ms)[0m [1m SELECT name
|
77
|
-
FROM sqlite_master
|
78
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
79
|
-
[0m
|
80
|
-
[1m[36mSQL (1.2ms)[0m [1m SELECT name
|
81
|
-
FROM sqlite_master
|
82
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
83
|
-
[0m
|
84
|
-
[1m[36mSQL (1.5ms)[0m [1m SELECT name
|
85
|
-
FROM sqlite_master
|
86
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
87
|
-
[0m
|
88
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
89
|
-
FROM sqlite_master
|
90
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
91
|
-
[0m
|
92
|
-
[1m[36mSQL (1.1ms)[0m [1m SELECT name
|
93
|
-
FROM sqlite_master
|
94
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
95
|
-
[0m
|
96
|
-
[1m[36mSQL (1.3ms)[0m [1m SELECT name
|
97
|
-
FROM sqlite_master
|
98
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
99
|
-
[0m
|