##// END OF EJS Templates
Rails3: test: replace deprecated errors.on at test_update_issue_with_required_custom_field_change of unit/time_entry_activity_test.rb...
Toshi MARUYAMA -
r7492:8dc797e19d8e
parent child
Show More
@@ -1,85 +1,85
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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
21 fixtures :enumerations, :time_entries
22
22
23 def test_should_be_an_enumeration
23 def test_should_be_an_enumeration
24 assert TimeEntryActivity.ancestors.include?(Enumeration)
24 assert TimeEntryActivity.ancestors.include?(Enumeration)
25 end
25 end
26
26
27 def test_objects_count
27 def test_objects_count
28 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
28 assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
29 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
29 assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
30 end
30 end
31
31
32 def test_option_name
32 def test_option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
34 end
34 end
35
35
36 def test_create_with_custom_field
36 def test_create_with_custom_field
37 field = TimeEntryActivityCustomField.find_by_name('Billable')
37 field = TimeEntryActivityCustomField.find_by_name('Billable')
38 e = TimeEntryActivity.new(:name => 'Custom Data')
38 e = TimeEntryActivity.new(:name => 'Custom Data')
39 e.custom_field_values = {field.id => "1"}
39 e.custom_field_values = {field.id => "1"}
40 assert e.save
40 assert e.save
41
41
42 e.reload
42 e.reload
43 assert_equal "1", e.custom_value_for(field).value
43 assert_equal "1", e.custom_value_for(field).value
44 end
44 end
45
45
46 def test_create_without_required_custom_field_should_fail
46 def test_create_without_required_custom_field_should_fail
47 field = TimeEntryActivityCustomField.find_by_name('Billable')
47 field = TimeEntryActivityCustomField.find_by_name('Billable')
48 field.update_attribute(:is_required, true)
48 field.update_attribute(:is_required, true)
49
49
50 e = TimeEntryActivity.new(:name => 'Custom Data')
50 e = TimeEntryActivity.new(:name => 'Custom Data')
51 assert !e.save
51 assert !e.save
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
53 end
53 end
54
54
55 def test_create_with_required_custom_field_should_succeed
55 def test_create_with_required_custom_field_should_succeed
56 field = TimeEntryActivityCustomField.find_by_name('Billable')
56 field = TimeEntryActivityCustomField.find_by_name('Billable')
57 field.update_attribute(:is_required, true)
57 field.update_attribute(:is_required, true)
58
58
59 e = TimeEntryActivity.new(:name => 'Custom Data')
59 e = TimeEntryActivity.new(:name => 'Custom Data')
60 e.custom_field_values = {field.id => "1"}
60 e.custom_field_values = {field.id => "1"}
61 assert e.save
61 assert e.save
62 end
62 end
63
63
64 def test_update_issue_with_required_custom_field_change
64 def test_update_issue_with_required_custom_field_change
65 field = TimeEntryActivityCustomField.find_by_name('Billable')
65 field = TimeEntryActivityCustomField.find_by_name('Billable')
66 field.update_attribute(:is_required, true)
66 field.update_attribute(:is_required, true)
67
67
68 e = TimeEntryActivity.find(10)
68 e = TimeEntryActivity.find(10)
69 assert e.available_custom_fields.include?(field)
69 assert e.available_custom_fields.include?(field)
70 # No change to custom field, record can be saved
70 # No change to custom field, record can be saved
71 assert e.save
71 assert e.save
72 # Blanking custom field, save should fail
72 # Blanking custom field, save should fail
73 e.custom_field_values = {field.id => ""}
73 e.custom_field_values = {field.id => ""}
74 assert !e.save
74 assert !e.save
75 assert e.errors.on(:custom_values)
75 assert e.errors[:custom_values]
76
76
77 # Update custom field to valid value, save should succeed
77 # Update custom field to valid value, save should succeed
78 e.custom_field_values = {field.id => "0"}
78 e.custom_field_values = {field.id => "0"}
79 assert e.save
79 assert e.save
80 e.reload
80 e.reload
81 assert_equal "0", e.custom_value_for(field).value
81 assert_equal "0", e.custom_value_for(field).value
82 end
82 end
83
83
84 end
84 end
85
85
General Comments 0
You need to be logged in to leave comments. Login now