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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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, :custom_fields,
  20. :issues, :projects, :users,
  21. :members, :roles, :member_roles,
  22. :trackers, :issue_statuses,
  23. :projects_trackers,
  24. :issue_categories,
  25. :groups_users,
  26. :enabled_modules
  27. include Redmine::I18n
  28. def test_should_be_an_enumeration
  29. assert TimeEntryActivity.ancestors.include?(Enumeration)
  30. end
  31. def test_objects_count
  32. assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
  33. assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
  34. end
  35. def test_option_name
  36. assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
  37. end
  38. def test_create_with_custom_field
  39. field = TimeEntryActivityCustomField.find_by_name('Billable')
  40. e = TimeEntryActivity.new(:name => 'Custom Data')
  41. e.custom_field_values = {field.id => "1"}
  42. assert e.save
  43. e.reload
  44. assert_equal "1", e.custom_value_for(field).value
  45. end
  46. def test_create_without_required_custom_field_should_fail
  47. set_language_if_valid 'en'
  48. field = TimeEntryActivityCustomField.find_by_name('Billable')
  49. field.update_attribute(:is_required, true)
  50. e = TimeEntryActivity.new(:name => 'Custom Data')
  51. assert !e.save
  52. assert_equal ["Billable cannot be blank"], e.errors.full_messages
  53. end
  54. def test_create_with_required_custom_field_should_succeed
  55. field = TimeEntryActivityCustomField.find_by_name('Billable')
  56. field.update_attribute(:is_required, true)
  57. e = TimeEntryActivity.new(:name => 'Custom Data')
  58. e.custom_field_values = {field.id => "1"}
  59. assert e.save
  60. end
  61. def test_update_with_required_custom_field_change
  62. set_language_if_valid 'en'
  63. field = TimeEntryActivityCustomField.find_by_name('Billable')
  64. field.update_attribute(:is_required, true)
  65. e = TimeEntryActivity.find(10)
  66. assert e.available_custom_fields.include?(field)
  67. # No change to custom field, record can be saved
  68. assert e.save
  69. # Blanking custom field, save should fail
  70. e.custom_field_values = {field.id => ""}
  71. assert !e.save
  72. assert_equal ["Billable cannot be blank"], e.errors.full_messages
  73. # Update custom field to valid value, save should succeed
  74. e.custom_field_values = {field.id => "0"}
  75. assert e.save
  76. e.reload
  77. assert_equal "0", e.custom_value_for(field).value
  78. end
  79. def test_system_activity_with_child_in_use_should_be_in_use
  80. project = Project.generate!
  81. system_activity = TimeEntryActivity.create!(:name => 'Activity')
  82. project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
  83. TimeEntry.generate!(:project => project, :activity => project_activity)
  84. assert project_activity.in_use?
  85. assert system_activity.in_use?
  86. end
  87. def test_destroying_a_system_activity_should_reassign_children_activities
  88. project = Project.generate!
  89. entries = []
  90. system_activity = TimeEntryActivity.create!(:name => 'Activity')
  91. entries << TimeEntry.generate!(:project => project, :activity => system_activity)
  92. project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
  93. entries << TimeEntry.generate!(:project => project.reload, :activity => project_activity)
  94. assert_difference 'TimeEntryActivity.count', -2 do
  95. assert_nothing_raised do
  96. assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
  97. end
  98. end
  99. assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
  100. end
  101. def test_project_activity_without_parent_should_not_disable_system_activities
  102. project = Project.find(1)
  103. activity = TimeEntryActivity.create!(:name => 'Csutom', :project => project)
  104. assert_include activity, project.activities
  105. assert_include TimeEntryActivity.find(9), project.activities
  106. end
  107. end