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