Fixed that deleting the last reply of a topic does not update last_reply_id.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9939 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
851fbaf750
commit
efc6abea07
|
@ -41,9 +41,9 @@ class Message < ActiveRecord::Base
|
||||||
validates_length_of :subject, :maximum => 255
|
validates_length_of :subject, :maximum => 255
|
||||||
validate :cannot_reply_to_locked_topic, :on => :create
|
validate :cannot_reply_to_locked_topic, :on => :create
|
||||||
|
|
||||||
after_create :add_author_as_watcher, :update_parent_last_reply
|
after_create :add_author_as_watcher, :reset_counters!
|
||||||
after_update :update_messages_board
|
after_update :update_messages_board
|
||||||
after_destroy :reset_board_counters
|
after_destroy :reset_counters!
|
||||||
|
|
||||||
scope :visible, lambda {|*args| { :include => {:board => :project},
|
scope :visible, lambda {|*args| { :include => {:board => :project},
|
||||||
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
|
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
|
||||||
|
@ -63,13 +63,6 @@ class Message < ActiveRecord::Base
|
||||||
errors.add :base, 'Topic is locked' if root.locked? && self != root
|
errors.add :base, 'Topic is locked' if root.locked? && self != root
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_parent_last_reply
|
|
||||||
if parent
|
|
||||||
parent.reload.update_attribute(:last_reply_id, self.id)
|
|
||||||
end
|
|
||||||
board.reset_counters!
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_messages_board
|
def update_messages_board
|
||||||
if board_id_changed?
|
if board_id_changed?
|
||||||
Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
|
Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
|
||||||
|
@ -78,7 +71,10 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_board_counters
|
def reset_counters!
|
||||||
|
if parent && parent.id
|
||||||
|
Message.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
|
||||||
|
end
|
||||||
board.reset_counters!
|
board.reset_counters!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,21 @@ class MessageTest < ActiveSupport::TestCase
|
||||||
assert_equal messages_count - 1, board.messages_count
|
assert_equal messages_count - 1, board.messages_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destroying_last_reply_should_update_topic_last_reply_id
|
||||||
|
topic = Message.find(4)
|
||||||
|
assert_equal 6, topic.last_reply_id
|
||||||
|
|
||||||
|
assert_difference 'Message.count', -1 do
|
||||||
|
Message.find(6).destroy
|
||||||
|
end
|
||||||
|
assert_equal 5, topic.reload.last_reply_id
|
||||||
|
|
||||||
|
assert_difference 'Message.count', -1 do
|
||||||
|
Message.find(5).destroy
|
||||||
|
end
|
||||||
|
assert_nil topic.reload.last_reply_id
|
||||||
|
end
|
||||||
|
|
||||||
def test_editable_by
|
def test_editable_by
|
||||||
message = Message.find(6)
|
message = Message.find(6)
|
||||||
author = message.author
|
author = message.author
|
||||||
|
|
Loading…
Reference in New Issue