obsolete.ChilliProject/test/unit/version_test.rb
Eric Davis 7b0cb6aba8 Upgraded to Rails 2.3.4 (#3597)
* Ran the Rails upgrade
* Upgraded to Rails Engines 2.3.2
* Added a plugin to let Engines override application views.
* Converted tests to use the new classes:
** ActionController::TestCase for functional
** ActiveSupport::TestCase for units
* Converted ActiveRecord::Error message to a string.
* ActiveRecord grouping returns an ordered hash which doesn't have #sort!
* Updated the I18n storage_units format.
* Added some default initializers from a fresh rails app
* Changed the order of check_box_tags and hidden_field_tags.  The hidden tag
  needs to appear first in Rails 2.3, otherwise it will override any value in
  the check_box_tag.
* Removed the custom handler for when the cookie store is tampered with.
  Rails 2.3 removed the TamperedWithCookie exception and instead Rails will not
  load the data from it when it's been tampered with (e.g. no user login).
* Fixed mail layouts, 2.3 has problems with implicit multipart emails that
  use layouts.  Also removed some custom Redmine mailer code.
* Fixed a bug that occurred in tests where the "required" span tag would be
  added to the :field_status translation.  This resulted in an email string of:

    <li>Status<span class="required"> *</span><span class="required"> *</span>

  Instead of:

    <li>Status: New</li>

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2887 e93f8b46-1217-0410-a6f0-8f06a7374b81
2009-09-13 17:14:35 +00:00

121 lines
5.0 KiB
Ruby

# Redmine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../test_helper'
class VersionTest < ActiveSupport::TestCase
fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions
def setup
end
def test_create
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '2011-03-25')
assert v.save
end
def test_invalid_effective_date_validation
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01')
assert !v.save
assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date)
end
def test_progress_should_be_0_with_no_assigned_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
assert_equal 0, v.completed_pourcent
assert_equal 0, v.closed_pourcent
end
def test_progress_should_be_0_with_unbegun_assigned_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v)
add_issue(v, :done_ratio => 0)
assert_progress_equal 0, v.completed_pourcent
assert_progress_equal 0, v.closed_pourcent
end
def test_progress_should_be_100_with_closed_assigned_issues
project = Project.find(1)
status = IssueStatus.find(:first, :conditions => {:is_closed => true})
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v, :status => status)
add_issue(v, :status => status, :done_ratio => 20)
add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25)
add_issue(v, :status => status, :estimated_hours => 15)
assert_progress_equal 100.0, v.completed_pourcent
assert_progress_equal 100.0, v.closed_pourcent
end
def test_progress_should_consider_done_ratio_of_open_assigned_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v)
add_issue(v, :done_ratio => 20)
add_issue(v, :done_ratio => 70)
assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_pourcent
assert_progress_equal 0, v.closed_pourcent
end
def test_progress_should_consider_closed_issues_as_completed
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v)
add_issue(v, :done_ratio => 20)
add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent
assert_progress_equal (100.0)/3, v.closed_pourcent
end
def test_progress_should_consider_estimated_hours_to_weigth_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v, :estimated_hours => 10)
add_issue(v, :estimated_hours => 20, :done_ratio => 30)
add_issue(v, :estimated_hours => 40, :done_ratio => 10)
add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent
assert_progress_equal 25.0/95.0*100, v.closed_pourcent
end
def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v, :done_ratio => 20)
add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true}))
add_issue(v, :estimated_hours => 10, :done_ratio => 30)
add_issue(v, :estimated_hours => 40, :done_ratio => 10)
assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent
assert_progress_equal 25.0/100.0*100, v.closed_pourcent
end
private
def add_issue(version, attributes={})
Issue.create!({:project => version.project,
:fixed_version => version,
:subject => 'Test',
:author => User.find(:first),
:tracker => version.project.trackers.find(:first)}.merge(attributes))
end
def assert_progress_equal(expected_float, actual_float, message="")
assert_in_delta(expected_float, actual_float, 0.000001, message="")
end
end