annotate .svn/pristine/fb/fb9aed3d609c2f59022b54e8ad9664c84c259e08.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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