FIX: Don't fail when exporting chat messages from deleted channels (#23131)
This commit is contained in:
parent
a2f5b1b101
commit
052462a8f8
|
@ -37,6 +37,7 @@ module Chat
|
||||||
private
|
private
|
||||||
|
|
||||||
def export(from, to)
|
def export(from, to)
|
||||||
|
Chat::Channel.unscoped do
|
||||||
Chat::Message
|
Chat::Message
|
||||||
.unscoped
|
.unscoped
|
||||||
.where(created_at: from..to)
|
.where(created_at: from..to)
|
||||||
|
@ -65,3 +66,4 @@ module Chat
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Chat::MessagesExporter do
|
describe Chat::MessagesExporter do
|
||||||
|
context "with different kinds of channels" do
|
||||||
fab!(:public_channel) { Fabricate(:chat_channel) }
|
fab!(:public_channel) { Fabricate(:chat_channel) }
|
||||||
fab!(:public_channel_message_1) { Fabricate(:chat_message, chat_channel: public_channel) }
|
fab!(:public_channel_message_1) { Fabricate(:chat_message, chat_channel: public_channel) }
|
||||||
fab!(:public_channel_message_2) { Fabricate(:chat_message, chat_channel: public_channel) }
|
fab!(:public_channel_message_2) { Fabricate(:chat_message, chat_channel: public_channel) }
|
||||||
|
@ -14,8 +15,12 @@ describe Chat::MessagesExporter do
|
||||||
fab!(:user_1) { Fabricate(:user) }
|
fab!(:user_1) { Fabricate(:user) }
|
||||||
fab!(:user_2) { Fabricate(:user) }
|
fab!(:user_2) { Fabricate(:user) }
|
||||||
fab!(:dm_channel) { Fabricate(:direct_message_channel, users: [user_1, user_2]) }
|
fab!(:dm_channel) { Fabricate(:direct_message_channel, users: [user_1, user_2]) }
|
||||||
fab!(:direct_message_1) { Fabricate(:chat_message, chat_channel: private_channel, user: user_1) }
|
fab!(:direct_message_1) do
|
||||||
fab!(:direct_message_2) { Fabricate(:chat_message, chat_channel: private_channel, user: user_2) }
|
Fabricate(:chat_message, chat_channel: private_channel, user: user_1)
|
||||||
|
end
|
||||||
|
fab!(:direct_message_2) do
|
||||||
|
Fabricate(:chat_message, chat_channel: private_channel, user: user_2)
|
||||||
|
end
|
||||||
|
|
||||||
before { deleted_message.trash! }
|
before { deleted_message.trash! }
|
||||||
|
|
||||||
|
@ -34,8 +39,25 @@ describe Chat::MessagesExporter do
|
||||||
assert_exported_message(result[5], direct_message_1)
|
assert_exported_message(result[5], direct_message_1)
|
||||||
assert_exported_message(result[6], direct_message_2)
|
assert_exported_message(result[6], direct_message_2)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with messages from deleted channels" do
|
||||||
|
fab!(:channel) { Fabricate(:chat_channel, deleted_at: Time.now) }
|
||||||
|
fab!(:message) { Fabricate(:chat_message, chat_channel: channel) }
|
||||||
|
|
||||||
|
it "exports such messages" do
|
||||||
|
exporter = Class.new.extend(Chat::MessagesExporter)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
exporter.chat_message_export { |data_row| result << data_row }
|
||||||
|
|
||||||
|
expect(result.length).to be(1)
|
||||||
|
assert_exported_message(result[0], message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assert_exported_message(data_row, message)
|
def assert_exported_message(data_row, message)
|
||||||
|
Chat::Channel.unscoped do
|
||||||
expect(data_row[0]).to eq(message.id)
|
expect(data_row[0]).to eq(message.id)
|
||||||
expect(data_row[1]).to eq(message.chat_channel.id)
|
expect(data_row[1]).to eq(message.chat_channel.id)
|
||||||
expect(data_row[2]).to eq(message.chat_channel.name)
|
expect(data_row[2]).to eq(message.chat_channel.name)
|
||||||
|
@ -51,3 +73,4 @@ describe Chat::MessagesExporter do
|
||||||
expect(data_row[12]).to eq(message.last_editor.username)
|
expect(data_row[12]).to eq(message.last_editor.username)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue