443- patch trim on validation + spec
This commit is contained in:
parent
fd2fac865b
commit
f1ae95fac9
2 changed files with 12 additions and 2 deletions
|
|
@ -18,7 +18,11 @@ class Aspect
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name, :scope => :user_id
|
validates_uniqueness_of :name, :scope => :user_id
|
||||||
attr_accessible :name
|
attr_accessible :name
|
||||||
|
|
||||||
|
before_validation do
|
||||||
|
name.strip!
|
||||||
|
end
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,17 @@ describe Aspect do
|
||||||
let(:aspect3) {user3.aspect(:name => "lala")}
|
let(:aspect3) {user3.aspect(:name => "lala")}
|
||||||
|
|
||||||
describe 'creation' do
|
describe 'creation' do
|
||||||
let(:aspect){user.aspect(:name => 'losers')}
|
let!(:aspect){user.aspect(:name => 'losers')}
|
||||||
it 'should have a name' do
|
it 'should have a name' do
|
||||||
aspect.name.should == "losers"
|
aspect.name.should == "losers"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not allow duplicate names' do
|
||||||
|
lambda {
|
||||||
|
invalid_aspect = user.aspect(:name => "losers ")
|
||||||
|
}.should_not change(Aspect, :count)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should not be creatable with people' do
|
it 'should not be creatable with people' do
|
||||||
aspect = user.aspect(:name => 'losers', :people => [friend, friend_2])
|
aspect = user.aspect(:name => 'losers', :people => [friend, friend_2])
|
||||||
aspect.people.size.should == 0
|
aspect.people.size.should == 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue