Sha256: 97436588547f74928d8e17bfdda3f49b6b0ab5fd94d0096b11ac267975f6a578
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
context DataMapper::Validations::FormatValidator do before(:all) do class Employee include DataMapper::CallbacksHelper include DataMapper::Validations::ValidationHelper attr_accessor :email end end it 'must have a valid email address' do class Employee validations.clear! validates_format_of :email, :as => :email_address, :on => :save end e = Employee.new e.valid?.should == true [ 'test test@example.com', 'test@example', 'test#example.com', 'tester@exampl$.com', '[scizzle]@example.com', '.test@example.com' ].all? { |test_email| e.email = test_email e.valid?(:save).should == false e.errors.full_messages.first.should == "#{test_email} is not a valid email address" } e.email = 'test@example.com' e.valid?(:save).should == true end it 'must have a valid organization code' do class Employee validations.clear! attr_accessor :organization_code # WARNING: contrived example # The organization code must be A#### or B######X12 validates_format_of :organization_code, :on => :save, :with => lambda { |code| (code =~ /A\d{4}/) || (code =~ /[B-Z]\d{6}X12/) } end e = Employee.new e.valid?.should == true e.organization_code = 'BLAH :)' e.valid?(:save).should == false e.errors.full_messages.first.should == 'Organization code is invalid' e.organization_code = 'A1234' e.valid?(:save).should == true e.organization_code = 'B123456X12' e.valid?(:save).should == true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datamapper-0.2.0 | spec/validates_format_of_spec.rb |