From d0ea5fae62b16c50ac86445368be0cc7b87e295a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 7 Apr 2011 16:34:58 +0000 Subject: [PATCH] Fixed: empty list for user/version custom fields on bulk edit form (#2096). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5354 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/custom_fields_helper.rb | 4 +-- app/models/custom_field.rb | 2 ++ app/views/issues/bulk_edit.rhtml | 2 +- app/views/timelog/bulk_edit.rhtml | 2 +- test/functional/issues_controller_test.rb | 34 +++++++++++++++++++++- test/unit/custom_field_user_format_test.rb | 7 +++++ 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 36f665e18..0f7a5a135 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -68,7 +68,7 @@ module CustomFieldsHelper custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) end - def custom_field_tag_for_bulk_edit(name, custom_field) + def custom_field_tag_for_bulk_edit(name, custom_field, projects) field_name = "#{name}[custom_field_values][#{custom_field.id}]" field_id = "#{name}_custom_field_values_#{custom_field.id}" field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) @@ -83,7 +83,7 @@ module CustomFieldsHelper [l(:general_text_yes), '1'], [l(:general_text_no), '0']]), :id => field_id) when "list" - select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options), :id => field_id) + select_tag(field_name, options_for_select([[l(:label_no_change_option), '']] + custom_field.possible_values_options(projects)), :id => field_id) else text_field_tag(field_name, '', :id => field_id) end diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index a09674df0..0e8151ee0 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -58,6 +58,8 @@ class CustomField < ActiveRecord::Base when 'version' obj.project.versions.sort.collect {|u| [u.to_s, u.id.to_s]} end + elsif obj.is_a?(Array) + obj.collect {|o| possible_values_options(o)}.inject {|memo, v| memo & v} else [] end diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml index 35ee17307..71b30ddac 100644 --- a/app/views/issues/bulk_edit.rhtml +++ b/app/views/issues/bulk_edit.rhtml @@ -48,7 +48,7 @@ <% end %> <% @custom_fields.each do |custom_field| %> -

<%= custom_field_tag_for_bulk_edit('issue', custom_field) %>

+

<%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %>

<% end %> <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> diff --git a/app/views/timelog/bulk_edit.rhtml b/app/views/timelog/bulk_edit.rhtml index 3045e2569..a93e39238 100644 --- a/app/views/timelog/bulk_edit.rhtml +++ b/app/views/timelog/bulk_edit.rhtml @@ -36,7 +36,7 @@

<% @custom_fields.each do |custom_field| %> -

<%= custom_field_tag_for_bulk_edit('time_entry', custom_field) %>

+

<%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %>

<% end %> <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 4c6e33266..31132eba0 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2008 Jean-Philippe Lang +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -1123,6 +1123,38 @@ class IssuesControllerTest < ActionController::TestCase assert !field.project_ids.include?(Issue.find(6).project_id) assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} end + + def test_get_bulk_edit_with_user_custom_field + field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) + + @request.session[:user_id] = 2 + get :bulk_edit, :ids => [1, 2] + assert_response :success + assert_template 'bulk_edit' + + assert_tag :select, + :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, + :children => { + :only => {:tag => 'option'}, + :count => Project.find(1).users.count + 1 + } + end + + def test_get_bulk_edit_with_version_custom_field + field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) + + @request.session[:user_id] = 2 + get :bulk_edit, :ids => [1, 2] + assert_response :success + assert_template 'bulk_edit' + + assert_tag :select, + :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, + :children => { + :only => {:tag => 'option'}, + :count => Project.find(1).versions.count + 1 + } + end def test_bulk_update @request.session[:user_id] = 2 diff --git a/test/unit/custom_field_user_format_test.rb b/test/unit/custom_field_user_format_test.rb index 5cc4ea5c1..8cac3009f 100644 --- a/test/unit/custom_field_user_format_test.rb +++ b/test/unit/custom_field_user_format_test.rb @@ -53,6 +53,13 @@ class CustomFieldUserFormatTest < ActiveSupport::TestCase assert_equal project.users.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options end + def test_possible_values_options_with_array + projects = Project.find([1, 2]) + possible_values_options = @field.possible_values_options(projects) + assert possible_values_options.any? + assert_equal (projects.first.users & projects.last.users).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options + end + def test_cast_blank_value assert_equal nil, @field.cast_value(nil) assert_equal nil, @field.cast_value("")