Recalculate last reply of thread on message deletion #968
This commit is contained in:
parent
43723385c6
commit
87f68e58ad
|
@ -80,9 +80,15 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def after_destroy
|
||||
parent.reset_last_reply_id! if parent
|
||||
board.reset_counters!
|
||||
end
|
||||
|
||||
def reset_last_reply_id!
|
||||
clid = children.present? ? children.last.id : nil
|
||||
self.update_attribute(:last_reply_id, clid)
|
||||
end
|
||||
|
||||
def sticky=(arg)
|
||||
write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
|
||||
end
|
||||
|
|
|
@ -101,6 +101,18 @@ class MessageTest < ActiveSupport::TestCase
|
|||
# Watchers removed
|
||||
end
|
||||
|
||||
def test_destroy_last_reply
|
||||
message = Message.find(4)
|
||||
last_reply = message.last_reply
|
||||
penultimate_reply = message.children[-2]
|
||||
|
||||
assert last_reply.destroy
|
||||
|
||||
message.reload
|
||||
|
||||
assert_equal penultimate_reply, message.last_reply
|
||||
end
|
||||
|
||||
def test_destroy_reply
|
||||
message = Message.find(5)
|
||||
board = message.board
|
||||
|
|
Loading…
Reference in New Issue