format_validators 0.0.2 → 0.0.3

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/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  == unreleased changes
2
2
 
3
+ == 0.0.3
4
+
5
+ * Added florida counties validator
6
+ * Added basic integration tests
7
+
3
8
  == 0.0.2
4
9
 
5
10
  * Setup dummy app
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "format_validators"
8
- s.version = "0.0.2"
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-14"
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"
@@ -0,0 +1,4 @@
1
+ class Building < ActiveRecord::Base
2
+ validates :name, :presence => true
3
+ validates :county, :florida_counties => true
4
+ end
Binary file
@@ -0,0 +1,14 @@
1
+ class CreateBuildings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :buildings do |t|
4
+ t.string :name
5
+ t.string :county
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :buildings
13
+ end
14
+ end
@@ -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
Binary file
@@ -0,0 +1,11 @@
1
+ # this class is used to test the validators
2
+ # it contains the methods needed to mimic and ActiveRecord::Base for the validators
3
+ class BasicRecord
4
+ def initialize(attribute)
5
+ @errors = {attribute => []}
6
+ end
7
+
8
+ def errors
9
+ @errors
10
+ end
11
+ end
@@ -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.2
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-14 00:00:00 Z
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: 4321630142708735267
227
+ hash: -4594523528245136505
224
228
  segments:
225
229
  - 0
226
230
  version: "0"
File without changes
File without changes
File without changes
@@ -1,99 +0,0 @@
1
- SQL (4.1ms)  SELECT name
2
- FROM sqlite_master
3
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
- 
5
- SQL (0.1ms) select sqlite_version(*)
6
- SQL (35.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
7
- SQL (0.1ms) PRAGMA index_list("schema_migrations")
8
- SQL (21.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
9
- SQL (0.2ms) SELECT name
10
- FROM sqlite_master
11
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
12
- SQL (1.5ms)  SELECT name
13
- FROM sqlite_master
14
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
15
- 
16
- SQL (1.2ms)  SELECT name
17
- FROM sqlite_master
18
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
19
- 
20
- SQL (1.3ms)  SELECT name
21
- FROM sqlite_master
22
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
23
- 
24
- SQL (0.4ms)  SELECT name
25
- FROM sqlite_master
26
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
27
- 
28
- SQL (1.0ms)  SELECT name
29
- FROM sqlite_master
30
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
31
- 
32
- SQL (1.4ms)  SELECT name
33
- FROM sqlite_master
34
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
35
- 
36
- SQL (1.4ms)  SELECT name
37
- FROM sqlite_master
38
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
39
- 
40
- SQL (1.4ms)  SELECT name
41
- FROM sqlite_master
42
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
43
- 
44
- SQL (1.3ms)  SELECT name
45
- FROM sqlite_master
46
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
47
- 
48
- SQL (2.0ms)  SELECT name
49
- FROM sqlite_master
50
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
51
- 
52
- SQL (2.0ms)  SELECT name
53
- FROM sqlite_master
54
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
55
- 
56
- SQL (1.3ms)  SELECT name
57
- FROM sqlite_master
58
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
59
- 
60
- SQL (1.5ms)  SELECT name
61
- FROM sqlite_master
62
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
63
- 
64
- SQL (1.5ms)  SELECT name
65
- FROM sqlite_master
66
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
67
- 
68
- SQL (1.1ms)  SELECT name
69
- FROM sqlite_master
70
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
71
- 
72
- SQL (1.3ms)  SELECT name
73
- FROM sqlite_master
74
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
75
- 
76
- SQL (1.7ms)  SELECT name
77
- FROM sqlite_master
78
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
79
- 
80
- SQL (1.2ms)  SELECT name
81
- FROM sqlite_master
82
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
83
- 
84
- SQL (1.5ms)  SELECT name
85
- FROM sqlite_master
86
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
87
- 
88
- SQL (1.3ms)  SELECT name
89
- FROM sqlite_master
90
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
91
- 
92
- SQL (1.1ms)  SELECT name
93
- FROM sqlite_master
94
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
95
- 
96
- SQL (1.3ms)  SELECT name
97
- FROM sqlite_master
98
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
99
-