1 $:.unshift(File.dirname(__FILE__) + '/../lib')
4 require 'active_record'
5 require 'active_record/base'
7 require 'validates_email_format_of'
9 ActiveRecord::Base.establish_connection(
10 :adapter => 'sqlite3',
11 :database => ':memory:')
13 ActiveRecord::Schema.define(:version => 0) do
14 create_table :users, :force => true do |t|
15 t.column 'email', :string
19 class Person < ActiveRecord::Base
20 validates_email_format_of :email, :on => :create, :message => 'fails with custom message', :allow_nil => true
25 require "#{File.dirname(__FILE__)}/../init"
27 class Test::Unit::TestCase #:nodoc:
28 def self.should_allow_values(klass,*good_values)
29 good_values.each do |v|
30 should "allow email to be set to #{v.inspect}" do
31 user = klass.new(:email => v)
33 assert_nil user.errors.on(:email)
38 def self.should_not_allow_values(klass,*bad_values)
39 bad_values.each do |v|
40 should "not allow email to be set to #{v.inspect}" do
41 user = klass.new(:email => v)
42 assert !user.save, "Saved user with email set to \"#{v}\""
43 assert user.errors.on(:email), "There are no errors set on email after being set to \"#{v}\""