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 TimeEntryActivityTest < ActiveSupport::TestCase
|
Chris@1115
|
21 fixtures :enumerations, :time_entries, :custom_fields
|
Chris@1115
|
22
|
Chris@1115
|
23 include Redmine::I18n
|
Chris@0
|
24
|
Chris@0
|
25 def test_should_be_an_enumeration
|
Chris@0
|
26 assert TimeEntryActivity.ancestors.include?(Enumeration)
|
Chris@0
|
27 end
|
Chris@441
|
28
|
Chris@0
|
29 def test_objects_count
|
Chris@0
|
30 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
|
Chris@441
|
31 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
|
Chris@0
|
32 end
|
Chris@0
|
33
|
Chris@0
|
34 def test_option_name
|
Chris@0
|
35 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
|
Chris@0
|
36 end
|
Chris@0
|
37
|
Chris@0
|
38 def test_create_with_custom_field
|
Chris@0
|
39 field = TimeEntryActivityCustomField.find_by_name('Billable')
|
Chris@0
|
40 e = TimeEntryActivity.new(:name => 'Custom Data')
|
Chris@0
|
41 e.custom_field_values = {field.id => "1"}
|
Chris@0
|
42 assert e.save
|
Chris@0
|
43
|
Chris@0
|
44 e.reload
|
Chris@0
|
45 assert_equal "1", e.custom_value_for(field).value
|
Chris@0
|
46 end
|
Chris@0
|
47
|
Chris@0
|
48 def test_create_without_required_custom_field_should_fail
|
Chris@1115
|
49 set_language_if_valid 'en'
|
Chris@0
|
50 field = TimeEntryActivityCustomField.find_by_name('Billable')
|
Chris@0
|
51 field.update_attribute(:is_required, true)
|
Chris@0
|
52
|
Chris@0
|
53 e = TimeEntryActivity.new(:name => 'Custom Data')
|
Chris@0
|
54 assert !e.save
|
Chris@1115
|
55 assert_equal ["Billable can't be blank"], e.errors.full_messages
|
Chris@0
|
56 end
|
Chris@0
|
57
|
Chris@0
|
58 def test_create_with_required_custom_field_should_succeed
|
Chris@0
|
59 field = TimeEntryActivityCustomField.find_by_name('Billable')
|
Chris@0
|
60 field.update_attribute(:is_required, true)
|
Chris@0
|
61
|
Chris@0
|
62 e = TimeEntryActivity.new(:name => 'Custom Data')
|
Chris@0
|
63 e.custom_field_values = {field.id => "1"}
|
Chris@0
|
64 assert e.save
|
Chris@0
|
65 end
|
Chris@0
|
66
|
Chris@1115
|
67 def test_update_with_required_custom_field_change
|
Chris@1115
|
68 set_language_if_valid 'en'
|
Chris@0
|
69 field = TimeEntryActivityCustomField.find_by_name('Billable')
|
Chris@0
|
70 field.update_attribute(:is_required, true)
|
Chris@0
|
71
|
Chris@0
|
72 e = TimeEntryActivity.find(10)
|
Chris@0
|
73 assert e.available_custom_fields.include?(field)
|
Chris@0
|
74 # No change to custom field, record can be saved
|
Chris@0
|
75 assert e.save
|
Chris@0
|
76 # Blanking custom field, save should fail
|
Chris@0
|
77 e.custom_field_values = {field.id => ""}
|
Chris@0
|
78 assert !e.save
|
Chris@1115
|
79 assert_equal ["Billable can't be blank"], e.errors.full_messages
|
Chris@909
|
80
|
Chris@0
|
81 # Update custom field to valid value, save should succeed
|
Chris@0
|
82 e.custom_field_values = {field.id => "0"}
|
Chris@0
|
83 assert e.save
|
Chris@0
|
84 e.reload
|
Chris@0
|
85 assert_equal "0", e.custom_value_for(field).value
|
Chris@0
|
86 end
|
Chris@0
|
87 end
|
Chris@0
|
88
|