annotate .svn/pristine/cc/ccd0c6df52e1bfff4e857e7d0c8fc8f47b679871.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class TrackerTest < ActiveSupport::TestCase
Chris@1295 21 fixtures :trackers, :workflows, :issue_statuses, :roles, :issues
Chris@1295 22
Chris@1295 23 def test_sorted_scope
Chris@1295 24 assert_equal Tracker.all.sort, Tracker.sorted.all
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def test_named_scope
Chris@1295 28 assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first
Chris@1295 29 end
Chris@1295 30
Chris@1295 31 def test_copy_workflows
Chris@1295 32 source = Tracker.find(1)
Chris@1295 33 assert_equal 89, source.workflow_rules.size
Chris@1295 34
Chris@1295 35 target = Tracker.new(:name => 'Target')
Chris@1295 36 assert target.save
Chris@1295 37 target.workflow_rules.copy(source)
Chris@1295 38 target.reload
Chris@1295 39 assert_equal 89, target.workflow_rules.size
Chris@1295 40 end
Chris@1295 41
Chris@1295 42 def test_issue_statuses
Chris@1295 43 tracker = Tracker.find(1)
Chris@1295 44 WorkflowTransition.delete_all
Chris@1295 45 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
Chris@1295 46 WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
Chris@1295 47
Chris@1295 48 assert_kind_of Array, tracker.issue_statuses
Chris@1295 49 assert_kind_of IssueStatus, tracker.issue_statuses.first
Chris@1295 50 assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id)
Chris@1295 51 end
Chris@1295 52
Chris@1295 53 def test_issue_statuses_empty
Chris@1295 54 WorkflowTransition.delete_all("tracker_id = 1")
Chris@1295 55 assert_equal [], Tracker.find(1).issue_statuses
Chris@1295 56 end
Chris@1295 57
Chris@1295 58 def test_issue_statuses_should_be_empty_for_new_record
Chris@1295 59 assert_equal [], Tracker.new.issue_statuses
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def test_core_fields_should_be_enabled_by_default
Chris@1295 63 tracker = Tracker.new
Chris@1295 64 assert_equal Tracker::CORE_FIELDS, tracker.core_fields
Chris@1295 65 assert_equal [], tracker.disabled_core_fields
Chris@1295 66 end
Chris@1295 67
Chris@1295 68 def test_core_fields
Chris@1295 69 tracker = Tracker.new
Chris@1295 70 tracker.core_fields = %w(assigned_to_id due_date)
Chris@1295 71
Chris@1295 72 assert_equal %w(assigned_to_id due_date), tracker.core_fields
Chris@1295 73 assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
Chris@1295 74 end
Chris@1295 75
Chris@1295 76 def test_core_fields_should_return_fields_enabled_for_any_tracker
Chris@1295 77 trackers = []
Chris@1295 78 trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
Chris@1295 79 trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
Chris@1295 80 trackers << Tracker.new(:core_fields => [])
Chris@1295 81
Chris@1295 82 assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
Chris@1295 83 assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def test_core_fields_should_return_all_fields_for_an_empty_argument
Chris@1295 87 assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
Chris@1295 88 assert_equal [], Tracker.disabled_core_fields([])
Chris@1295 89 end
Chris@1295 90
Chris@1295 91 def test_sort_should_sort_by_position
Chris@1295 92 a = Tracker.new(:name => 'Tracker A', :position => 2)
Chris@1295 93 b = Tracker.new(:name => 'Tracker B', :position => 1)
Chris@1295 94
Chris@1295 95 assert_equal [b, a], [a, b].sort
Chris@1295 96 end
Chris@1295 97
Chris@1295 98 def test_destroying_a_tracker_without_issues_should_not_raise_an_error
Chris@1295 99 tracker = Tracker.find(1)
Chris@1295 100 Issue.delete_all :tracker_id => tracker.id
Chris@1295 101
Chris@1295 102 assert_difference 'Tracker.count', -1 do
Chris@1295 103 assert_nothing_raised do
Chris@1295 104 tracker.destroy
Chris@1295 105 end
Chris@1295 106 end
Chris@1295 107 end
Chris@1295 108
Chris@1295 109 def test_destroying_a_tracker_with_issues_should_raise_an_error
Chris@1295 110 tracker = Tracker.find(1)
Chris@1295 111
Chris@1295 112 assert_no_difference 'Tracker.count' do
Chris@1295 113 assert_raise Exception do
Chris@1295 114 tracker.destroy
Chris@1295 115 end
Chris@1295 116 end
Chris@1295 117 end
Chris@1295 118 end