ticket: 487 - make sure to remove extraneous spaces from project names when saving record

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@608 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
jacqui 2007-10-03 03:05:34 +00:00
parent fbcf864bde
commit dd2f530f74
2 changed files with 17 additions and 1 deletions

View file

@ -86,7 +86,10 @@ class Project < ActiveRecord::Base
complete!
end
end
def name=(value)
self[:name] = value.gsub(/\s{2,}/, " ").strip
end
end
class NullProject

View file

@ -39,6 +39,19 @@ class ProjectTest < Test::Rails::TestCase
assert_equal "cannot contain the comma (',') character", newproj.errors.on(:name)
end
def test_name_removes_extra_spaces
newproj = Project.new
newproj.name = "These Words Have Proximity Issues "
assert newproj.save
assert_equal 0, newproj.errors.count
assert_equal "These Words Have Proximity Issues", newproj.name
# and on update...
@timemachine.name = " a time machine needs lots of spaaaaaaace "
assert @timemachine.save
assert_equal "a time machine needs lots of spaaaaaaace", @timemachine.name
end
def test_project_initial_state_is_active
assert_equal :active, @timemachine.current_state
assert @timemachine.active?