annotate .svn/pristine/f5/f575043e242ce42c6c0b028c3162bbe2d7e93996.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class IssueStatusTest < ActiveSupport::TestCase
Chris@1296 21 fixtures :issue_statuses, :issues, :roles, :trackers
Chris@1296 22
Chris@1296 23 def test_create
Chris@1296 24 status = IssueStatus.new :name => "Assigned"
Chris@1296 25 assert !status.save
Chris@1296 26 # status name uniqueness
Chris@1296 27 assert_equal 1, status.errors.count
Chris@1296 28
Chris@1296 29 status.name = "Test Status"
Chris@1296 30 assert status.save
Chris@1296 31 assert !status.is_default
Chris@1296 32 end
Chris@1296 33
Chris@1296 34 def test_destroy
Chris@1296 35 status = IssueStatus.find(3)
Chris@1296 36 assert_difference 'IssueStatus.count', -1 do
Chris@1296 37 assert status.destroy
Chris@1296 38 end
Chris@1296 39 assert_nil WorkflowTransition.first(:conditions => {:old_status_id => status.id})
Chris@1296 40 assert_nil WorkflowTransition.first(:conditions => {:new_status_id => status.id})
Chris@1296 41 end
Chris@1296 42
Chris@1296 43 def test_destroy_status_in_use
Chris@1296 44 # Status assigned to an Issue
Chris@1296 45 status = Issue.find(1).status
Chris@1296 46 assert_raise(RuntimeError, "Can't delete status") { status.destroy }
Chris@1296 47 end
Chris@1296 48
Chris@1296 49 def test_default
Chris@1296 50 status = IssueStatus.default
Chris@1296 51 assert_kind_of IssueStatus, status
Chris@1296 52 end
Chris@1296 53
Chris@1296 54 def test_change_default
Chris@1296 55 status = IssueStatus.find(2)
Chris@1296 56 assert !status.is_default
Chris@1296 57 status.is_default = true
Chris@1296 58 assert status.save
Chris@1296 59 status.reload
Chris@1296 60
Chris@1296 61 assert_equal status, IssueStatus.default
Chris@1296 62 assert !IssueStatus.find(1).is_default
Chris@1296 63 end
Chris@1296 64
Chris@1296 65 def test_reorder_should_not_clear_default_status
Chris@1296 66 status = IssueStatus.default
Chris@1296 67 status.move_to_bottom
Chris@1296 68 status.reload
Chris@1296 69 assert status.is_default?
Chris@1296 70 end
Chris@1296 71
Chris@1296 72 def test_new_statuses_allowed_to
Chris@1296 73 WorkflowTransition.delete_all
Chris@1296 74
Chris@1296 75 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false)
Chris@1296 76 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false)
Chris@1296 77 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true)
Chris@1296 78 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :author => true, :assignee => true)
Chris@1296 79 status = IssueStatus.find(1)
Chris@1296 80 role = Role.find(1)
Chris@1296 81 tracker = Tracker.find(1)
Chris@1296 82
Chris@1296 83 assert_equal [2], status.new_statuses_allowed_to([role], tracker, false, false).map(&:id)
Chris@1296 84 assert_equal [2], status.find_new_statuses_allowed_to([role], tracker, false, false).map(&:id)
Chris@1296 85
Chris@1296 86 assert_equal [2, 3, 5], status.new_statuses_allowed_to([role], tracker, true, false).map(&:id)
Chris@1296 87 assert_equal [2, 3, 5], status.find_new_statuses_allowed_to([role], tracker, true, false).map(&:id)
Chris@1296 88
Chris@1296 89 assert_equal [2, 4, 5], status.new_statuses_allowed_to([role], tracker, false, true).map(&:id)
Chris@1296 90 assert_equal [2, 4, 5], status.find_new_statuses_allowed_to([role], tracker, false, true).map(&:id)
Chris@1296 91
Chris@1296 92 assert_equal [2, 3, 4, 5], status.new_statuses_allowed_to([role], tracker, true, true).map(&:id)
Chris@1296 93 assert_equal [2, 3, 4, 5], status.find_new_statuses_allowed_to([role], tracker, true, true).map(&:id)
Chris@1296 94 end
Chris@1296 95
Chris@1296 96 def test_update_done_ratios_with_issue_done_ratio_set_to_issue_field_should_change_nothing
Chris@1296 97 IssueStatus.find(1).update_attribute(:default_done_ratio, 50)
Chris@1296 98
Chris@1296 99 with_settings :issue_done_ratio => 'issue_field' do
Chris@1296 100 IssueStatus.update_issue_done_ratios
Chris@1296 101 assert_equal 0, Issue.count(:conditions => {:done_ratio => 50})
Chris@1296 102 end
Chris@1296 103 end
Chris@1296 104
Chris@1296 105 def test_update_done_ratios_with_issue_done_ratio_set_to_issue_status_should_update_issues
Chris@1296 106 IssueStatus.find(1).update_attribute(:default_done_ratio, 50)
Chris@1296 107
Chris@1296 108 with_settings :issue_done_ratio => 'issue_status' do
Chris@1296 109 IssueStatus.update_issue_done_ratios
Chris@1296 110 issues = Issue.all(:conditions => {:status_id => 1})
Chris@1296 111 assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
Chris@1296 112 end
Chris@1296 113 end
Chris@1296 114
Chris@1296 115 def test_sorted_scope
Chris@1296 116 assert_equal IssueStatus.all.sort, IssueStatus.sorted.all
Chris@1296 117 end
Chris@1296 118
Chris@1296 119 def test_named_scope
Chris@1296 120 status = IssueStatus.named("resolved").first
Chris@1296 121 assert_not_nil status
Chris@1296 122 assert_equal "Resolved", status.name
Chris@1296 123 end
Chris@1296 124 end