Workflow enhancement: editable and required fields configurable by role, tracker and status (#703, #3521).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9977 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -823,7 +823,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
def test_show_should_display_update_form_with_minimal_permissions
|
||||
Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
|
||||
Workflow.delete_all :role_id => 1
|
||||
WorkflowTransition.delete_all :role_id => 1
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :show, :id => 1
|
||||
@@ -1300,7 +1300,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
def test_get_new_with_minimal_permissions
|
||||
Role.find(1).update_attribute :permissions, [:add_issues]
|
||||
Workflow.delete_all :role_id => 1
|
||||
WorkflowTransition.delete_all :role_id => 1
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1, :tracker_id => 1
|
||||
@@ -1426,6 +1426,50 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
:attributes => {:name => 'issue[custom_field_values][2]', :value => 'Custom field value'}
|
||||
end
|
||||
|
||||
def test_get_new_should_mark_required_fields
|
||||
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
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, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
get :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
assert_select 'label[for=issue_start_date]' do
|
||||
assert_select 'span[class=required]', 0
|
||||
end
|
||||
assert_select 'label[for=issue_due_date]' do
|
||||
assert_select 'span[class=required]'
|
||||
end
|
||||
assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
|
||||
assert_select 'span[class=required]', 0
|
||||
end
|
||||
assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
|
||||
assert_select 'span[class=required]'
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_new_should_not_display_readonly_fields
|
||||
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
get :new, :project_id => 1
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
|
||||
assert_select 'input[name=?]', 'issue[start_date]'
|
||||
assert_select 'input[name=?]', 'issue[due_date]', 0
|
||||
assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
|
||||
assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
|
||||
end
|
||||
|
||||
def test_get_new_without_tracker_id
|
||||
@request.session[:user_id] = 2
|
||||
get :new, :project_id => 1
|
||||
@@ -1463,7 +1507,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5}
|
||||
assert_response :success
|
||||
assert_template 'attributes'
|
||||
assert_template 'form'
|
||||
|
||||
issue = assigns(:issue)
|
||||
assert_kind_of Issue, issue
|
||||
@@ -1474,10 +1518,10 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
def test_update_new_form_should_propose_transitions_based_on_initial_status
|
||||
@request.session[:user_id] = 2
|
||||
Workflow.delete_all
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
|
||||
WorkflowTransition.delete_all
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
|
||||
|
||||
xhr :post, :new, :project_id => 1,
|
||||
:issue => {:tracker_id => 1,
|
||||
@@ -1678,6 +1722,58 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
assert_error_tag :content => /Database can't be blank/
|
||||
end
|
||||
|
||||
def test_create_should_validate_required_fields
|
||||
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_no_difference 'Issue.count' do
|
||||
post :create, :project_id => 1, :issue => {
|
||||
:tracker_id => 2,
|
||||
:status_id => 1,
|
||||
:subject => 'Test',
|
||||
:start_date => '',
|
||||
:due_date => '',
|
||||
:custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
|
||||
}
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
assert_error_tag :content => /Due date can't be blank/i
|
||||
assert_error_tag :content => /Bar can't be blank/i
|
||||
end
|
||||
|
||||
def test_create_should_ignore_readonly_fields
|
||||
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
|
||||
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
|
||||
@request.session[:user_id] = 2
|
||||
|
||||
assert_difference 'Issue.count' do
|
||||
post :create, :project_id => 1, :issue => {
|
||||
:tracker_id => 2,
|
||||
:status_id => 1,
|
||||
:subject => 'Test',
|
||||
:start_date => '2012-07-14',
|
||||
:due_date => '2012-07-16',
|
||||
:custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
|
||||
}
|
||||
assert_response 302
|
||||
end
|
||||
|
||||
issue = Issue.first(:order => 'id DESC')
|
||||
assert_equal Date.parse('2012-07-14'), issue.start_date
|
||||
assert_nil issue.due_date
|
||||
assert_equal 'value1', issue.custom_field_value(cf1)
|
||||
assert_nil issue.custom_field_value(cf2)
|
||||
end
|
||||
|
||||
def test_post_create_with_watchers
|
||||
@request.session[:user_id] = 2
|
||||
ActionMailer::Base.deliveries.clear
|
||||
@@ -1917,7 +2013,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
context "without workflow privilege" do
|
||||
setup do
|
||||
Workflow.delete_all(["role_id = ?", Role.anonymous.id])
|
||||
WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
|
||||
Role.anonymous.add_permission! :add_issues, :add_issue_notes
|
||||
end
|
||||
|
||||
@@ -1976,9 +2072,9 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
context "with workflow privilege" do
|
||||
setup do
|
||||
Workflow.delete_all(["role_id = ?", Role.anonymous.id])
|
||||
Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
|
||||
Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
|
||||
WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
|
||||
WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
|
||||
WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
|
||||
Role.anonymous.add_permission! :add_issues, :add_issue_notes
|
||||
end
|
||||
|
||||
@@ -2286,7 +2382,7 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
:description => 'This is the description',
|
||||
:priority_id => 5}
|
||||
assert_response :success
|
||||
assert_template 'attributes'
|
||||
assert_template 'form'
|
||||
|
||||
issue = assigns(:issue)
|
||||
assert_kind_of Issue, issue
|
||||
@@ -2298,10 +2394,10 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
|
||||
def test_update_edit_form_should_propose_transitions_based_on_initial_status
|
||||
@request.session[:user_id] = 2
|
||||
Workflow.delete_all
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
|
||||
WorkflowTransition.delete_all
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
|
||||
|
||||
xhr :put, :new, :project_id => 1,
|
||||
:id => 2,
|
||||
@@ -2317,7 +2413,6 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
@request.session[:user_id] = 2
|
||||
xhr :put, :new, :project_id => 1,
|
||||
:id => 1,
|
||||
:project_change => '1',
|
||||
:issue => {:project_id => 2,
|
||||
:tracker_id => 2,
|
||||
:subject => 'This is the test_new issue',
|
||||
@@ -2845,13 +2940,13 @@ class IssuesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
|
||||
Workflow.delete_all
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
|
||||
WorkflowTransition.delete_all
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
|
||||
@request.session[:user_id] = 2
|
||||
get :bulk_edit, :ids => [1, 2]
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class RolesControllerTest < ActionController::TestCase
|
||||
assert_redirected_to '/roles'
|
||||
role = Role.find_by_name('RoleWithWorkflowCopy')
|
||||
assert_not_nil role
|
||||
assert_equal Role.find(1).workflows.size, role.workflows.size
|
||||
assert_equal Role.find(1).workflow_rules.size, role.workflow_rules.size
|
||||
end
|
||||
|
||||
def test_edit
|
||||
|
||||
@@ -66,7 +66,7 @@ class TrackersControllerTest < ActionController::TestCase
|
||||
assert_equal [1], tracker.project_ids.sort
|
||||
assert_equal Tracker::CORE_FIELDS, tracker.core_fields
|
||||
assert_equal [1, 6], tracker.custom_field_ids.sort
|
||||
assert_equal 0, tracker.workflows.count
|
||||
assert_equal 0, tracker.workflow_rules.count
|
||||
end
|
||||
|
||||
def create_with_disabled_core_fields
|
||||
@@ -86,7 +86,7 @@ class TrackersControllerTest < ActionController::TestCase
|
||||
assert_redirected_to :action => 'index'
|
||||
tracker = Tracker.find_by_name('New tracker')
|
||||
assert_equal 0, tracker.projects.count
|
||||
assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
|
||||
assert_equal Tracker.find(1).workflow_rules.count, tracker.workflow_rules.count
|
||||
end
|
||||
|
||||
def test_create_with_failure
|
||||
|
||||
@@ -37,7 +37,7 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
|
||||
count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
|
||||
count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
|
||||
assert_tag :tag => 'a', :content => count.to_s,
|
||||
:attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' }
|
||||
end
|
||||
@@ -51,9 +51,9 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
def test_get_edit_with_role_and_tracker
|
||||
Workflow.delete_all
|
||||
Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
|
||||
Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
|
||||
WorkflowTransition.delete_all
|
||||
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
|
||||
WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
|
||||
|
||||
get :edit, :role_id => 2, :tracker_id => 1
|
||||
assert_response :success
|
||||
@@ -79,7 +79,7 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
def test_get_edit_with_role_and_tracker_and_all_statuses
|
||||
Workflow.delete_all
|
||||
WorkflowTransition.delete_all
|
||||
|
||||
get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0'
|
||||
assert_response :success
|
||||
@@ -102,9 +102,9 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
}
|
||||
assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
|
||||
|
||||
assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
|
||||
assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
|
||||
assert_equal 3, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
assert_not_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
|
||||
assert_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4})
|
||||
end
|
||||
|
||||
def test_post_edit_with_additional_transitions
|
||||
@@ -115,27 +115,117 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
}
|
||||
assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
|
||||
|
||||
assert_equal 4, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
assert_equal 4, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
|
||||
w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5})
|
||||
w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5})
|
||||
assert ! w.author
|
||||
assert ! w.assignee
|
||||
w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1})
|
||||
w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1})
|
||||
assert w.author
|
||||
assert ! w.assignee
|
||||
w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
|
||||
w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2})
|
||||
assert ! w.author
|
||||
assert w.assignee
|
||||
w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4})
|
||||
w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4})
|
||||
assert w.author
|
||||
assert w.assignee
|
||||
end
|
||||
|
||||
def test_clear_workflow
|
||||
assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
|
||||
assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
|
||||
|
||||
post :edit, :role_id => 2, :tracker_id => 1
|
||||
assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
|
||||
end
|
||||
|
||||
def test_get_permissions
|
||||
get :permissions
|
||||
|
||||
assert_response :success
|
||||
assert_template 'permissions'
|
||||
assert_not_nil assigns(:roles)
|
||||
assert_not_nil assigns(:trackers)
|
||||
end
|
||||
|
||||
def test_get_permissions_with_role_and_tracker
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required')
|
||||
WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required')
|
||||
WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly')
|
||||
|
||||
get :permissions, :role_id => 1, :tracker_id => 2
|
||||
assert_response :success
|
||||
assert_template 'permissions'
|
||||
|
||||
assert_select 'input[name=role_id][value=1]'
|
||||
assert_select 'input[name=tracker_id][value=2]'
|
||||
|
||||
# Required field
|
||||
assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do
|
||||
assert_select 'option[value=]'
|
||||
assert_select 'option[value=][selected=selected]', 0
|
||||
assert_select 'option[value=readonly]', :text => 'Read-only'
|
||||
assert_select 'option[value=readonly][selected=selected]', 0
|
||||
assert_select 'option[value=required]', :text => 'Required'
|
||||
assert_select 'option[value=required][selected=selected]'
|
||||
end
|
||||
|
||||
# Read-only field
|
||||
assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do
|
||||
assert_select 'option[value=]'
|
||||
assert_select 'option[value=][selected=selected]', 0
|
||||
assert_select 'option[value=readonly]', :text => 'Read-only'
|
||||
assert_select 'option[value=readonly][selected=selected]'
|
||||
assert_select 'option[value=required]', :text => 'Required'
|
||||
assert_select 'option[value=required][selected=selected]', 0
|
||||
end
|
||||
|
||||
# Other field
|
||||
assert_select 'select[name=?]', 'permissions[due_date][3]' do
|
||||
assert_select 'option[value=]'
|
||||
assert_select 'option[value=][selected=selected]', 0
|
||||
assert_select 'option[value=readonly]', :text => 'Read-only'
|
||||
assert_select 'option[value=readonly][selected=selected]', 0
|
||||
assert_select 'option[value=required]', :text => 'Required'
|
||||
assert_select 'option[value=required][selected=selected]', 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_post_permissions
|
||||
WorkflowPermission.delete_all
|
||||
|
||||
post :permissions, :role_id => 1, :tracker_id => 2, :permissions => {
|
||||
'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''},
|
||||
'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''},
|
||||
'due_date' => {'1' => '', '2' => '', '3' => ''},
|
||||
}
|
||||
assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2'
|
||||
|
||||
workflows = WorkflowPermission.all
|
||||
assert_equal 3, workflows.size
|
||||
workflows.each do |workflow|
|
||||
assert_equal 1, workflow.role_id
|
||||
assert_equal 2, workflow.tracker_id
|
||||
end
|
||||
assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'}
|
||||
assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'}
|
||||
assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'}
|
||||
end
|
||||
|
||||
def test_post_permissions_should_clear_permissions
|
||||
WorkflowPermission.delete_all
|
||||
WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required')
|
||||
WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required')
|
||||
wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required')
|
||||
wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly')
|
||||
|
||||
post :permissions, :role_id => 1, :tracker_id => 2
|
||||
assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2'
|
||||
|
||||
workflows = WorkflowPermission.all
|
||||
assert_equal 2, workflows.size
|
||||
assert wf1.reload
|
||||
assert wf2.reload
|
||||
end
|
||||
|
||||
def test_get_copy
|
||||
@@ -192,7 +282,7 @@ class WorkflowsControllerTest < ActionController::TestCase
|
||||
|
||||
# Returns an array of status transitions that can be compared
|
||||
def status_transitions(conditions)
|
||||
Workflow.find(:all, :conditions => conditions,
|
||||
WorkflowTransition.find(:all, :conditions => conditions,
|
||||
:order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user