Ensure uniqueness and format of an accounts email address.

This commit is contained in:
Mario Visic 2012-01-21 15:51:38 +11:00
parent 40c2902e80
commit 07ff99e135

View File

@ -1,20 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe Account do describe Account do
let!(:existing_account) { Factory(:account, :email => 'another@email.com') }
it 'should have a valid factory' do it 'should have a valid factory' do
FactoryGirl.build(:account).should be_valid FactoryGirl.build(:account).should be_valid
end end
## Validations ## ## Validations ##
it { should validate_presence_of :name }
%w{name email password}.each do |attr| it { should validate_presence_of :email }
it "should validate presence of #{attr}" do it { should validate_presence_of :password }
account = FactoryGirl.build(:account, attr.to_sym => nil) it { should validate_uniqueness_of(:email).with_message(/is already taken/) }
account.should_not be_valid it { should allow_value('valid@email.com').for(:email) }
account.errors[attr.to_sym].should include("can't be blank") it { should allow_value('prefix+suffix@email.com').for(:email) }
end it { should_not allow_value('not-an-email').for(:email) }
end
it "should have a default locale" do it "should have a default locale" do
account = Account.new account = Account.new