Project

General

Profile

Feature #31444 » feature-31444.patch

Mizuki ISHIKAWA, 2019-05-28 08:56

View differences:

lib/redmine/field_format.rb
field_attributes :user_role
def possible_values_options(custom_field, object=nil)
possible_values_records(custom_field, object).map {|u| [u.name, u.id.to_s]}
users = possible_values_records(custom_field, object)
options = users.map {|u| [u.name, u.id.to_s]}
options = [["<< #{l(:label_me)} >>", User.current.id]] + options if users.include?(User.current)
options
end
def possible_values_records(custom_field, object=nil)
test/functional/context_menus_controller_test.rb
assert_select "li.cf_#{field.id}" do
assert_select 'a[href="#"]', :text => 'User'
assert_select 'ul' do
assert_select 'a', Project.find(1).members.count + 1
assert_select 'a', Project.find(1).members.count + 2 # users + 'none' + 'me'
assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
end
test/functional/issues_controller_test.rb
assert_response :success
assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
assert_select 'option', Project.find(1).users.count
assert_select 'option', Project.find(1).users.count + 1 # users + 'me'
assert_select 'option[value="2"]', :text => 'John Smith'
end
assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
......
assert_response :success
assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
assert_select 'option', Project.find(1).users.count + 3 # "no change" + "none" + "me" options
end
end
test/unit/lib/redmine/field_format/user_field_format_test.rb
assert_equal ['Dave Lopper'], field.possible_values_options(project).map(&:first)
end
def test_possible_values_options_should_return_project_members_and_me_if_logged_in
User.current = User.find(2)
field = IssueCustomField.new(:field_format => 'user')
project = Project.find(1)
assert_equal ['<< me >>', 'Dave Lopper', 'John Smith'], field.possible_values_options(project).map(&:first)
end
def test_value_from_keyword_should_return_user_id
field = IssueCustomField.new(:field_format => 'user')
project = Project.find(1)
(1-1/2)