2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2009-03-01 11:39:01 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2008-06-17 19:10:54 +00: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-24 07:19:25 +00:00
|
|
|
#
|
2008-06-17 19:10:54 +00: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-24 07:19:25 +00:00
|
|
|
#
|
2008-06-17 19:10:54 +00: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.
|
|
|
|
|
|
2023-01-01 07:13:39 +00:00
|
|
|
require_relative '../test_helper'
|
2008-06-17 19:10:54 +00:00
|
|
|
|
2016-07-14 09:35:49 +00:00
|
|
|
class EnumerationsControllerTest < Redmine::ControllerTest
|
2008-06-17 19:10:54 +00:00
|
|
|
def setup
|
|
|
|
|
@request.session[:user_id] = 1 # admin
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_index
|
|
|
|
|
get :index
|
|
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
assert_select 'table.enumerations'
|
2008-06-17 19:10:54 +00:00
|
|
|
end
|
2011-08-24 07:19:25 +00:00
|
|
|
|
2012-10-17 17:29:27 +00:00
|
|
|
def test_index_should_require_admin
|
|
|
|
|
@request.session[:user_id] = nil
|
|
|
|
|
get :index
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2012-10-17 17:29:27 +00:00
|
|
|
end
|
|
|
|
|
|
2011-11-29 20:04:30 +00:00
|
|
|
def test_new
|
2020-11-22 12:58:23 +00:00
|
|
|
get(:new, :params => {:type => 'IssuePriority'})
|
2011-11-29 20:04:30 +00:00
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
|
2014-11-20 19:57:06 +00:00
|
|
|
assert_select 'input[name=?][value=?]', 'enumeration[type]', 'IssuePriority'
|
|
|
|
|
assert_select 'input[name=?]', 'enumeration[name]'
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
2012-02-23 14:26:30 +00:00
|
|
|
def test_new_with_invalid_type_should_respond_with_404
|
2020-11-22 12:58:23 +00:00
|
|
|
get(:new, :params => {:type => 'UnknownType'})
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :not_found
|
2012-02-23 14:26:30 +00:00
|
|
|
end
|
|
|
|
|
|
2011-11-29 20:04:30 +00:00
|
|
|
def test_create
|
|
|
|
|
assert_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'IssuePriority',
|
|
|
|
|
:name => 'Lowest'
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
2012-10-17 17:29:27 +00:00
|
|
|
assert_redirected_to '/enumerations'
|
2012-03-04 12:50:19 +00:00
|
|
|
e = IssuePriority.find_by_name('Lowest')
|
|
|
|
|
assert_not_nil e
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
2018-09-15 06:45:10 +00:00
|
|
|
def test_create_with_custom_field_values
|
2018-09-15 09:07:25 +00:00
|
|
|
custom_field = TimeEntryActivityCustomField.generate!
|
2018-09-15 06:45:10 +00:00
|
|
|
assert_difference 'TimeEntryActivity.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2018-09-15 06:45:10 +00:00
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'TimeEntryActivity',
|
|
|
|
|
:name => 'Sample',
|
|
|
|
|
:custom_field_values => {custom_field.id.to_s => "sample"}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2018-09-15 06:45:10 +00:00
|
|
|
end
|
|
|
|
|
assert_redirected_to '/enumerations'
|
|
|
|
|
assert_equal "sample", Enumeration.find_by(:name => 'Sample').custom_field_values.last.value
|
|
|
|
|
end
|
|
|
|
|
|
2020-03-20 02:31:13 +00:00
|
|
|
def test_create_with_multiple_select_list_custom_fields
|
|
|
|
|
custom_field = IssuePriorityCustomField.generate!(:field_format => 'list', :multiple => true, :possible_values => ['1', '2', '3', '4'])
|
|
|
|
|
assert_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2020-03-20 02:31:13 +00:00
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'IssuePriority',
|
|
|
|
|
:name => 'Sample',
|
|
|
|
|
:custom_field_values => {custom_field.id.to_s => ['1', '2']}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2020-03-20 02:31:13 +00:00
|
|
|
end
|
|
|
|
|
assert_redirected_to '/enumerations'
|
|
|
|
|
assert_equal ['1', '2'].sort, Enumeration.find_by(:name => 'Sample').custom_field_values.last.value.sort
|
|
|
|
|
end
|
|
|
|
|
|
2011-11-29 20:04:30 +00:00
|
|
|
def test_create_with_failure
|
|
|
|
|
assert_no_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'IssuePriority',
|
|
|
|
|
:name => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
assert_select_error /name cannot be blank/i
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_edit
|
2020-11-22 12:58:23 +00:00
|
|
|
get(:edit, :params => {:id => 6})
|
2011-11-29 20:04:30 +00:00
|
|
|
assert_response :success
|
2014-11-20 19:57:06 +00:00
|
|
|
assert_select 'input[name=?][value=?]', 'enumeration[name]', 'High'
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
2012-02-23 14:26:30 +00:00
|
|
|
def test_edit_invalid_should_respond_with_404
|
2020-11-22 12:58:23 +00:00
|
|
|
get(:edit, :params => {:id => 999})
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :not_found
|
2012-02-23 14:26:30 +00:00
|
|
|
end
|
|
|
|
|
|
2011-11-29 20:04:30 +00:00
|
|
|
def test_update
|
|
|
|
|
assert_no_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 6,
|
|
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'IssuePriority',
|
|
|
|
|
:name => 'New name'
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
2012-10-17 17:29:27 +00:00
|
|
|
assert_redirected_to '/enumerations'
|
2011-11-29 20:04:30 +00:00
|
|
|
e = IssuePriority.find(6)
|
|
|
|
|
assert_equal 'New name', e.name
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_update_with_failure
|
|
|
|
|
assert_no_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 6,
|
|
|
|
|
:enumeration => {
|
|
|
|
|
:type => 'IssuePriority',
|
|
|
|
|
:name => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
assert_select_error /name cannot be blank/i
|
2011-11-29 20:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
2017-07-30 16:31:12 +00:00
|
|
|
def test_update_position
|
|
|
|
|
assert_equal 2, Enumeration.find(2).position
|
2020-11-22 12:58:23 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
|
|
|
|
:id => 2,
|
|
|
|
|
:enumeration => {
|
|
|
|
|
:position => 1,
|
2017-07-30 16:31:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2017-07-30 16:31:12 +00:00
|
|
|
assert_equal 1, Enumeration.find(2).position
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-15 06:45:10 +00:00
|
|
|
def test_update_custom_field_values
|
2018-09-15 09:07:25 +00:00
|
|
|
custom_field = TimeEntryActivityCustomField.generate!
|
2018-09-15 06:45:10 +00:00
|
|
|
enumeration = Enumeration.find(9)
|
|
|
|
|
assert_nil enumeration.custom_field_values.last.value
|
2020-11-22 12:58:23 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
|
|
|
|
:id => enumeration.id,
|
|
|
|
|
:enumeration => {
|
|
|
|
|
:custom_field_values => {custom_field.id.to_s => "sample"}
|
2018-09-15 06:45:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-22 12:58:23 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2018-09-15 06:45:10 +00:00
|
|
|
assert_equal "sample", enumeration.reload.custom_field_values.last.value
|
|
|
|
|
end
|
|
|
|
|
|
2008-06-17 19:10:54 +00:00
|
|
|
def test_destroy_enumeration_not_in_use
|
2011-12-11 10:26:12 +00:00
|
|
|
assert_difference 'IssuePriority.count', -1 do
|
2020-11-22 12:58:23 +00:00
|
|
|
delete(:destroy, :params => {:id => 7})
|
2011-12-11 10:26:12 +00:00
|
|
|
end
|
2008-06-17 19:10:54 +00:00
|
|
|
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
|
|
|
|
assert_nil Enumeration.find_by_id(7)
|
|
|
|
|
end
|
2011-08-24 07:19:25 +00:00
|
|
|
|
2008-06-17 19:10:54 +00:00
|
|
|
def test_destroy_enumeration_in_use
|
2011-12-11 10:26:12 +00:00
|
|
|
assert_no_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
delete(:destroy, :params => {:id => 4})
|
2011-12-11 10:26:12 +00:00
|
|
|
end
|
2008-06-17 19:10:54 +00:00
|
|
|
assert_response :success
|
2016-07-18 21:26:30 +00:00
|
|
|
|
2008-06-17 19:10:54 +00:00
|
|
|
assert_not_nil Enumeration.find_by_id(4)
|
2012-05-13 08:45:15 +00:00
|
|
|
assert_select 'select[name=reassign_to_id]' do
|
2014-11-20 19:38:40 +00:00
|
|
|
assert_select 'option[value="6"]', :text => 'High'
|
2012-05-13 08:45:15 +00:00
|
|
|
end
|
2008-06-17 19:10:54 +00:00
|
|
|
end
|
2011-08-24 07:19:25 +00:00
|
|
|
|
2008-06-17 19:10:54 +00:00
|
|
|
def test_destroy_enumeration_in_use_with_reassignment
|
2012-12-03 18:21:32 +00:00
|
|
|
issue = Issue.where(:priority_id => 4).first
|
2011-12-11 10:26:12 +00:00
|
|
|
assert_difference 'IssuePriority.count', -1 do
|
2020-11-22 12:58:23 +00:00
|
|
|
delete(:destroy, :params => {:id => 4, :reassign_to_id => 6})
|
2011-12-11 10:26:12 +00:00
|
|
|
end
|
2008-06-17 19:10:54 +00:00
|
|
|
assert_redirected_to :controller => 'enumerations', :action => 'index'
|
|
|
|
|
assert_nil Enumeration.find_by_id(4)
|
|
|
|
|
# check that the issue was reassign
|
|
|
|
|
assert_equal 6, issue.reload.priority_id
|
|
|
|
|
end
|
2013-05-17 18:18:06 +00:00
|
|
|
|
|
|
|
|
def test_destroy_enumeration_in_use_with_blank_reassignment
|
|
|
|
|
assert_no_difference 'IssuePriority.count' do
|
2020-11-22 12:58:23 +00:00
|
|
|
delete(:destroy, :params => {:id => 4, :reassign_to_id => ''})
|
2013-05-17 18:18:06 +00:00
|
|
|
end
|
|
|
|
|
assert_response :success
|
|
|
|
|
end
|
2008-06-17 19:10:54 +00:00
|
|
|
end
|