Validate uniqueness of aspect name, 359
This commit is contained in:
parent
d87345ca33
commit
962f282cbc
2 changed files with 16 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ class Aspect
|
|||
belongs_to :user, :class_name => 'User'
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => :user_id
|
||||
|
||||
timestamps!
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,21 @@ describe Aspect do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
before do
|
||||
@aspect = @user.aspect(:name => 'losers')
|
||||
end
|
||||
it 'has a unique name for one user' do
|
||||
aspect2 = @user.aspect(:name => @aspect.name)
|
||||
aspect2.valid?.should be_false
|
||||
end
|
||||
|
||||
it 'has no uniqueness between users' do
|
||||
aspect2 = @user2.aspect(:name => @aspect.name)
|
||||
aspect2.valid?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'querying' do
|
||||
before do
|
||||
@aspect = @user.aspect(:name => 'losers')
|
||||
|
|
|
|||
Loading…
Reference in a new issue