summaryrefslogtreecommitdiffstats
path: root/test/functional/workflows_controller_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-25 02:54:47 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-02-25 02:54:47 +0000
commitb6c794d16b47bf353a1a2dfc00e9cbd078525ee8 (patch)
tree7dec97be4c38b4e3b6321f7c55b81697ca6f5ee2 /test/functional/workflows_controller_test.rb
parentc6f71f727bc73188ce7285c6e19bf50553246ec7 (diff)
downloadredmine-b6c794d16b47bf353a1a2dfc00e9cbd078525ee8.tar.gz
redmine-b6c794d16b47bf353a1a2dfc00e9cbd078525ee8.zip
Bulk edit workflows for multiple trackers/roles (#16164).
git-svn-id: http://svn.redmine.org/redmine/trunk@12924 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/workflows_controller_test.rb')
-rw-r--r--test/functional/workflows_controller_test.rb136
1 files changed, 73 insertions, 63 deletions
diff --git a/test/functional/workflows_controller_test.rb b/test/functional/workflows_controller_test.rb
index 09cfc12bf..ea00cbc77 100644
--- a/test/functional/workflows_controller_test.rb
+++ b/test/functional/workflows_controller_test.rb
@@ -39,8 +39,6 @@ class WorkflowsControllerTest < ActionController::TestCase
get :edit
assert_response :success
assert_template 'edit'
- assert_not_nil assigns(:roles)
- assert_not_nil assigns(:trackers)
end
def test_get_edit_with_role_and_tracker
@@ -57,18 +55,11 @@ class WorkflowsControllerTest < ActionController::TestCase
assert_equal [2, 3, 5], assigns(:statuses).collect(&:id)
# allowed transitions
- assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
- :name => 'issue_status[3][5][]',
- :value => 'always',
- :checked => 'checked' }
+ assert_select 'input[type=checkbox][name=?][value=1][checked=checked]', 'transitions[3][5][always]'
# not allowed
- assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
- :name => 'issue_status[3][2][]',
- :value => 'always',
- :checked => nil }
+ assert_select 'input[type=checkbox][name=?][value=1]:not([checked=checked])', 'transitions[3][2][always]'
# unused
- assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
- :name => 'issue_status[1][1][]' }
+ assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]', 0
end
def test_get_edit_with_role_and_tracker_and_all_statuses
@@ -81,19 +72,18 @@ class WorkflowsControllerTest < ActionController::TestCase
assert_not_nil assigns(:statuses)
assert_equal IssueStatus.count, assigns(:statuses).size
- assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
- :name => 'issue_status[1][1][]',
- :value => 'always',
- :checked => nil }
+ assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]'
end
def test_post_edit
+ WorkflowTransition.delete_all
+
post :edit, :role_id => 2, :tracker_id => 1,
- :issue_status => {
- '4' => {'5' => ['always']},
- '3' => {'1' => ['always'], '2' => ['always']}
+ :transitions => {
+ '4' => {'5' => {'always' => '1'}},
+ '3' => {'1' => {'always' => '1'}, '2' => {'always' => '1'}}
}
- assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
+ assert_response 302
assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count
assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first
@@ -101,12 +91,16 @@ class WorkflowsControllerTest < ActionController::TestCase
end
def test_post_edit_with_additional_transitions
+ WorkflowTransition.delete_all
+
post :edit, :role_id => 2, :tracker_id => 1,
- :issue_status => {
- '4' => {'5' => ['always']},
- '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']}
+ :transitions => {
+ '4' => {'5' => {'always' => '1', 'author' => '0', 'assignee' => '0'}},
+ '3' => {'1' => {'always' => '0', 'author' => '1', 'assignee' => '0'},
+ '2' => {'always' => '0', 'author' => '0', 'assignee' => '1'},
+ '4' => {'always' => '0', 'author' => '1', 'assignee' => '1'}}
}
- assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1'
+ assert_response 302
assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count
@@ -124,20 +118,11 @@ class WorkflowsControllerTest < ActionController::TestCase
assert w.assignee
end
- def test_clear_workflow
- assert WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count > 0
-
- post :edit, :role_id => 1, :tracker_id => 2
- assert_equal 0, WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count
- 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
@@ -150,11 +135,11 @@ class WorkflowsControllerTest < ActionController::TestCase
assert_response :success
assert_template 'permissions'
- assert_select 'input[name=role_id][value=1]'
- assert_select 'input[name=tracker_id][value=2]'
+ assert_select 'input[name=?][value=1]', 'role_id[]'
+ assert_select 'input[name=?][value=2]', 'tracker_id[]'
# Required field
- assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do
+ assert_select 'select[name=?]', 'permissions[2][assigned_to_id]' do
assert_select 'option[value=]'
assert_select 'option[value=][selected=selected]', 0
assert_select 'option[value=readonly]', :text => 'Read-only'
@@ -164,7 +149,7 @@ class WorkflowsControllerTest < ActionController::TestCase
end
# Read-only field
- assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do
+ assert_select 'select[name=?]', 'permissions[3][fixed_version_id]' do
assert_select 'option[value=]'
assert_select 'option[value=][selected=selected]', 0
assert_select 'option[value=readonly]', :text => 'Read-only'
@@ -174,7 +159,7 @@ class WorkflowsControllerTest < ActionController::TestCase
end
# Other field
- assert_select 'select[name=?]', 'permissions[due_date][3]' do
+ assert_select 'select[name=?]', 'permissions[3][due_date]' do
assert_select 'option[value=]'
assert_select 'option[value=][selected=selected]', 0
assert_select 'option[value=readonly]', :text => 'Read-only'
@@ -193,7 +178,7 @@ class WorkflowsControllerTest < ActionController::TestCase
# Custom field that is always required
# The default option is "(Required)"
- assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do
+ assert_select 'select[name=?]', "permissions[3][#{cf.id}]" do
assert_select 'option[value=]'
assert_select 'option[value=readonly]', :text => 'Read-only'
assert_select 'option[value=required]', 0
@@ -209,15 +194,56 @@ class WorkflowsControllerTest < ActionController::TestCase
assert_response :success
assert_template 'permissions'
- assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf1.id}][1]"
- assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf3.id}][1]"
+ assert_select 'select[name=?]:not(.disabled)', "permissions[1][#{cf1.id}]"
+ assert_select 'select[name=?]:not(.disabled)', "permissions[1][#{cf3.id}]"
- assert_select 'select[name=?][disabled=disabled]', "permissions[#{cf2.id}][1]" do
+ assert_select 'select[name=?][disabled=disabled]', "permissions[1][#{cf2.id}]" do
assert_select 'option[value=][selected=selected]', :text => 'Hidden'
end
end
- def test_get_permissions_with_role_and_tracker_and_all_statuses
+ def test_get_permissions_with_missing_permissions_for_roles_should_default_to_no_change
+ WorkflowPermission.delete_all
+ WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required')
+
+ get :permissions, :role_id => [1, 2], :tracker_id => 2
+ assert_response :success
+
+ assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do
+ assert_select 'option[selected]', 1
+ assert_select 'option[selected][value=no_change]'
+ end
+ end
+
+ def test_get_permissions_with_different_permissions_for_roles_should_default_to_no_change
+ WorkflowPermission.delete_all
+ WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required')
+ WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'readonly')
+
+ get :permissions, :role_id => [1, 2], :tracker_id => 2
+ assert_response :success
+
+ assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do
+ assert_select 'option[selected]', 1
+ assert_select 'option[selected][value=no_change]'
+ end
+ end
+
+ def test_get_permissions_with_same_permissions_for_roles_should_default_to_permission
+ WorkflowPermission.delete_all
+ WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required')
+ WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required')
+
+ get :permissions, :role_id => [1, 2], :tracker_id => 2
+ assert_response :success
+
+ assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do
+ assert_select 'option[selected]', 1
+ assert_select 'option[selected][value=required]'
+ end
+ end
+
+ def test_get_permissions_with_role_and_tracker_and_all_statuses_should_show_all_statuses
WorkflowTransition.delete_all
get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0'
@@ -229,11 +255,11 @@ class WorkflowsControllerTest < ActionController::TestCase
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' => ''},
+ '1' => {'assigned_to_id' => '', 'fixed_version_id' => 'required', 'due_date' => ''},
+ '2' => {'assigned_to_id' => 'readonly', 'fixed_version_id' => 'readonly', 'due_date' => ''},
+ '3' => {'assigned_to_id' => '', 'fixed_version_id' => '', 'due_date' => ''}
}
- assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2'
+ assert_response 302
workflows = WorkflowPermission.all
assert_equal 3, workflows.size
@@ -246,22 +272,6 @@ class WorkflowsControllerTest < ActionController::TestCase
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
get :copy
assert_response :success