annotate .svn/pristine/96/96da29427be16ec91048978883152cdf19376c7c.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +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 TimeEntryTest < ActiveSupport::TestCase
Chris@1494 21 fixtures :issues, :projects, :users, :time_entries,
Chris@1494 22 :members, :roles, :member_roles,
Chris@1494 23 :trackers, :issue_statuses,
Chris@1494 24 :projects_trackers,
Chris@1494 25 :journals, :journal_details,
Chris@1494 26 :issue_categories, :enumerations,
Chris@1494 27 :groups_users,
Chris@1494 28 :enabled_modules
Chris@1494 29
Chris@1494 30 def test_hours_format
Chris@1494 31 assertions = { "2" => 2.0,
Chris@1494 32 "21.1" => 21.1,
Chris@1494 33 "2,1" => 2.1,
Chris@1494 34 "1,5h" => 1.5,
Chris@1494 35 "7:12" => 7.2,
Chris@1494 36 "10h" => 10.0,
Chris@1494 37 "10 h" => 10.0,
Chris@1494 38 "45m" => 0.75,
Chris@1494 39 "45 m" => 0.75,
Chris@1494 40 "3h15" => 3.25,
Chris@1494 41 "3h 15" => 3.25,
Chris@1494 42 "3 h 15" => 3.25,
Chris@1494 43 "3 h 15m" => 3.25,
Chris@1494 44 "3 h 15 m" => 3.25,
Chris@1494 45 "3 hours" => 3.0,
Chris@1494 46 "12min" => 0.2,
Chris@1494 47 "12 Min" => 0.2,
Chris@1494 48 }
Chris@1494 49
Chris@1494 50 assertions.each do |k, v|
Chris@1494 51 t = TimeEntry.new(:hours => k)
Chris@1494 52 assert_equal v, t.hours, "Converting #{k} failed:"
Chris@1494 53 end
Chris@1494 54 end
Chris@1494 55
Chris@1494 56 def test_hours_should_default_to_nil
Chris@1494 57 assert_nil TimeEntry.new.hours
Chris@1494 58 end
Chris@1494 59
Chris@1494 60 def test_spent_on_with_blank
Chris@1494 61 c = TimeEntry.new
Chris@1494 62 c.spent_on = ''
Chris@1494 63 assert_nil c.spent_on
Chris@1494 64 end
Chris@1494 65
Chris@1494 66 def test_spent_on_with_nil
Chris@1494 67 c = TimeEntry.new
Chris@1494 68 c.spent_on = nil
Chris@1494 69 assert_nil c.spent_on
Chris@1494 70 end
Chris@1494 71
Chris@1494 72 def test_spent_on_with_string
Chris@1494 73 c = TimeEntry.new
Chris@1494 74 c.spent_on = "2011-01-14"
Chris@1494 75 assert_equal Date.parse("2011-01-14"), c.spent_on
Chris@1494 76 end
Chris@1494 77
Chris@1494 78 def test_spent_on_with_invalid_string
Chris@1494 79 c = TimeEntry.new
Chris@1494 80 c.spent_on = "foo"
Chris@1494 81 assert_nil c.spent_on
Chris@1494 82 end
Chris@1494 83
Chris@1494 84 def test_spent_on_with_date
Chris@1494 85 c = TimeEntry.new
Chris@1494 86 c.spent_on = Date.today
Chris@1494 87 assert_equal Date.today, c.spent_on
Chris@1494 88 end
Chris@1494 89
Chris@1494 90 def test_spent_on_with_time
Chris@1494 91 c = TimeEntry.new
Chris@1494 92 c.spent_on = Time.now
Chris@1494 93 assert_equal Date.today, c.spent_on
Chris@1494 94 end
Chris@1494 95
Chris@1494 96 def test_validate_time_entry
Chris@1494 97 anon = User.anonymous
Chris@1494 98 project = Project.find(1)
Chris@1494 99 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
Chris@1494 100 :priority => IssuePriority.all.first, :subject => 'test_create',
Chris@1494 101 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
Chris@1494 102 assert issue.save
Chris@1494 103 activity = TimeEntryActivity.find_by_name('Design')
Chris@1494 104 te = TimeEntry.create(:spent_on => '2010-01-01',
Chris@1494 105 :hours => 100000,
Chris@1494 106 :issue => issue,
Chris@1494 107 :project => project,
Chris@1494 108 :user => anon,
Chris@1494 109 :activity => activity)
Chris@1494 110 assert_equal 1, te.errors.count
Chris@1494 111 end
Chris@1494 112
Chris@1494 113 def test_spent_on_with_2_digits_year_should_not_be_valid
Chris@1494 114 entry = TimeEntry.new(:project => Project.find(1), :user => User.find(1), :activity => TimeEntryActivity.first, :hours => 1)
Chris@1494 115 entry.spent_on = "09-02-04"
Chris@1494 116 assert !entry.valid?
Chris@1494 117 assert_include I18n.translate('activerecord.errors.messages.not_a_date'), entry.errors[:spent_on]
Chris@1494 118 end
Chris@1494 119
Chris@1494 120 def test_set_project_if_nil
Chris@1494 121 anon = User.anonymous
Chris@1494 122 project = Project.find(1)
Chris@1494 123 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
Chris@1494 124 :priority => IssuePriority.all.first, :subject => 'test_create',
Chris@1494 125 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
Chris@1494 126 assert issue.save
Chris@1494 127 activity = TimeEntryActivity.find_by_name('Design')
Chris@1494 128 te = TimeEntry.create(:spent_on => '2010-01-01',
Chris@1494 129 :hours => 10,
Chris@1494 130 :issue => issue,
Chris@1494 131 :user => anon,
Chris@1494 132 :activity => activity)
Chris@1494 133 assert_equal project.id, te.project.id
Chris@1494 134 end
Chris@1494 135 end