diff --git a/app/models/profile.rb b/app/models/profile.rb index ecc0fb5ef..328fa45c0 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -19,6 +19,8 @@ class Profile validates_presence_of :first_name, :last_name + before_save :strip_names + def person_id self._parent_document.id end @@ -27,4 +29,9 @@ class Profile self._parent_document end + private + def strip_names + first_name.strip! + last_name.strip! + end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 7bba8311c..4830652f8 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -9,6 +9,15 @@ describe Profile do @person = Factory.build(:person) end + describe 'sanitization' do + it 'strips the names' do + @person.profile = Factory.build(:profile, :first_name => " Bob", :last_name => "Bobson ") + @person.profile.save + @person.profile.first_name.should == "Bob" + @person.profile.last_name.should == "Bobson" + end + end + describe 'requirements' do it "should include a first name" do @person.profile = Factory.build(:profile,:first_name => nil) @@ -23,7 +32,5 @@ describe Profile do @person.profile.last_name = "Smith" @person.profile.valid?.should be true end - end - end