summaryrefslogtreecommitdiffstats
path: root/test/unit/time_entry_activity_test.rb
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-10-21 22:34:22 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-10-21 22:34:22 +0000
commitac4937a76755de2f9b6a83f6160efa0fde2d03aa (patch)
tree611bf32cf6c377b65e3362583f4846e1f6a69210 /test/unit/time_entry_activity_test.rb
parent29ab7b4108cb45bc4efb44253419fa2e658ac3e9 (diff)
downloadredmine-ac4937a76755de2f9b6a83f6160efa0fde2d03aa.tar.gz
redmine-ac4937a76755de2f9b6a83f6160efa0fde2d03aa.zip
Enumerations can now have custom fields defined on them. #4077
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2945 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/time_entry_activity_test.rb')
-rw-r--r--test/unit/time_entry_activity_test.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb
index 9422a91ab..16077c0c9 100644
--- a/test/unit/time_entry_activity_test.rb
+++ b/test/unit/time_entry_activity_test.rb
@@ -32,5 +32,54 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
def test_option_name
assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
end
+
+ def test_create_with_custom_field
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ e.custom_field_values = {field.id => "1"}
+ assert e.save
+
+ e.reload
+ assert_equal "1", e.custom_value_for(field).value
+ end
+
+ def test_create_without_required_custom_field_should_fail
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ assert !e.save
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
+ end
+
+ def test_create_with_required_custom_field_should_succeed
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ e.custom_field_values = {field.id => "1"}
+ assert e.save
+ end
+
+ def test_update_issue_with_required_custom_field_change
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.find(10)
+ assert e.available_custom_fields.include?(field)
+ # No change to custom field, record can be saved
+ assert e.save
+ # Blanking custom field, save should fail
+ e.custom_field_values = {field.id => ""}
+ assert !e.save
+ assert e.errors.on(:custom_values)
+
+ # Update custom field to valid value, save should succeed
+ e.custom_field_values = {field.id => "0"}
+ assert e.save
+ e.reload
+ assert_equal "0", e.custom_value_for(field).value
+ end
+
end