discourse/plugins/chat/spec/models/direct_message_channel_spec.rb
Martin Brennan c6764d8c74
FIX: Automatically generate category channel slugs (#18879)
This commit automatically ensures that category channels
have slugs when they are created or updated based on the
channel name, category name, or existing slug. The behaviour
has been copied from the Category model.

We also include a backfill here with a simplified version
of Slug.for with deduplication to fill the slugs for already
created Category chat channels.

The channel slug is also now used for chat notifications,
and for the UI and navigation for chat. `slugifyChannel`
is still used, but now does the following fallback:

* Uses channel.slug if it is present
* Uses channel.escapedTitle if it is present
* Uses channel.title if it is present

In future we may want to remove this altogether
and always rely on the slug being present, but this
is currently not possible because we are not generating
slugs for DM channels at this point.
2022-11-09 10:28:31 +10:00

74 lines
1.8 KiB
Ruby

# frozen_string_literal: true
RSpec.describe DirectMessageChannel do
subject(:channel) { Fabricate.build(:direct_message_channel) }
it_behaves_like "a chat channel model"
it { is_expected.to delegate_method(:allowed_user_ids).to(:direct_message).as(:user_ids) }
describe "#category_channel?" do
it "always returns false" do
expect(channel).not_to be_a_category_channel
end
end
describe "#public_channel?" do
it "always returns false" do
expect(channel).not_to be_a_public_channel
end
end
describe "#chatable_has_custom_fields?" do
it "always returns false" do
expect(channel).not_to be_a_chatable_has_custom_fields
end
end
describe "#direct_message_channel?" do
it "always returns true" do
expect(channel).to be_a_direct_message_channel
end
end
describe "#read_restricted?" do
it "always returns true" do
expect(channel).to be_read_restricted
end
end
describe "#allowed_group_ids" do
it "always returns nothing" do
expect(channel.allowed_group_ids).to be_nil
end
end
describe "#chatable_url" do
it "always returns nothing" do
expect(channel.chatable_url).to be_nil
end
end
describe "#title" do
subject(:title) { channel.title(user) }
let(:user) { stub }
let(:direct_message) { channel.direct_message }
it "delegates to direct_message" do
direct_message.expects(:chat_channel_title_for_user).with(channel, user).returns("something")
expect(title).to eq("something")
end
end
describe "slug generation" do
subject(:channel) { Fabricate(:direct_message_channel) }
it "always sets the slug to nil for direct message channels" do
channel.name = "Cool Channel"
channel.validate!
expect(channel.slug).to eq(nil)
end
end
end