Skip to content

Commit

Permalink
include an email validator as seen on http://guides.rubyonrails.org/a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak committed Oct 29, 2011
1 parent 637427d commit b91ea65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/suspenders/app_builder.rb
Expand Up @@ -14,7 +14,7 @@ def remove_public_images_rails
remove_file 'public/images/rails.png'
end

def setup_development_environment
def raise_delivery_errors
replace_in_file "config/environments/development.rb", "raise_delivery_errors = false", "raise_delivery_errors = true"
end

Expand Down Expand Up @@ -147,6 +147,10 @@ def set_attr_accessibles_on_user
:after => /include Clearance::User\n/
end

def add_email_validator
copy_file "email_validator.rb", "app/validators/email_validator.rb"
end

def include_clearance_matchers
create_file "spec/support/clearance.rb", "require 'clearance/testing'"
end
Expand Down
3 changes: 2 additions & 1 deletion lib/suspenders/generators/app_generator.rb
Expand Up @@ -41,7 +41,7 @@ def remove_files_we_dont_need

def setup_development_environment
say "Setting up the development environment"
build(:setup_development_environment)
build(:raise_delivery_errors)
end

def setup_staging_environment
Expand Down Expand Up @@ -87,6 +87,7 @@ def configure_app
build(:generate_cucumber)
build(:generate_clearance)
build(:install_factory_girl_steps)
build(:add_email_validator)
build(:include_clearance_matchers)
build(:setup_default_rake_task)
end
Expand Down
7 changes: 7 additions & 0 deletions templates/email_validator.rb
@@ -0,0 +1,7 @@
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || "is not an email")
end
end
end

0 comments on commit b91ea65

Please sign in to comment.