annotate .svn/pristine/3c/3cbd1a22df619e52f4440d56f4eefc4b5f35d719.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class TimeEntryTest < ActiveSupport::TestCase
Chris@1296 21 fixtures :issues, :projects, :users, :time_entries,
Chris@1296 22 :members, :roles, :member_roles,
Chris@1296 23 :trackers, :issue_statuses,
Chris@1296 24 :projects_trackers,
Chris@1296 25 :journals, :journal_details,
Chris@1296 26 :issue_categories, :enumerations,
Chris@1296 27 :groups_users,
Chris@1296 28 :enabled_modules,
Chris@1296 29 :workflows
Chris@1296 30
Chris@1296 31 def test_hours_format
Chris@1296 32 assertions = { "2" => 2.0,
Chris@1296 33 "21.1" => 21.1,
Chris@1296 34 "2,1" => 2.1,
Chris@1296 35 "1,5h" => 1.5,
Chris@1296 36 "7:12" => 7.2,
Chris@1296 37 "10h" => 10.0,
Chris@1296 38 "10 h" => 10.0,
Chris@1296 39 "45m" => 0.75,
Chris@1296 40 "45 m" => 0.75,
Chris@1296 41 "3h15" => 3.25,
Chris@1296 42 "3h 15" => 3.25,
Chris@1296 43 "3 h 15" => 3.25,
Chris@1296 44 "3 h 15m" => 3.25,
Chris@1296 45 "3 h 15 m" => 3.25,
Chris@1296 46 "3 hours" => 3.0,
Chris@1296 47 "12min" => 0.2,
Chris@1296 48 "12 Min" => 0.2,
Chris@1296 49 }
Chris@1296 50
Chris@1296 51 assertions.each do |k, v|
Chris@1296 52 t = TimeEntry.new(:hours => k)
Chris@1296 53 assert_equal v, t.hours, "Converting #{k} failed:"
Chris@1296 54 end
Chris@1296 55 end
Chris@1296 56
Chris@1296 57 def test_hours_should_default_to_nil
Chris@1296 58 assert_nil TimeEntry.new.hours
Chris@1296 59 end
Chris@1296 60
Chris@1296 61 def test_spent_on_with_blank
Chris@1296 62 c = TimeEntry.new
Chris@1296 63 c.spent_on = ''
Chris@1296 64 assert_nil c.spent_on
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def test_spent_on_with_nil
Chris@1296 68 c = TimeEntry.new
Chris@1296 69 c.spent_on = nil
Chris@1296 70 assert_nil c.spent_on
Chris@1296 71 end
Chris@1296 72
Chris@1296 73 def test_spent_on_with_string
Chris@1296 74 c = TimeEntry.new
Chris@1296 75 c.spent_on = "2011-01-14"
Chris@1296 76 assert_equal Date.parse("2011-01-14"), c.spent_on
Chris@1296 77 end
Chris@1296 78
Chris@1296 79 def test_spent_on_with_invalid_string
Chris@1296 80 c = TimeEntry.new
Chris@1296 81 c.spent_on = "foo"
Chris@1296 82 assert_nil c.spent_on
Chris@1296 83 end
Chris@1296 84
Chris@1296 85 def test_spent_on_with_date
Chris@1296 86 c = TimeEntry.new
Chris@1296 87 c.spent_on = Date.today
Chris@1296 88 assert_equal Date.today, c.spent_on
Chris@1296 89 end
Chris@1296 90
Chris@1296 91 def test_spent_on_with_time
Chris@1296 92 c = TimeEntry.new
Chris@1296 93 c.spent_on = Time.now
Chris@1296 94 assert_equal Date.today, c.spent_on
Chris@1296 95 end
Chris@1296 96
Chris@1296 97 def test_validate_time_entry
Chris@1296 98 anon = User.anonymous
Chris@1296 99 project = Project.find(1)
Chris@1296 100 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
Chris@1296 101 :priority => IssuePriority.all.first, :subject => 'test_create',
Chris@1296 102 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
Chris@1296 103 assert issue.save
Chris@1296 104 activity = TimeEntryActivity.find_by_name('Design')
Chris@1296 105 te = TimeEntry.create(:spent_on => '2010-01-01',
Chris@1296 106 :hours => 100000,
Chris@1296 107 :issue => issue,
Chris@1296 108 :project => project,
Chris@1296 109 :user => anon,
Chris@1296 110 :activity => activity)
Chris@1296 111 assert_equal 1, te.errors.count
Chris@1296 112 end
Chris@1296 113
Chris@1296 114 def test_set_project_if_nil
Chris@1296 115 anon = User.anonymous
Chris@1296 116 project = Project.find(1)
Chris@1296 117 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
Chris@1296 118 :priority => IssuePriority.all.first, :subject => 'test_create',
Chris@1296 119 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
Chris@1296 120 assert issue.save
Chris@1296 121 activity = TimeEntryActivity.find_by_name('Design')
Chris@1296 122 te = TimeEntry.create(:spent_on => '2010-01-01',
Chris@1296 123 :hours => 10,
Chris@1296 124 :issue => issue,
Chris@1296 125 :user => anon,
Chris@1296 126 :activity => activity)
Chris@1296 127 assert_equal project.id, te.project.id
Chris@1296 128 end
Chris@1296 129 end