You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time_entry_activity_test.rb 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class TimeEntryActivityTest < ActiveSupport::TestCase
  19. fixtures :enumerations, :time_entries
  20. include Redmine::I18n
  21. def test_should_be_an_enumeration
  22. assert TimeEntryActivity.ancestors.include?(Enumeration)
  23. end
  24. def test_objects_count
  25. assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
  26. assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
  27. end
  28. def test_option_name
  29. assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
  30. end
  31. def test_create_with_custom_field
  32. field = TimeEntryActivityCustomField.find_by_name('Billable')
  33. e = TimeEntryActivity.new(:name => 'Custom Data')
  34. e.custom_field_values = {field.id => "1"}
  35. assert e.save
  36. e.reload
  37. assert_equal "1", e.custom_value_for(field).value
  38. end
  39. def test_create_without_required_custom_field_should_fail
  40. set_language_if_valid 'en'
  41. field = TimeEntryActivityCustomField.find_by_name('Billable')
  42. field.update_attribute(:is_required, true)
  43. e = TimeEntryActivity.new(:name => 'Custom Data')
  44. assert !e.save
  45. assert_equal ["Billable can't be blank"], e.errors.full_messages
  46. end
  47. def test_create_with_required_custom_field_should_succeed
  48. field = TimeEntryActivityCustomField.find_by_name('Billable')
  49. field.update_attribute(:is_required, true)
  50. e = TimeEntryActivity.new(:name => 'Custom Data')
  51. e.custom_field_values = {field.id => "1"}
  52. assert e.save
  53. end
  54. def test_update_with_required_custom_field_change
  55. set_language_if_valid 'en'
  56. field = TimeEntryActivityCustomField.find_by_name('Billable')
  57. field.update_attribute(:is_required, true)
  58. e = TimeEntryActivity.find(10)
  59. assert e.available_custom_fields.include?(field)
  60. # No change to custom field, record can be saved
  61. assert e.save
  62. # Blanking custom field, save should fail
  63. e.custom_field_values = {field.id => ""}
  64. assert !e.save
  65. assert_equal ["Billable can't be blank"], e.errors.full_messages
  66. # Update custom field to valid value, save should succeed
  67. e.custom_field_values = {field.id => "0"}
  68. assert e.save
  69. e.reload
  70. assert_equal "0", e.custom_value_for(field).value
  71. end
  72. end