annotate .svn/pristine/65/65b88641ff8e4579cbf40b69a6bf7f5392a27740.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 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 IssuePriorityTest < ActiveSupport::TestCase
Chris@1295 21 fixtures :enumerations, :issues
Chris@1295 22
Chris@1295 23 def test_named_scope
Chris@1295 24 assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def test_default_should_return_the_default_priority
Chris@1295 28 assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
Chris@1295 29 end
Chris@1295 30
Chris@1295 31 def test_default_should_return_nil_when_no_default_priority
Chris@1295 32 IssuePriority.update_all :is_default => false
Chris@1295 33 assert_nil IssuePriority.default
Chris@1295 34 end
Chris@1295 35
Chris@1295 36 def test_should_be_an_enumeration
Chris@1295 37 assert IssuePriority.ancestors.include?(Enumeration)
Chris@1295 38 end
Chris@1295 39
Chris@1295 40 def test_objects_count
Chris@1295 41 # low priority
Chris@1295 42 assert_equal 6, IssuePriority.find(4).objects_count
Chris@1295 43 # urgent
Chris@1295 44 assert_equal 0, IssuePriority.find(7).objects_count
Chris@1295 45 end
Chris@1295 46
Chris@1295 47 def test_option_name
Chris@1295 48 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
Chris@1295 49 end
Chris@1295 50
Chris@1295 51 def test_should_be_created_at_last_position
Chris@1295 52 IssuePriority.delete_all
Chris@1295 53
Chris@1295 54 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
Chris@1295 55 assert_equal [1, 2, 3], priorities.map(&:position)
Chris@1295 56 end
Chris@1295 57
Chris@1295 58 def test_reset_positions_in_list_should_set_sequential_positions
Chris@1295 59 IssuePriority.delete_all
Chris@1295 60
Chris@1295 61 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
Chris@1295 62 priorities[0].update_attribute :position, 4
Chris@1295 63 priorities[1].update_attribute :position, 2
Chris@1295 64 priorities[2].update_attribute :position, 7
Chris@1295 65 assert_equal [4, 2, 7], priorities.map(&:reload).map(&:position)
Chris@1295 66
Chris@1295 67 priorities[0].reset_positions_in_list
Chris@1295 68 assert_equal [2, 1, 3], priorities.map(&:reload).map(&:position)
Chris@1295 69 end
Chris@1295 70
Chris@1295 71 def test_moving_in_list_should_reset_positions
Chris@1295 72 priority = IssuePriority.first
Chris@1295 73 priority.expects(:reset_positions_in_list).once
Chris@1295 74 priority.move_to = 'higher'
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 def test_clear_position_names_should_set_position_names_to_nil
Chris@1295 78 IssuePriority.clear_position_names
Chris@1295 79 assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
Chris@1295 80 end
Chris@1295 81
Chris@1295 82 def test_compute_position_names_with_default_priority
Chris@1295 83 IssuePriority.clear_position_names
Chris@1295 84
Chris@1295 85 IssuePriority.compute_position_names
Chris@1295 86 assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1295 87 end
Chris@1295 88
Chris@1295 89 def test_compute_position_names_without_default_priority_should_split_priorities
Chris@1295 90 IssuePriority.clear_position_names
Chris@1295 91 IssuePriority.update_all :is_default => false
Chris@1295 92
Chris@1295 93 IssuePriority.compute_position_names
Chris@1295 94 assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1295 95 end
Chris@1295 96
Chris@1295 97 def test_adding_a_priority_should_update_position_names
Chris@1295 98 priority = IssuePriority.create!(:name => 'New')
Chris@1295 99 assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1295 100 end
Chris@1295 101
Chris@1295 102 def test_destroying_a_priority_should_update_position_names
Chris@1295 103 IssuePriority.find_by_position_name('highest').destroy
Chris@1295 104 assert_equal %w(lowest default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
Chris@1295 105 end
Chris@1295 106 end