From: Jean-Philippe Lang Date: Fri, 9 Oct 2015 06:41:39 +0000 (+0000) Subject: Merged r14618 (#20360). X-Git-Tag: 3.1.2~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6f885a5b045042942056b04054ba0c1432ee4df8;p=redmine.git Merged r14618 (#20360). git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@14651 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index e30fc9fda..77e4560ba 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -519,11 +519,17 @@ class Project < ActiveRecord::Base # Returns a scope of all custom fields enabled for project issues # (explicitly associated custom fields and custom fields enabled for all projects) def all_issue_custom_fields - @all_issue_custom_fields ||= IssueCustomField. - sorted. - where("is_for_all = ? OR id IN (SELECT DISTINCT cfp.custom_field_id" + - " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" + - " WHERE cfp.project_id = ?)", true, id) + if new_record? + @all_issue_custom_fields ||= IssueCustomField. + sorted. + where("is_for_all = ? OR id IN (?)", true, issue_custom_field_ids) + else + @all_issue_custom_fields ||= IssueCustomField. + sorted. + where("is_for_all = ? OR id IN (SELECT DISTINCT cfp.custom_field_id" + + " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" + + " WHERE cfp.project_id = ?)", true, id) + end end def project diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index e4e74521d..b1e865e33 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -610,6 +610,20 @@ class ProjectsControllerTest < ActionController::TestCase assert_response 404 end + def test_get_copy_should_preselect_custom_fields + field1 = IssueCustomField.generate!(:is_for_all => false) + field2 = IssueCustomField.generate!(:is_for_all => false) + source = Project.generate!(:issue_custom_fields => [field1]) + @request.session[:user_id] = 1 + + get :copy, :id => source.id + assert_response :success + assert_select 'fieldset#project_issue_custom_fields' do + assert_select 'input[type=checkbox][value=?][checked=checked]', field1.id.to_s + assert_select 'input[type=checkbox][value=?]:not([checked])', field2.id.to_s + end + end + def test_post_copy_should_copy_requested_items @request.session[:user_id] = 1 # admin CustomField.delete_all