Mercurial > hg > soundsoftware-site
comparison test/unit/time_entry_activity_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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, :custom_fields |
22 | |
23 include Redmine::I18n | |
22 | 24 |
23 def test_should_be_an_enumeration | 25 def test_should_be_an_enumeration |
24 assert TimeEntryActivity.ancestors.include?(Enumeration) | 26 assert TimeEntryActivity.ancestors.include?(Enumeration) |
25 end | 27 end |
26 | 28 |
42 e.reload | 44 e.reload |
43 assert_equal "1", e.custom_value_for(field).value | 45 assert_equal "1", e.custom_value_for(field).value |
44 end | 46 end |
45 | 47 |
46 def test_create_without_required_custom_field_should_fail | 48 def test_create_without_required_custom_field_should_fail |
49 set_language_if_valid 'en' | |
47 field = TimeEntryActivityCustomField.find_by_name('Billable') | 50 field = TimeEntryActivityCustomField.find_by_name('Billable') |
48 field.update_attribute(:is_required, true) | 51 field.update_attribute(:is_required, true) |
49 | 52 |
50 e = TimeEntryActivity.new(:name => 'Custom Data') | 53 e = TimeEntryActivity.new(:name => 'Custom Data') |
51 assert !e.save | 54 assert !e.save |
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values) | 55 assert_equal ["Billable can't be blank"], e.errors.full_messages |
53 end | 56 end |
54 | 57 |
55 def test_create_with_required_custom_field_should_succeed | 58 def test_create_with_required_custom_field_should_succeed |
56 field = TimeEntryActivityCustomField.find_by_name('Billable') | 59 field = TimeEntryActivityCustomField.find_by_name('Billable') |
57 field.update_attribute(:is_required, true) | 60 field.update_attribute(:is_required, true) |
59 e = TimeEntryActivity.new(:name => 'Custom Data') | 62 e = TimeEntryActivity.new(:name => 'Custom Data') |
60 e.custom_field_values = {field.id => "1"} | 63 e.custom_field_values = {field.id => "1"} |
61 assert e.save | 64 assert e.save |
62 end | 65 end |
63 | 66 |
64 def test_update_issue_with_required_custom_field_change | 67 def test_update_with_required_custom_field_change |
68 set_language_if_valid 'en' | |
65 field = TimeEntryActivityCustomField.find_by_name('Billable') | 69 field = TimeEntryActivityCustomField.find_by_name('Billable') |
66 field.update_attribute(:is_required, true) | 70 field.update_attribute(:is_required, true) |
67 | 71 |
68 e = TimeEntryActivity.find(10) | 72 e = TimeEntryActivity.find(10) |
69 assert e.available_custom_fields.include?(field) | 73 assert e.available_custom_fields.include?(field) |
70 # No change to custom field, record can be saved | 74 # No change to custom field, record can be saved |
71 assert e.save | 75 assert e.save |
72 # Blanking custom field, save should fail | 76 # Blanking custom field, save should fail |
73 e.custom_field_values = {field.id => ""} | 77 e.custom_field_values = {field.id => ""} |
74 assert !e.save | 78 assert !e.save |
75 assert e.errors[:custom_values] | 79 assert_equal ["Billable can't be blank"], e.errors.full_messages |
76 | 80 |
77 # Update custom field to valid value, save should succeed | 81 # Update custom field to valid value, save should succeed |
78 e.custom_field_values = {field.id => "0"} | 82 e.custom_field_values = {field.id => "0"} |
79 assert e.save | 83 assert e.save |
80 e.reload | 84 e.reload |
81 assert_equal "0", e.custom_value_for(field).value | 85 assert_equal "0", e.custom_value_for(field).value |
82 end | 86 end |
83 | |
84 end | 87 end |
85 | 88 |