Fix some authors validations edge cases

master
Zequez 2015-08-06 09:41:44 -03:00
parent 4d0d1d2aa5
commit b290a04c3e
2 changed files with 19 additions and 2 deletions

View File

@ -36,8 +36,8 @@ class Author < ActiveRecord::Base
#################
validates :slug, uniqueness: true
validates :forum_name, uniqueness: true
validates :name, presence: true, format: { with: /[a-z]/ }
validates :forum_name, allow_blank: true, uniqueness: true
validates :name, presence: true, format: { with: /[a-z]/i }
private

View File

@ -41,6 +41,17 @@ describe Author do
expect(build :author, forum_name: 'rsarsa').to be_invalid
end
it 'should allow an empty #forum_name' do
author = build :author, forum_name: ''
expect(author).to be_valid
end
it 'should not validate uniqueness with an empty forum name' do
create :author, forum_name: ''
author = build :author, forum_name: ''
expect(author).to be_valid
end
it 'should not allow an empty #name' do
author = build :author, name: ''
expect(author).to be_invalid
@ -64,6 +75,12 @@ describe Author do
expect(author).to be_valid
expect(author.errors[:name]).to be_empty
end
it 'should allow a single uppercase letter' do
author = build :author, name: '-0-A-0-'
expect(author).to be_valid
expect(author.errors[:name]).to be_empty
end
end
describe 'scopes and finders' do