2011-08-30 09:50:24 +04:00
|
|
|
# Redmine - project management software
|
2014-02-08 11:58:49 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2009-05-31 03:30:36 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-30 09:50:24 +04:00
|
|
|
#
|
2009-05-31 03:30:36 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-08-30 09:50:24 +04:00
|
|
|
#
|
2009-05-31 03:30:36 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2009-05-31 03:30:36 +04:00
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class TimeEntryActivityTest < ActiveSupport::TestCase
|
2012-11-02 02:47:25 +04:00
|
|
|
fixtures :enumerations, :time_entries, :custom_fields
|
2009-05-31 03:30:36 +04:00
|
|
|
|
2012-01-28 15:16:58 +04:00
|
|
|
include Redmine::I18n
|
|
|
|
|
2009-05-31 03:30:36 +04:00
|
|
|
def test_should_be_an_enumeration
|
|
|
|
assert TimeEntryActivity.ancestors.include?(Enumeration)
|
|
|
|
end
|
2011-04-04 15:54:22 +04:00
|
|
|
|
2009-05-31 03:30:36 +04:00
|
|
|
def test_objects_count
|
|
|
|
assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count
|
2011-04-04 15:54:22 +04:00
|
|
|
assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count
|
2009-05-31 03:30:36 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_option_name
|
|
|
|
assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
|
|
|
|
end
|
2009-10-22 02:34:22 +04:00
|
|
|
|
|
|
|
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
|
2012-01-28 15:16:58 +04:00
|
|
|
set_language_if_valid 'en'
|
2009-10-22 02:34:22 +04:00
|
|
|
field = TimeEntryActivityCustomField.find_by_name('Billable')
|
|
|
|
field.update_attribute(:is_required, true)
|
|
|
|
|
|
|
|
e = TimeEntryActivity.new(:name => 'Custom Data')
|
|
|
|
assert !e.save
|
2012-03-05 14:49:05 +04:00
|
|
|
assert_equal ["Billable can't be blank"], e.errors.full_messages
|
2009-10-22 02:34:22 +04:00
|
|
|
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
|
|
|
|
|
2012-01-28 15:16:58 +04:00
|
|
|
def test_update_with_required_custom_field_change
|
|
|
|
set_language_if_valid 'en'
|
2009-10-22 02:34:22 +04:00
|
|
|
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
|
2012-03-05 14:49:05 +04:00
|
|
|
assert_equal ["Billable can't be blank"], e.errors.full_messages
|
2011-08-30 09:50:24 +04:00
|
|
|
|
2009-10-22 02:34:22 +04:00
|
|
|
# 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
|
2009-05-31 03:30:36 +04:00
|
|
|
|
2013-05-01 21:10:15 +04:00
|
|
|
def test_system_activity_with_child_in_use_should_be_in_use
|
|
|
|
project = Project.generate!
|
|
|
|
system_activity = TimeEntryActivity.create!(:name => 'Activity')
|
|
|
|
project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
|
|
|
|
|
|
|
|
TimeEntry.generate!(:project => project, :activity => project_activity)
|
|
|
|
|
|
|
|
assert project_activity.in_use?
|
|
|
|
assert system_activity.in_use?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_destroying_a_system_activity_should_reassign_children_activities
|
|
|
|
project = Project.generate!
|
|
|
|
system_activity = TimeEntryActivity.create!(:name => 'Activity')
|
|
|
|
project_activity = TimeEntryActivity.create!(:name => 'Activity', :project => project, :parent_id => system_activity.id)
|
|
|
|
|
|
|
|
entries = [
|
|
|
|
TimeEntry.generate!(:project => project, :activity => system_activity),
|
|
|
|
TimeEntry.generate!(:project => project, :activity => project_activity)
|
|
|
|
]
|
|
|
|
|
|
|
|
assert_difference 'TimeEntryActivity.count', -2 do
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert system_activity.destroy(TimeEntryActivity.find_by_name('Development'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert entries.all? {|entry| entry.reload.activity.name == 'Development'}
|
|
|
|
end
|
|
|
|
end
|