Skip to content

Instantly share code, notes, and snippets.

@yakovenkodenis
Created July 31, 2015 19:32
Show Gist options
  • Save yakovenkodenis/899785c2c269787e59dd to your computer and use it in GitHub Desktop.
Save yakovenkodenis/899785c2c269787e59dd to your computer and use it in GitHub Desktop.
Model validations/assosiations spec
RSpec.describe Account, type: :model do
describe 'validations' do
it { should validate_presence_of :owner }
it { should validate_presence_of :subdomain }
it { should validate_uniqueness_of :subdomain }
it { should allow_value('denis').for(:subdomain) }
it { should allow_value('test').for(:subdomain) }
it { should_not allow_value('www').for(:subdomain) }
it { should_not allow_value('WWW').for(:subdomain) }
it { should_not allow_value('.test').for(:subdomain) }
it { should_not allow_value('test/').for(:subdomain) }
it 'should validate case insensitive uniqueness' do
create(:account, subdomain: 'Test')
expect(build(:account, subdomain: 'test')).to_not be_valid
end
end
describe 'associations' do
it { should belong_to :owner }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment