diff --git a/app/models/project.rb b/app/models/project.rb index 526d479f3..db509b0ac 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -841,7 +841,7 @@ class Project < ActiveRecord::Base def copy(project, options={}) project = project.is_a?(Project) ? project : Project.find(project) - to_be_copied = %w(members wiki versions issue_categories issues queries boards documents) + to_be_copied = %w(members wiki versions issue_categories issues queries boards documents news) to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? Project.transaction do @@ -1161,6 +1161,15 @@ class Project < ActiveRecord::Base end end + # Copies news from +project+ + def copy_news(project) + project.news.each do |news| + new_news = News.new + new_news.attributes = news.attributes.dup.except("id", "project_id", "created_on", "updated_on") + self.news << new_news + end + end + def allowed_permissions @allowed_permissions ||= begin module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name) diff --git a/app/views/projects/copy.html.erb b/app/views/projects/copy.html.erb index 8a7805ef0..bd0916b7a 100644 --- a/app/views/projects/copy.html.erb +++ b/app/views/projects/copy.html.erb @@ -12,6 +12,7 @@ + <%= call_hook :view_projects_copy_only_items, project: @source_project, f: f %> <%= hidden_field_tag 'only[]', '' %>
diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index d18b99df6..ae53f7818 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -393,6 +393,15 @@ class ProjectCopyTest < ActiveSupport::TestCase assert_equal "testfile.txt", copied_document.attachments.first.filename end + test "#copy should copy news" do + assert @project.copy(@source_project) + + assert_equal 1, @project.news.size + @project.news.each do |news| + assert !@source_project.news.include?(news) + end + end + test "#copy should change the new issues to use the copied issue categories" do issue = Issue.find(4) issue.update_attribute(:category_id, 3)