FIX: Serialize channel title for DMs (#90)
This commit is contained in:
parent
68bc80e19d
commit
9e901dbfbf
|
@ -1,5 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AiChatChannelSerializer < ApplicationSerializer
|
||||
attributes :id, :chatable, :chatable_type, :chatable_url, :title, :slug
|
||||
attributes :id, :chatable, :chatable_type, :chatable_url, :slug
|
||||
|
||||
def title
|
||||
# Display all participants for a DM.
|
||||
# For category channels, the argument is ignored.
|
||||
object.title(nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe AiChatChannelSerializer do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
describe "#title" do
|
||||
context "when the channel is a DM" do
|
||||
fab!(:dm_channel) { Fabricate(:direct_message_channel) }
|
||||
|
||||
it "display every participant" do
|
||||
serialized = described_class.new(dm_channel, scope: Guardian.new(admin), root: nil)
|
||||
|
||||
expect(serialized.title).to eq(dm_channel.title(nil))
|
||||
end
|
||||
end
|
||||
|
||||
context "when the channel is a regular one" do
|
||||
fab!(:channel) { Fabricate(:chat_channel) }
|
||||
|
||||
it "displays the category title" do
|
||||
serialized = described_class.new(channel, scope: Guardian.new(admin), root: nil)
|
||||
|
||||
expect(serialized.title).to eq(channel.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue