Skip to content

Instantly share code, notes, and snippets.

@johncblandii
Created February 7, 2013 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncblandii/4728284 to your computer and use it in GitHub Desktop.
Save johncblandii/4728284 to your computer and use it in GitHub Desktop.
Account Model Rspec Validations
require 'spec_helper'
describe Account do
context "#validations" do
it{ FactoryGirl.build(:account).should be_valid }
it{ FactoryGirl.build(:account, name: "").should be_invalid }
it{
FactoryGirl.build(:account, contact_email: "jb@johnson.com").should be_valid
FactoryGirl.build(:account, contact_email: "jb@johnson.co").should be_valid
FactoryGirl.build(:account, contact_email: "jb@johnson.uk.com").should be_valid
FactoryGirl.build(:account, contact_email: "jb@.com").should be_invalid
FactoryGirl.build(:account, contact_email: "@.com").should be_invalid
FactoryGirl.build(:account, contact_email: "jb@com").should be_invalid
FactoryGirl.build(:account, contact_email: "").should be_invalid
}
it{
FactoryGirl.build(:account, contact_phone: "(555) 123-0555").should be_valid
FactoryGirl.build(:account, contact_phone: "(555)123-0555").should be_valid
FactoryGirl.build(:account, contact_phone: "555.123.0555").should be_valid
FactoryGirl.build(:account, contact_phone: "5551230555").should be_valid
FactoryGirl.build(:account, contact_phone: "(83)123-0555").should be_invalid
FactoryGirl.build(:account, contact_phone: "(555) 44-0555").should be_invalid
FactoryGirl.build(:account, contact_phone: "555.123.055").should be_invalid
}
it{
FactoryGirl.build(:account, status: "active").should be_valid
FactoryGirl.build(:account, status: "ACTIVE").should be_valid
FactoryGirl.build(:account, status: "inactive").should be_valid
FactoryGirl.build(:account, status: "INACTIVE").should be_valid
FactoryGirl.build(:account, status: "somethingelse").should be_invalid
}
it{
FactoryGirl.create(:account, subdomain: "validone").should be_valid
FactoryGirl.build(:account, subdomain: "validone").should be_invalid #must be unique
FactoryGirl.build(:account, subdomain: "3validone").should be_invalid
FactoryGirl.build(:account, subdomain: "validone32434").should be_invalid
FactoryGirl.build(:account, subdomain: "a").should be_invalid
FactoryGirl.build(:account, subdomain: "1").should be_invalid
FactoryGirl.build(:account, subdomain: "a123456789012345").should be_invalid
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment