annotate .svn/pristine/65/65b88641ff8e4579cbf40b69a6bf7f5392a27740.svn-base @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents
children
rev   line source
Chris@1464 1 # Redmine - project management software
Chris@1464 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1464 3 #
Chris@1464 4 # This program is free software; you can redistribute it and/or
Chris@1464 5 # modify it under the terms of the GNU General Public License
Chris@1464 6 # as published by the Free Software Foundation; either version 2
Chris@1464 7 # of the License, or (at your option) any later version.
Chris@1464 8 #
Chris@1464 9 # This program is distributed in the hope that it will be useful,
Chris@1464 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1464 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1464 12 # GNU General Public License for more details.
Chris@1464 13 #
Chris@1464 14 # You should have received a copy of the GNU General Public License
Chris@1464 15 # along with this program; if not, write to the Free Software
Chris@1464 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1464 17
Chris@1464 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1464 19
Chris@1464 20 class IssuePriorityTest < ActiveSupport::TestCase
Chris@1464 21 fixtures :enumerations, :issues
Chris@1464 22
Chris@1464 23 def test_named_scope
Chris@1464 24 assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
Chris@1464 25 end
Chris@1464 26
Chris@1464 27 def test_default_should_return_the_default_priority
Chris@1464 28 assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
Chris@1464 29 end
Chris@1464 30
Chris@1464 31 def test_default_should_return_nil_when_no_default_priority
Chris@1464 32 IssuePriority.update_all :is_default => false
Chris@1464 33 assert_nil IssuePriority.default
Chris@1464 34 end
Chris@1464 35
Chris@1464 36 def test_should_be_an_enumeration
Chris@1464 37 assert IssuePriority.ancestors.include?(Enumeration)
Chris@1464 38 end
Chris@1464 39
Chris@1464 40 def test_objects_count
Chris@1464 41 # low priority
Chris@1464 42 assert_equal 6, IssuePriority.find(4).objects_count
Chris@1464 43 # urgent
Chris@1464 44 assert_equal 0, IssuePriority.find(7).objects_count
Chris@1464 45 end
Chris@1464 46
Chris@1464 47 def test_option_name
Chris@1464 48 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
Chris@1464 49 end
Chris@1464 50
Chris@1464 51 def test_should_be_created_at_last_position
Chris@1464 52 IssuePriority.delete_all
Chris@1464 53
Chris@1464 54 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
Chris@1464 55 assert_equal [1, 2, 3], priorities.map(&:position)
Chris@1464 56 end
Chris@1464 57
Chris@1464 58 def test_reset_positions_in_list_should_set_sequential_positions
Chris@1464 59 IssuePriority.delete_all
Chris@1464 60
Chris@1464 61 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
Chris@1464 62 priorities[0].update_attribute :position, 4
Chris@1464 63 priorities[1].update_attribute :position, 2
Chris@1464 64 priorities[2].update_attribute :position, 7
Chris@1464 65 assert_equal [4, 2, 7], priorities.map(&:reload).map(&:position)
Chris@1464 66
Chris@1464 67 priorities[0].reset_positions_in_list
Chris@1464 68 assert_equal [2, 1, 3], priorities.map(&:reload).map(&:position)
Chris@1464 69 end
Chris@1464 70
Chris@1464 71 def test_moving_in_list_should_reset_positions
Chris@1464 72 priority = IssuePriority.first
Chris@1464 73 priority.expects(:reset_positions_in_list).once
Chris@1464 74 priority.move_to = 'higher'
Chris@1464 75 end
Chris@1464 76
Chris@1464 77 def test_clear_position_names_should_set_position_names_to_nil
Chris@1464 78 IssuePriority.clear_position_names
Chris@1464 79 assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
Chris@1464 80 end
Chris@1464 81
Chris@1464 82 def test_compute_position_names_with_default_priority
Chris@1464 83 IssuePriority.clear_position_names
Chris@1464 84
Chris@1464 85 IssuePriority.compute_position_names
Chris@1464 86 assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1464 87 end
Chris@1464 88
Chris@1464 89 def test_compute_position_names_without_default_priority_should_split_priorities
Chris@1464 90 IssuePriority.clear_position_names
Chris@1464 91 IssuePriority.update_all :is_default => false
Chris@1464 92
Chris@1464 93 IssuePriority.compute_position_names
Chris@1464 94 assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1464 95 end
Chris@1464 96
Chris@1464 97 def test_adding_a_priority_should_update_position_names
Chris@1464 98 priority = IssuePriority.create!(:name => 'New')
Chris@1464 99 assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1464 100 end
Chris@1464 101
Chris@1464 102 def test_destroying_a_priority_should_update_position_names
Chris@1464 103 IssuePriority.find_by_position_name('highest').destroy
Chris@1464 104 assert_equal %w(lowest default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1464 105 end
Chris@1464 106 end