Permalink
Browse files

Finished work on counties validator.

  • Loading branch information...
1 parent f377f4b commit 711b7206e0dcddfa61f858846cb5914086f8fb85 @jeremiahishere jeremiahishere committed Mar 21, 2012
@@ -1,19 +1,18 @@
-#counties use abbreviations and will not validate otherwise
-# ex: Saint Lucie must be St. Lucie
+# counties use abbreviations and will not validate otherwise
+# example: Saint Lucie must be St. Lucie
class FloridaCountiesValidator < ActiveModel::EachValidator
def validate_each record, attribute, value
value = value.downcase.split(' ').map {|w| w.capitalize }.join(' ')
# this part has not been tested
if value.include?("County")
- message = value + ' county should not contain the word county.'
+ message = value + ' should not contain the word county.'
record.errors[attribute] << (options[:message] || message )
- value.gsub("County", "").trim
+ value = value.gsub("County", "").strip
end
message = value + ' is not a county in Florida'
record.errors[attribute] << (options[:message] || message ) unless COUNTIES.include? value
-
end
COUNTIES = [
View
@@ -149,3 +149,27 @@
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'

+ SQL (4.0ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.4ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.3ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.5ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (1.8ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
+ SQL (0.7ms)  SELECT name
+ FROM sqlite_master
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+
@@ -33,7 +33,10 @@
@record.errors[:county].should_not_receive("<<")
@validator.validate_each(@record, :county, "St. Lucie")
end
-
- end
+ it "should set a county error if the input includes the word 'county'" do
+ @record.errors[:county].should_receive("<<").with("Orange County should not contain the word county.")
+ @validator.validate_each(@record, :county, "Orange County")
+ end
+ end
end

0 comments on commit 711b720

Please sign in to comment.