From: Jean-Philippe Lang Date: Sat, 27 Nov 2010 12:42:11 +0000 (+0000) Subject: Fixed: messages attachments/watchers are not deleted when deleting a project or forum... X-Git-Tag: 1.1.0~153 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4faca3cd4a7d8c7d39c7e73784ccaae076471e7b;p=redmine.git Fixed: messages attachments/watchers are not deleted when deleting a project or forum (#6966). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4431 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/board.rb b/app/models/board.rb index e7310da65..de0e444b9 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -18,7 +18,7 @@ class Board < ActiveRecord::Base belongs_to :project has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC" - has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC" + has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC" belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id acts_as_list :scope => :project_id acts_as_watchable diff --git a/test/fixtures/attachments.yml b/test/fixtures/attachments.yml index 002bb0913..487ce5aa9 100644 --- a/test/fixtures/attachments.yml +++ b/test/fixtures/attachments.yml @@ -145,3 +145,15 @@ attachments_012: filename: version_file.zip author_id: 2 content_type: application/octet-stream +attachments_013: + created_on: 2006-07-19 21:07:27 +02:00 + container_type: Message + container_id: 1 + downloads: 0 + disk_filename: 060719210727_foo.zip + digest: b91e08d0cf966d5c6ff411bd8c4cc3a2 + id: 13 + filesize: 452 + filename: foo.zip + author_id: 2 + content_type: application/octet-stream diff --git a/test/unit/board_test.rb b/test/unit/board_test.rb index 569c4620a..d3073ec82 100644 --- a/test/unit/board_test.rb +++ b/test/unit/board_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class BoardTest < ActiveSupport::TestCase - fixtures :projects, :boards, :messages + fixtures :projects, :boards, :messages, :attachments, :watchers def setup @project = Project.find(1) @@ -23,8 +23,13 @@ class BoardTest < ActiveSupport::TestCase def test_destroy board = Board.find(1) - assert board.destroy - # make sure that the associated messages are removed + assert_difference 'Message.count', -6 do + assert_difference 'Attachment.count', -1 do + assert_difference 'Watcher.count', -1 do + assert board.destroy + end + end + end assert_equal 0, Message.count(:conditions => {:board_id => 1}) end end