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
|
end
|
||||||
|
|
||||||
def after_destroy
|
def after_destroy
|
||||||
|
parent.reset_last_reply_id! if parent
|
||||||
board.reset_counters!
|
board.reset_counters!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset_last_reply_id!
|
||||||
|
clid = children.present? ? children.last.id : nil
|
||||||
|
self.update_attribute(:last_reply_id, clid)
|
||||||
|
end
|
||||||
|
|
||||||
def sticky=(arg)
|
def sticky=(arg)
|
||||||
write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
|
write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
|
||||||
end
|
end
|
||||||
|
@ -101,6 +101,18 @@ class MessageTest < ActiveSupport::TestCase
|
|||||||
# Watchers removed
|
# Watchers removed
|
||||||
end
|
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
|
def test_destroy_reply
|
||||||
message = Message.find(5)
|
message = Message.find(5)
|
||||||
board = message.board
|
board = message.board
|
||||||
|
Loading…
x
Reference in New Issue
Block a user