diff --git a/app/models/project.rb b/app/models/project.rb index 1a35342..b081783 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -743,7 +743,7 @@ class Project < ActiveRecord::Base def copy(project, options={}) project = project.is_a?(Project) ? project : Project.find(project) - to_be_copied = %w(wiki versions issue_categories issues members queries boards) + to_be_copied = %w(wiki versions issue_categories issues members queries boards news) to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? Project.transaction do @@ -994,6 +994,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 26ec2e5..a2052f1 100644 --- a/app/views/projects/copy.html.erb +++ b/app/views/projects/copy.html.erb @@ -11,6 +11,7 @@ + <%= hidden_field_tag 'only[]', '' %>
diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index 2f1f6ee..20e5d76 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -304,6 +304,15 @@ class ProjectCopyTest < ActiveSupport::TestCase end 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)