]> source.dussan.org Git - redmine.git/commitdiff
Merged r14618 (#20360).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 06:43:03 +0000 (06:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 06:43:03 +0000 (06:43 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/2.6-stable@14653 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/functional/projects_controller_test.rb

index f4d458726ba9d38379cfc2a4ec6b4decf6f627a3..0494a8298e20e50e131c5f0d900d3ce11adfbcc1 100644 (file)
@@ -526,11 +526,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
 
   # Returns an array of all custom fields enabled for project time entries
index e73098f0a1131a4298fd054eb52a7d064411b916..88ba95d33cd65b0c46371b33c53e3718f650a1c0 100644 (file)
@@ -555,6 +555,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