Project

General

Profile

Patch #18419 » copy_news_with_project.patch

Ivan Kasatenko, 2014-11-22 21:30

View differences:

app/models/project.rb
743 743
  def copy(project, options={})
744 744
    project = project.is_a?(Project) ? project : Project.find(project)
745 745

  
746
    to_be_copied = %w(wiki versions issue_categories issues members queries boards)
746
    to_be_copied = %w(wiki versions issue_categories issues members queries boards news)
747 747
    to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil?
748 748

  
749 749
    Project.transaction do
......
994 994
    end
995 995
  end
996 996

  
997
  # Copies news from +project+
998
  def copy_news(project)
999
    project.news.each do |news|
1000
      new_news = News.new
1001
      new_news.attributes = news.attributes.dup.except("id", "project_id", "created_on", "updated_on")
1002
      self.news << new_news
1003
    end
1004
  end
1005

  
997 1006
  def allowed_permissions
998 1007
    @allowed_permissions ||= begin
999 1008
      module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name)
app/views/projects/copy.html.erb
11 11
  <label class="block"><%= check_box_tag 'only[]', 'queries', true %> <%= l(:label_query_plural) %> (<%= @source_project.queries.count %>)</label>
12 12
  <label class="block"><%= check_box_tag 'only[]', 'boards', true %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label>
13 13
  <label class="block"><%= check_box_tag 'only[]', 'wiki', true %> <%= l(:label_wiki_page_plural) %> (<%= @source_project.wiki.nil? ? 0 : @source_project.wiki.pages.count %>)</label>
14
  <label class="block"><%= check_box_tag 'only[]', 'news', true %> <%= l(:label_news_plural) %> (<%= @source_project.news.nil? ? 0 : @source_project.news.count %>)</label>
14 15
  <%= hidden_field_tag 'only[]', '' %>
15 16
  <br />
16 17
  <label class="block"><%= check_box_tag 'notifications', 1, params[:notifications] %> <%= l(:label_project_copy_notifications) %></label>
test/unit/project_copy_test.rb
304 304
    end
305 305
  end
306 306

  
307
  test "#copy should copy news" do
308
    assert @project.copy(@source_project)
309

  
310
    assert_equal 1, @project.news.size
311
    @project.news.each do |news|
312
      assert !@source_project.news.include?(news)
313
    end
314
  end
315

  
307 316
  test "#copy should change the new issues to use the copied issue categories" do
308 317
    issue = Issue.find(4)
309 318
    issue.update_attribute(:category_id, 3)
(1-1/2)