mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
FIX: do not use return in block (#26260)
We were incorrectly using `return` in a block which was causing exceptions at runtime. These exceptions were not causing much issues as they are in defer block. While working on writing a test for this specific case, I noticed that our `upsert_custom_fields` function was using rails `update_all` which is not updating the `updated_at` timestamp. This commit also fixes it and adds a test for it.
This commit is contained in:
@ -174,7 +174,7 @@ module Chat
|
||||
|
||||
def update_user_last_channel(guardian:, channel:)
|
||||
Scheduler::Defer.later "Chat::ListChannelMessages - defer update_user_last_channel" do
|
||||
return if guardian.user.custom_fields[::Chat::LAST_CHAT_CHANNEL_ID] == channel.id
|
||||
next if guardian.user.custom_fields[::Chat::LAST_CHAT_CHANNEL_ID] == channel.id
|
||||
guardian.user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel.id)
|
||||
end
|
||||
end
|
||||
|
@ -218,5 +218,12 @@ RSpec.describe Chat::ListChannelMessages do
|
||||
channel.id,
|
||||
)
|
||||
end
|
||||
|
||||
it "doesn’t update the custom field when it was already set to this value" do
|
||||
user.upsert_custom_fields(::Chat::LAST_CHAT_CHANNEL_ID => channel.id)
|
||||
field = UserCustomField.find_by(name: Chat::LAST_CHAT_CHANNEL_ID, user_id: user.id)
|
||||
|
||||
expect { result }.to_not change { field.reload.updated_at }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user