Sha256: 34e4bc787e99dbd4fa70407af87c566b7a97a8dafb44a99d13bc12f8edfccd1d
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb') describe "Phone Validation" do before(:each) do TestRecord.reset_callbacks(:validate) TestRecord.validates :phone, :phone => true end subject { TestRecord.new } it 'should validate format of phone with ###-###-####' do subject.phone = '999-999-9999' subject.should be_valid subject.should have(0).errors end it 'should validate format of phone with ##########' do subject.phone = '9999999999' subject.should be_valid subject.should have(0).errors end it 'should validate format of phone with ###.###.####' do subject.phone = '999.999.9999' subject.should be_valid subject.should have(0).errors end it 'should validate format of phone with ### ### ####' do subject.phone = '999 999 9999' subject.should be_valid subject.should have(0).errors end it 'should validate format of phone with (###) ###-####' do subject.phone = '(999) 999-9999' subject.should be_valid subject.should have(0).errors end describe "for invalid formats" do before :each do subject.phone = '999' end it "rejects invalid formats" do subject.should_not be_valid subject.should have(1).error end it "generates an error message of type invalid" do subject.should_not be_valid subject.errors[:phone].should include subject.errors.generate_message(:phone, :invalid) end end end
Version data entries
4 entries across 4 versions & 1 rubygems