Skip to content

Commit 4faca3c

Browse files
committed
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
1 parent 97140f6 commit 4faca3c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

app/models/board.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class Board < ActiveRecord::Base
1919
belongs_to :project
2020
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
21-
has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC"
21+
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
2222
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
2323
acts_as_list :scope => :project_id
2424
acts_as_watchable

test/fixtures/attachments.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,15 @@ attachments_012:
145145
filename: version_file.zip
146146
author_id: 2
147147
content_type: application/octet-stream
148+
attachments_013:
149+
created_on: 2006-07-19 21:07:27 +02:00
150+
container_type: Message
151+
container_id: 1
152+
downloads: 0
153+
disk_filename: 060719210727_foo.zip
154+
digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
155+
id: 13
156+
filesize: 452
157+
filename: foo.zip
158+
author_id: 2
159+
content_type: application/octet-stream

test/unit/board_test.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require File.dirname(__FILE__) + '/../test_helper'
22

33
class BoardTest < ActiveSupport::TestCase
4-
fixtures :projects, :boards, :messages
4+
fixtures :projects, :boards, :messages, :attachments, :watchers
55

66
def setup
77
@project = Project.find(1)
@@ -23,8 +23,13 @@ def test_create
2323

2424
def test_destroy
2525
board = Board.find(1)
26-
assert board.destroy
27-
# make sure that the associated messages are removed
26+
assert_difference 'Message.count', -6 do
27+
assert_difference 'Attachment.count', -1 do
28+
assert_difference 'Watcher.count', -1 do
29+
assert board.destroy
30+
end
31+
end
32+
end
2833
assert_equal 0, Message.count(:conditions => {:board_id => 1})
2934
end
3035
end

0 commit comments

Comments
 (0)