2005-01-09 11:59:57 +00:00
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
|
|
|
|
|
|
class ProjectTest < Test::Unit::TestCase
|
|
|
|
|
fixtures :projects
|
|
|
|
|
|
2006-06-19 04:04:20 +00:00
|
|
|
def setup
|
2006-06-20 02:07:18 +00:00
|
|
|
@timemachine = projects(:timemachine)
|
|
|
|
|
@moremoney = projects(:moremoney)
|
2005-01-09 11:59:57 +00:00
|
|
|
end
|
2006-06-19 04:04:20 +00:00
|
|
|
|
|
|
|
|
def test_validate_presence_of_name
|
|
|
|
|
@timemachine.name = ""
|
|
|
|
|
assert !@timemachine.save
|
|
|
|
|
assert_equal 1, @timemachine.errors.count
|
|
|
|
|
assert_equal "project must have a name", @timemachine.errors.on(:name)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_validate_name_is_less_than_256
|
|
|
|
|
@timemachine.name = "a"*256
|
|
|
|
|
assert !@timemachine.save
|
|
|
|
|
assert_equal 1, @timemachine.errors.count
|
|
|
|
|
assert_equal "project name must be less than 256 characters", @timemachine.errors.on(:name)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_validate_name_is_unique
|
|
|
|
|
newproj = Project.new
|
2006-08-01 07:03:31 +00:00
|
|
|
newproj.name = projects(:timemachine).name
|
|
|
|
|
newproj.user_id = projects(:timemachine).user_id
|
2006-06-19 04:04:20 +00:00
|
|
|
assert !newproj.save
|
|
|
|
|
assert_equal 1, newproj.errors.count
|
|
|
|
|
assert_equal "already exists", newproj.errors.on(:name)
|
|
|
|
|
end
|
|
|
|
|
|
2006-06-19 06:36:00 +00:00
|
|
|
def test_validate_name_does_not_contain_slash
|
|
|
|
|
newproj = Project.new
|
|
|
|
|
newproj.name = "Save Earth/Mankind from Evil"
|
|
|
|
|
assert !newproj.save
|
|
|
|
|
assert_equal 1, newproj.errors.count
|
|
|
|
|
assert_equal "cannot contain the slash ('/') character", newproj.errors.on(:name)
|
|
|
|
|
end
|
2006-10-10 07:17:54 +00:00
|
|
|
|
|
|
|
|
def test_project_initial_state_is_active
|
|
|
|
|
assert_equal :active, @timemachine.current_state
|
|
|
|
|
assert @timemachine.active?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_hide_project
|
|
|
|
|
@timemachine.hide!
|
|
|
|
|
assert_equal :hidden, @timemachine.current_state
|
|
|
|
|
assert @timemachine.hidden?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_activate_project
|
|
|
|
|
@timemachine.activate!
|
|
|
|
|
assert_equal :active, @timemachine.current_state
|
|
|
|
|
assert @timemachine.active?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_complete_project
|
|
|
|
|
@timemachine.complete!
|
|
|
|
|
assert_equal :completed, @timemachine.current_state
|
|
|
|
|
assert @timemachine.completed?
|
|
|
|
|
end
|
2006-11-16 05:33:25 +00:00
|
|
|
|
|
|
|
|
def test_find_project_by_namepart_with_exact_match
|
|
|
|
|
p = Project.find_by_namepart('Build a working time machine')
|
|
|
|
|
assert_not_nil p
|
|
|
|
|
assert_equal @timemachine.id, p.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_find_project_by_namepart_with_starts_with
|
|
|
|
|
p = Project.find_by_namepart('Build a')
|
|
|
|
|
assert_not_nil p
|
|
|
|
|
assert_equal @timemachine.id, p.id
|
|
|
|
|
end
|
2006-06-19 06:36:00 +00:00
|
|
|
|
2005-01-09 11:59:57 +00:00
|
|
|
end
|