code layout clean up test_required_attributes_should_be_validated of unit issue test

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10646 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2012-10-13 10:55:09 +00:00
parent 0df2c4a975
commit 93daf6865e
1 changed files with 26 additions and 10 deletions

View File

@ -628,26 +628,42 @@ class IssueTest < ActiveSupport::TestCase
end end
def test_required_attributes_should_be_validated def test_required_attributes_should_be_validated
cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string',
:is_for_all => true, :tracker_ids => [1, 2])
WorkflowPermission.delete_all WorkflowPermission.delete_all
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required') WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'category_id', :rule => 'required') :role_id => 1, :field_name => 'due_date',
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') :rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
:role_id => 1, :field_name => 'category_id',
:rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
:role_id => 1, :field_name => cf.id.to_s,
:rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'start_date', :rule => 'required') WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2,
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf.id.to_s, :rule => 'required') :role_id => 1, :field_name => 'start_date',
:rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2,
:role_id => 1, :field_name => cf.id.to_s,
:rule => 'required')
user = User.find(2) user = User.find(2)
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Required fields', :author => user) issue = Issue.new(:project_id => 1, :tracker_id => 1,
assert_equal [cf.id.to_s, "category_id", "due_date"], issue.required_attribute_names(user).sort :status_id => 1, :subject => 'Required fields',
:author => user)
assert_equal [cf.id.to_s, "category_id", "due_date"],
issue.required_attribute_names(user).sort
assert !issue.save, "Issue was saved" assert !issue.save, "Issue was saved"
assert_equal ["Category can't be blank", "Due date can't be blank", "Foo can't be blank"], issue.errors.full_messages.sort assert_equal ["Category can't be blank", "Due date can't be blank", "Foo can't be blank"],
issue.errors.full_messages.sort
issue.tracker_id = 2 issue.tracker_id = 2
assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort
assert !issue.save, "Issue was saved" assert !issue.save, "Issue was saved"
assert_equal ["Foo can't be blank", "Start date can't be blank"], issue.errors.full_messages.sort assert_equal ["Foo can't be blank", "Start date can't be blank"],
issue.errors.full_messages.sort
issue.start_date = Date.today issue.start_date = Date.today
issue.custom_field_values = {cf.id.to_s => 'bar'} issue.custom_field_values = {cf.id.to_s => 'bar'}