Fix some authors validations edge cases
parent
4d0d1d2aa5
commit
b290a04c3e
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue