mirror of
https://github.com/discourse/discourse.git
synced 2025-02-18 03:12:45 +08:00
![Loïc Guitaut](/assets/img/avatar_default.png)
This is a followup of the previous refactor where we created two new models to handle all the dedicated logic that was present in the `ChatChannel` model. For the sake of consistency, `DMChannel` has been renamed to `DirectMessageChannel` and the previous `DirectMessageChannel` model is now named `DirectMessage`. This should help reasoning about direct messages.
64 lines
1.5 KiB
Ruby
64 lines
1.5 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
|
|
end
|