]> source.dussan.org Git - redmine.git/commitdiff
Fixed that query roles are not copied when copying a project (#17202).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 14 Jul 2014 16:20:44 +0000 (16:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 14 Jul 2014 16:20:44 +0000 (16:20 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13329 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/object_helpers.rb
test/unit/project_copy_test.rb

index 6ced34565c722a28291b10921072b329728c95d4..a146a344a59414666e8dc8295a862676ec60ca55 100644 (file)
@@ -952,6 +952,7 @@ class Project < ActiveRecord::Base
       new_query.sort_criteria = query.sort_criteria if query.sort_criteria
       new_query.project = self
       new_query.user_id = query.user_id
+      new_query.role_ids = query.role_ids if query.visibility == IssueQuery::VISIBILITY_ROLES
       self.queries << new_query
     end
   end
index 1f58baf9e415d2f03985cae6efaa0756bef184b5..4e4a9fba32cc6dcbe324d03c39411932ee8f16e7 100644 (file)
@@ -178,6 +178,14 @@ module ObjectHelpers
     changeset.save!
     changeset
   end
+
+  def Query.generate!(attributes={})
+    query = new(attributes)
+    query.name = "Generated query" if query.name.blank?
+    query.user ||= User.find(1)
+    query.save!
+    query
+  end
 end
 
 module IssueObjectHelpers
index 238417a2d01bd030789b1db749fdbcf409be6537..2f1f6ee59974407b280a452a2de8cf4cc44f71a1 100644 (file)
@@ -222,6 +222,17 @@ class ProjectCopyTest < ActiveSupport::TestCase
     assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort
   end
 
+  def test_copy_should_copy_queries_roles_visibility
+    source = Project.generate!
+    target = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
+    IssueQuery.generate!(:project => source, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3]).to_a)
+
+    assert target.copy(source)
+    assert_equal 1, target.queries.size
+    query = target.queries.first
+    assert_equal [1, 3], query.role_ids.sort
+  end
+
   test "#copy should copy versions" do
     @source_project.versions << Version.generate!
     @source_project.versions << Version.generate!