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