mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-08 15:50:08 +09:00
Rewrite the search entry when the attachment is replaced too
An attachment message is indexed by its file name, and the update action still accepts a new attachment. Active Storage clears attachment_changes in its own after_commit, which runs before this one, so the replacement is noted in before_update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0142qgjggdJ2KDdGk7RF9Xm9
This commit is contained in:
@@ -37,6 +37,14 @@ class Message::SearchableTest < ActiveSupport::TestCase
|
||||
assert_equal [], rooms(:designers).messages.search("sharks")
|
||||
end
|
||||
|
||||
test "a new attachment replaces the old file name in the index" do
|
||||
message = rooms(:designers).messages.create! attachment: fixture_file_upload("moon.jpg", "image/jpeg"), client_message_id: "moon", creator: users(:david)
|
||||
|
||||
Message.find(message.id).update! attachment: fixture_file_upload("pixel.bmp", "image/bmp")
|
||||
assert_equal [ message ], rooms(:designers).messages.search("pixel")
|
||||
assert_equal [], rooms(:designers).messages.search("moon")
|
||||
end
|
||||
|
||||
test "search results are returned in message order" do
|
||||
messages = [ "first cat", "second cat", "third cat", "cat cat cat" ].map do |body|
|
||||
rooms(:designers).messages.create! body: body, client_message_id: body, creator: users(:david)
|
||||
|
||||
Reference in New Issue
Block a user