diff --git a/app/views/roles/list.rhtml b/app/views/roles/list.rhtml index 202fdf41..93b82138 100644 --- a/app/views/roles/list.rhtml +++ b/app/views/roles/list.rhtml @@ -24,6 +24,7 @@ <%= button_to(l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small", :disabled => role.builtin? ) %> + <% end %> diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index c834828c..0aabbb61 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -1,49 +1,4 @@ --- -roles_004: - name: Non member - id: 4 - builtin: 1 - permissions: | - --- - - :add_issues - - :edit_issues - - :manage_issue_relations - - :add_issue_notes - - :move_issues - - :save_queries - - :view_gantt - - :view_calendar - - :log_time - - :view_time_entries - - :comment_news - - :view_documents - - :manage_documents - - :view_wiki_pages - - :edit_wiki_pages - - :add_messages - - :view_files - - :manage_files - - :browse_repository - - :view_changesets - - position: 5 -roles_005: - name: Anonymous - id: 5 - builtin: 2 - permissions: | - --- - - :add_issue_notes - - :view_gantt - - :view_calendar - - :view_time_entries - - :view_documents - - :view_wiki_pages - - :view_files - - :browse_repository - - :view_changesets - - position: 6 roles_001: name: Manager id: 1 @@ -85,7 +40,7 @@ roles_001: - :browse_repository - :view_changesets - position: 2 + position: 1 roles_002: name: Developer id: 2 @@ -123,7 +78,7 @@ roles_002: - :browse_repository - :view_changesets - position: 3 + position: 2 roles_003: name: Reporter id: 3 @@ -139,7 +94,6 @@ roles_003: - :manage_issue_relations - :add_issue_notes - :move_issues - - :delete_issues - :manage_public_queries - :save_queries - :view_gantt @@ -160,4 +114,50 @@ roles_003: - :browse_repository - :view_changesets + position: 3 +roles_004: + name: Non member + id: 4 + builtin: 1 + permissions: | + --- + - :add_issues + - :edit_issues + - :manage_issue_relations + - :add_issue_notes + - :move_issues + - :save_queries + - :view_gantt + - :view_calendar + - :log_time + - :view_time_entries + - :comment_news + - :view_documents + - :manage_documents + - :view_wiki_pages + - :edit_wiki_pages + - :add_messages + - :view_files + - :manage_files + - :browse_repository + - :view_changesets + position: 4 +roles_005: + name: Anonymous + id: 5 + builtin: 2 + permissions: | + --- + - :add_issue_notes + - :view_gantt + - :view_calendar + - :view_time_entries + - :view_documents + - :view_wiki_pages + - :view_files + - :browse_repository + - :view_changesets + + position: 5 + \ No newline at end of file diff --git a/test/fixtures/workflows.yml b/test/fixtures/workflows.yml index 47e95e6e..bef5ae01 100644 --- a/test/fixtures/workflows.yml +++ b/test/fixtures/workflows.yml @@ -245,12 +245,6 @@ workflows_225: old_status_id: 3 id: 225 tracker_id: 3 -workflows_037: - new_status_id: 3 - role_id: 2 - old_status_id: 2 - id: 37 - tracker_id: 1 workflows_063: new_status_id: 4 role_id: 3 diff --git a/test/functional/roles_controller_test.rb b/test/functional/roles_controller_test.rb index 3c245edf..d70a4f0c 100644 --- a/test/functional/roles_controller_test.rb +++ b/test/functional/roles_controller_test.rb @@ -32,6 +32,18 @@ class RolesControllerTest < Test::Unit::TestCase @request.session[:user_id] = 1 # admin end + def test_get_index + get :index + assert_response :success + assert_template 'list' + + assert_not_nil assigns(:roles) + assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles) + + assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' }, + :content => 'Manager' + end + def test_get_new get :new assert_response :success @@ -89,4 +101,120 @@ class RolesControllerTest < Test::Unit::TestCase role = Role.find(1) assert_equal [:edit_project], role.permissions end + + def test_destroy + r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages]) + assert r.save + + post :destroy, :id => r + assert_redirected_to 'roles/list' + assert_nil Role.find_by_id(r.id) + end + + def test_destroy_role_in_use + post :destroy, :id => 1 + assert_redirected_to 'roles' + assert flash[:error] == 'This role is in use and can not be deleted.' + assert_not_nil Role.find_by_id(1) + end + + def test_get_workflow + get :workflow + assert_response :success + assert_template 'workflow' + assert_not_nil assigns(:roles) + assert_not_nil assigns(:trackers) + end + + def test_get_workflow_with_role_and_tracker + get :workflow, :role_id => 2, :tracker_id => 1 + assert_response :success + assert_template 'workflow' + # allowed transitions + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'issue_status[2][]', + :value => '1', + :checked => 'checked' } + # not allowed + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'issue_status[2][]', + :value => '3', + :checked => nil } + end + + def test_post_workflow + post :workflow, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']} + assert_redirected_to 'roles/workflow' + + 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}) + end + + def test_clear_workflow + assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 + + post :workflow, :role_id => 2, :tracker_id => 1 + assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) + end + + def test_get_report + get :report + assert_response :success + assert_template 'report' + + assert_not_nil assigns(:roles) + assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles) + + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'permissions[3][]', + :value => 'add_issues', + :checked => 'checked' } + + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'permissions[3][]', + :value => 'delete_issues', + :checked => nil } + end + + def test_post_report + post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']} + assert_redirected_to 'roles/list' + + assert_equal [:edit_issues], Role.find(1).permissions + assert_equal [:add_issues, :delete_issues], Role.find(3).permissions + assert Role.find(2).permissions.empty? + end + + def test_clear_all_permissions + post :report, :permissions => { '0' => '' } + assert_redirected_to 'roles/list' + assert Role.find(1).permissions.empty? + end + + def test_move_highest + post :move, :id => 3, :position => 'highest' + assert_redirected_to 'roles/list' + assert_equal 1, Role.find(3).position + end + + def test_move_higher + position = Role.find(3).position + post :move, :id => 3, :position => 'higher' + assert_redirected_to 'roles/list' + assert_equal position - 1, Role.find(3).position + end + + def test_move_lower + position = Role.find(2).position + post :move, :id => 2, :position => 'lower' + assert_redirected_to 'roles/list' + assert_equal position + 1, Role.find(2).position + end + + def test_move_lowest + post :move, :id => 2, :position => 'lowest' + assert_redirected_to 'roles/list' + assert_equal Role.count, Role.find(2).position + end end diff --git a/test/unit/tracker_test.rb b/test/unit/tracker_test.rb index 7adacef3..406bdd6d 100644 --- a/test/unit/tracker_test.rb +++ b/test/unit/tracker_test.rb @@ -22,12 +22,12 @@ class TrackerTest < Test::Unit::TestCase def test_copy_workflows source = Tracker.find(1) - assert_equal 90, source.workflows.size + assert_equal 89, source.workflows.size target = Tracker.new(:name => 'Target') assert target.save assert target.workflows.copy(source) target.reload - assert_equal 90, target.workflows.size + assert_equal 89, target.workflows.size end end