annotate test/unit/time_entry_test.rb @ 1458:b1f4c9a2af24 bug_794

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