Add email validation plugin from:
git://github.com/dancroak/validates_email_format_of.git
This commit is contained in:
parent
b547145865
commit
aefc5f5112
14 changed files with 398 additions and 0 deletions
BIN
vendor/plugins/validates_email_format_of/test/db/email_format_test.sqlite3
vendored
Normal file
BIN
vendor/plugins/validates_email_format_of/test/db/email_format_test.sqlite3
vendored
Normal file
Binary file not shown.
47
vendor/plugins/validates_email_format_of/test/test_helper.rb
vendored
Normal file
47
vendor/plugins/validates_email_format_of/test/test_helper.rb
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
||||
|
||||
require 'rubygems'
|
||||
require 'active_record'
|
||||
require 'active_record/base'
|
||||
|
||||
require 'validates_email_format_of'
|
||||
|
||||
ActiveRecord::Base.establish_connection(
|
||||
:adapter => 'sqlite3',
|
||||
:database => ':memory:')
|
||||
|
||||
ActiveRecord::Schema.define(:version => 0) do
|
||||
create_table :users, :force => true do |t|
|
||||
t.column 'email', :string
|
||||
end
|
||||
end
|
||||
|
||||
class Person < ActiveRecord::Base
|
||||
validates_email_format_of :email, :on => :create, :message => 'fails with custom message', :allow_nil => true
|
||||
end
|
||||
|
||||
require 'test/unit'
|
||||
require 'shoulda'
|
||||
require "#{File.dirname(__FILE__)}/../init"
|
||||
|
||||
class Test::Unit::TestCase #:nodoc:
|
||||
def self.should_allow_values(klass,*good_values)
|
||||
good_values.each do |v|
|
||||
should "allow email to be set to #{v.inspect}" do
|
||||
user = klass.new(:email => v)
|
||||
user.save
|
||||
assert_nil user.errors.on(:email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.should_not_allow_values(klass,*bad_values)
|
||||
bad_values.each do |v|
|
||||
should "not allow email to be set to #{v.inspect}" do
|
||||
user = klass.new(:email => v)
|
||||
assert !user.save, "Saved user with email set to \"#{v}\""
|
||||
assert user.errors.on(:email), "There are no errors set on email after being set to \"#{v}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
37
vendor/plugins/validates_email_format_of/test/validates_email_format_of_test.rb
vendored
Normal file
37
vendor/plugins/validates_email_format_of/test/validates_email_format_of_test.rb
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
require File.dirname(__FILE__) + '/test_helper'
|
||||
require File.dirname(__FILE__) + '/../shoulda_macros/validates_email_format_of'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
validates_email_format_of :email,
|
||||
:on => :create,
|
||||
:message => 'fails with custom message',
|
||||
:allow_nil => true
|
||||
end
|
||||
|
||||
class ValidatesEmailFormatOfTest < Test::Unit::TestCase
|
||||
should_validate_email_format_of_klass(User, :email)
|
||||
|
||||
context 'An invalid user on update' do
|
||||
setup do
|
||||
@user = User.new(:email => 'dcroak@thoughtbot.com')
|
||||
assert @user.save
|
||||
assert @user.update_attribute(:email, '..dcroak@thoughtbot.com')
|
||||
end
|
||||
|
||||
should 'pass validation' do
|
||||
assert @user.valid?
|
||||
assert @user.save
|
||||
assert_nil @user.errors.on(:email)
|
||||
end
|
||||
end
|
||||
|
||||
context 'A user with a nil email' do
|
||||
setup { @user = User.new(:email => nil) }
|
||||
|
||||
should 'pass validation' do
|
||||
assert @user.valid?
|
||||
assert @user.save
|
||||
assert_nil @user.errors.on(:email)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue