Commit 87f68e58 authored by Felix Schäfer's avatar Felix Schäfer

Recalculate last reply of thread on message deletion #968

parent 43723385
......@@ -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
......
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