From 6fedbf60d5a9bb2747b1e250ffc9f5f4947676f6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 25 Oct 2009 11:23:46 +0000 Subject: [PATCH] Allow project forums copy. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2976 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 12 +++++++++++- app/views/projects/copy.rhtml | 1 + test/fixtures/boards.yml | 9 +++++++++ test/unit/project_test.rb | 9 +++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 7b9080833..00aa5df6c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -408,7 +408,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) + to_be_copied = %w(wiki versions issue_categories issues members queries boards) to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil? Project.transaction do @@ -521,6 +521,16 @@ class Project < ActiveRecord::Base self.queries << new_query end end + + # Copies boards from +project+ + def copy_boards(project) + project.boards.each do |board| + new_board = Board.new + new_board.attributes = board.attributes.dup.except("id", "project_id", "topics_count", "messages_count", "last_message_id") + new_board.project = self + self.boards << new_board + end + end def allowed_permissions @allowed_permissions ||= begin diff --git a/app/views/projects/copy.rhtml b/app/views/projects/copy.rhtml index f88817c1f..49e262786 100644 --- a/app/views/projects/copy.rhtml +++ b/app/views/projects/copy.rhtml @@ -18,6 +18,7 @@ + <%= hidden_field_tag 'only[]', '' %> diff --git a/test/fixtures/boards.yml b/test/fixtures/boards.yml index 0d6135875..cce3fdccc 100644 --- a/test/fixtures/boards.yml +++ b/test/fixtures/boards.yml @@ -17,3 +17,12 @@ boards_002: position: 2 last_message_id: messages_count: 0 +boards_003: + name: Discussion + project_id: 2 + topics_count: 0 + id: 3 + description: Discussion board + position: 1 + last_message_id: + messages_count: 0 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index a08b5f856..082a850b8 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -488,6 +488,15 @@ class ProjectTest < ActiveSupport::TestCase end end + should "copy boards" do + assert @project.copy(@source_project) + + assert_equal 1, @project.boards.size + @project.boards.each do |board| + assert !@source_project.boards.include?(board) + end + end + should "change the new issues to use the copied issue categories" do issue = Issue.find(4) issue.update_attribute(:category_id, 3) -- 2.39.5