Commit 4faca3cd authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

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
parent 97140f6a
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
class Board < ActiveRecord::Base class Board < ActiveRecord::Base
belongs_to :project 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 :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 belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
acts_as_list :scope => :project_id acts_as_list :scope => :project_id
acts_as_watchable acts_as_watchable
......
...@@ -145,3 +145,15 @@ attachments_012: ...@@ -145,3 +145,15 @@ attachments_012:
filename: version_file.zip filename: version_file.zip
author_id: 2 author_id: 2
content_type: application/octet-stream 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
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'
class BoardTest < ActiveSupport::TestCase class BoardTest < ActiveSupport::TestCase
fixtures :projects, :boards, :messages fixtures :projects, :boards, :messages, :attachments, :watchers
def setup def setup
@project = Project.find(1) @project = Project.find(1)
...@@ -23,8 +23,13 @@ class BoardTest < ActiveSupport::TestCase ...@@ -23,8 +23,13 @@ class BoardTest < ActiveSupport::TestCase
def test_destroy def test_destroy
board = Board.find(1) board = Board.find(1)
assert board.destroy assert_difference 'Message.count', -6 do
# make sure that the associated messages are removed 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}) assert_equal 0, Message.count(:conditions => {:board_id => 1})
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment