annotate test/unit/time_entry_activity_test.rb @ 976:0befb332f41a get_statistics

get stats up to current date
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 25 Oct 2012 13:50:45 +0100
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 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 TimeEntryActivityTest < ActiveSupport::TestCase
Chris@0 21 fixtures :enumerations, :time_entries
Chris@0 22
Chris@0 23 def test_should_be_an_enumeration
Chris@0 24 assert TimeEntryActivity.ancestors.include?(Enumeration)
Chris@0 25 end
Chris@441 26
Chris@0 27 def test_objects_count
Chris@0 28 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
Chris@441 29 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
Chris@0 30 end
Chris@0 31
Chris@0 32 def test_option_name
Chris@0 33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
Chris@0 34 end
Chris@0 35
Chris@0 36 def test_create_with_custom_field
Chris@0 37 field = TimeEntryActivityCustomField.find_by_name('Billable')
Chris@0 38 e = TimeEntryActivity.new(:name => 'Custom Data')
Chris@0 39 e.custom_field_values = {field.id => "1"}
Chris@0 40 assert e.save
Chris@0 41
Chris@0 42 e.reload
Chris@0 43 assert_equal "1", e.custom_value_for(field).value
Chris@0 44 end
Chris@0 45
Chris@0 46 def test_create_without_required_custom_field_should_fail
Chris@0 47 field = TimeEntryActivityCustomField.find_by_name('Billable')
Chris@0 48 field.update_attribute(:is_required, true)
Chris@0 49
Chris@0 50 e = TimeEntryActivity.new(:name => 'Custom Data')
Chris@0 51 assert !e.save
Chris@0 52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
Chris@0 53 end
Chris@0 54
Chris@0 55 def test_create_with_required_custom_field_should_succeed
Chris@0 56 field = TimeEntryActivityCustomField.find_by_name('Billable')
Chris@0 57 field.update_attribute(:is_required, true)
Chris@0 58
Chris@0 59 e = TimeEntryActivity.new(:name => 'Custom Data')
Chris@0 60 e.custom_field_values = {field.id => "1"}
Chris@0 61 assert e.save
Chris@0 62 end
Chris@0 63
Chris@0 64 def test_update_issue_with_required_custom_field_change
Chris@0 65 field = TimeEntryActivityCustomField.find_by_name('Billable')
Chris@0 66 field.update_attribute(:is_required, true)
Chris@0 67
Chris@0 68 e = TimeEntryActivity.find(10)
Chris@0 69 assert e.available_custom_fields.include?(field)
Chris@0 70 # No change to custom field, record can be saved
Chris@0 71 assert e.save
Chris@0 72 # Blanking custom field, save should fail
Chris@0 73 e.custom_field_values = {field.id => ""}
Chris@0 74 assert !e.save
Chris@909 75 assert e.errors[:custom_values]
Chris@909 76
Chris@0 77 # Update custom field to valid value, save should succeed
Chris@0 78 e.custom_field_values = {field.id => "0"}
Chris@0 79 assert e.save
Chris@0 80 e.reload
Chris@0 81 assert_equal "0", e.custom_value_for(field).value
Chris@0 82 end
Chris@0 83
Chris@0 84 end
Chris@0 85