##// END OF EJS Templates
remove empty lines including trailing white space from test/unit/time_entry_activity_test.rb...
Toshi MARUYAMA -
r15956:359d7e43a0a9
parent child
Show More
@@ -1,130 +1,127
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class TimeEntryActivityTest < ActiveSupport::TestCase
20 class TimeEntryActivityTest < ActiveSupport::TestCase
21 fixtures :enumerations, :time_entries, :custom_fields,
21 fixtures :enumerations, :time_entries, :custom_fields,
22 :issues, :projects, :users,
22 :issues, :projects, :users,
23 :members, :roles, :member_roles,
23 :members, :roles, :member_roles,
24 :trackers, :issue_statuses,
24 :trackers, :issue_statuses,
25 :projects_trackers,
25 :projects_trackers,
26 :issue_categories,
26 :issue_categories,
27 :groups_users,
27 :groups_users,
28 :enabled_modules
28 :enabled_modules
29
29
30 include Redmine::I18n
30 include Redmine::I18n
31
31
32 def test_should_be_an_enumeration
32 def test_should_be_an_enumeration
33 assert TimeEntryActivity.ancestors.include?(Enumeration)
33 assert TimeEntryActivity.ancestors.include?(Enumeration)
34 end
34 end
35
35
36 def test_objects_count
36 def test_objects_count
37 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
37 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
38 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
38 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
39 end
39 end
40
40
41 def test_option_name
41 def test_option_name
42 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
42 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
43 end
43 end
44
44
45 def test_create_with_custom_field
45 def test_create_with_custom_field
46 field = TimeEntryActivityCustomField.find_by_name('Billable')
46 field = TimeEntryActivityCustomField.find_by_name('Billable')
47 e = TimeEntryActivity.new(:name => 'Custom Data')
47 e = TimeEntryActivity.new(:name => 'Custom Data')
48 e.custom_field_values = {field.id => "1"}
48 e.custom_field_values = {field.id => "1"}
49 assert e.save
49 assert e.save
50
50
51 e.reload
51 e.reload
52 assert_equal "1", e.custom_value_for(field).value
52 assert_equal "1", e.custom_value_for(field).value
53 end
53 end
54
54
55 def test_create_without_required_custom_field_should_fail
55 def test_create_without_required_custom_field_should_fail
56 set_language_if_valid 'en'
56 set_language_if_valid 'en'
57 field = TimeEntryActivityCustomField.find_by_name('Billable')
57 field = TimeEntryActivityCustomField.find_by_name('Billable')
58 field.update_attribute(:is_required, true)
58 field.update_attribute(:is_required, true)
59
59
60 e = TimeEntryActivity.new(:name => 'Custom Data')
60 e = TimeEntryActivity.new(:name => 'Custom Data')
61 assert !e.save
61 assert !e.save
62 assert_equal ["Billable cannot be blank"], e.errors.full_messages
62 assert_equal ["Billable cannot be blank"], e.errors.full_messages
63 end
63 end
64
64
65 def test_create_with_required_custom_field_should_succeed
65 def test_create_with_required_custom_field_should_succeed
66 field = TimeEntryActivityCustomField.find_by_name('Billable')
66 field = TimeEntryActivityCustomField.find_by_name('Billable')
67 field.update_attribute(:is_required, true)
67 field.update_attribute(:is_required, true)
68
68
69 e = TimeEntryActivity.new(:name => 'Custom Data')
69 e = TimeEntryActivity.new(:name => 'Custom Data')
70 e.custom_field_values = {field.id => "1"}
70 e.custom_field_values = {field.id => "1"}
71 assert e.save
71 assert e.save
72 end
72 end
73
73
74 def test_update_with_required_custom_field_change
74 def test_update_with_required_custom_field_change
75 set_language_if_valid 'en'
75 set_language_if_valid 'en'
76 field = TimeEntryActivityCustomField.find_by_name('Billable')
76 field = TimeEntryActivityCustomField.find_by_name('Billable')
77 field.update_attribute(:is_required, true)
77 field.update_attribute(:is_required, true)
78
78
79 e = TimeEntryActivity.find(10)
79 e = TimeEntryActivity.find(10)
80 assert e.available_custom_fields.include?(field)
80 assert e.available_custom_fields.include?(field)
81 # No change to custom field, record can be saved
81 # No change to custom field, record can be saved
82 assert e.save
82 assert e.save
83 # Blanking custom field, save should fail
83 # Blanking custom field, save should fail
84 e.custom_field_values = {field.id => ""}
84 e.custom_field_values = {field.id => ""}
85 assert !e.save
85 assert !e.save
86 assert_equal ["Billable cannot be blank"], e.errors.full_messages
86 assert_equal ["Billable cannot be blank"], e.errors.full_messages
87
87
88 # Update custom field to valid value, save should succeed
88 # Update custom field to valid value, save should succeed
89 e.custom_field_values = {field.id => "0"}
89 e.custom_field_values = {field.id => "0"}
90 assert e.save
90 assert e.save
91 e.reload
91 e.reload
92 assert_equal "0", e.custom_value_for(field).value
92 assert_equal "0", e.custom_value_for(field).value
93 end
93 end
94
94
95 def test_system_activity_with_child_in_use_should_be_in_use
95 def test_system_activity_with_child_in_use_should_be_in_use
96 project = Project.generate!
96 project = Project.generate!
97 system_activity = TimeEntryActivity.create!(:name => 'Activity')
97 system_activity = TimeEntryActivity.create!(:name => 'Activity')
98 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
98 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
99
99
100 TimeEntry.generate!(:project => project, :activity => project_activity)
100 TimeEntry.generate!(:project => project, :activity => project_activity)
101
101
102 assert project_activity.in_use?
102 assert project_activity.in_use?
103 assert system_activity.in_use?
103 assert system_activity.in_use?
104 end
104 end
105
105
106 def test_destroying_a_system_activity_should_reassign_children_activities
106 def test_destroying_a_system_activity_should_reassign_children_activities
107 project = Project.generate!
107 project = Project.generate!
108 entries = []
108 entries = []
109
110 system_activity = TimeEntryActivity.create!(:name => 'Activity')
109 system_activity = TimeEntryActivity.create!(:name => 'Activity')
111 entries << TimeEntry.generate!(:project => project, :activity => system_activity)
110 entries << TimeEntry.generate!(:project => project, :activity => system_activity)
112
113 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
111 project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
114 entries << TimeEntry.generate!(:project => project.reload, :activity => project_activity)
112 entries << TimeEntry.generate!(:project => project.reload, :activity => project_activity)
115
116 assert_difference 'TimeEntryActivity.count', -2 do
113 assert_difference 'TimeEntryActivity.count', -2 do
117 assert_nothing_raised do
114 assert_nothing_raised do
118 assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
115 assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
119 end
116 end
120 end
117 end
121 assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
118 assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
122 end
119 end
123
120
124 def test_project_activity_without_parent_should_not_disable_system_activities
121 def test_project_activity_without_parent_should_not_disable_system_activities
125 project = Project.find(1)
122 project = Project.find(1)
126 activity = TimeEntryActivity.create!(:name => 'Csutom', :project => project)
123 activity = TimeEntryActivity.create!(:name => 'Csutom', :project => project)
127 assert_include activity, project.activities
124 assert_include activity, project.activities
128 assert_include TimeEntryActivity.find(9), project.activities
125 assert_include TimeEntryActivity.find(9), project.activities
129 end
126 end
130 end
127 end
General Comments 0
You need to be logged in to leave comments. Login now