DEV: Refactor `SystemMessage#create` specs.

DEV: Refactor SystemMessage#create specs.

diff --git a/spec/components/system_message_spec.rb b/spec/components/system_message_spec.rb
index b0c1845..088c19f 100644
--- a/spec/components/system_message_spec.rb
+++ b/spec/components/system_message_spec.rb
@@ -6,7 +6,7 @@ require 'topic_subtype'
 
 describe SystemMessage do
 
-  context 'send' do
+  context '#create' do
 
     fab!(:admin) { Fabricate(:admin) }
     fab!(:user) { Fabricate(:user) }
@@ -20,14 +20,17 @@ describe SystemMessage do
       post = system_message.create(:welcome_invite)
       topic = post.topic
 
-      expect(post.valid?).to eq(true)
-      expect(topic).to be_private_message
-      expect(topic).to be_valid
+      expect(topic.private_message?).to eq(true)
       expect(topic.subtype).to eq(TopicSubtype.system_message)
-      expect(topic.allowed_users.include?(user)).to eq(true)
-      expect(topic.allowed_users.include?(admin)).to eq(true)
 
-      expect(UserArchivedMessage.where(user_id: admin.id, topic_id: topic.id).length).to eq(1)
+      expect(topic.allowed_users.pluck(:user_id)).to contain_exactly(
+        user.id, admin.id
+      )
+
+      expect(UserArchivedMessage.where(
+        user_id: admin.id,
+        topic_id: topic.id
+      ).count).to eq(1)
     end
 
     it 'can create a post from system user in user selected locale' do
@@ -38,14 +41,18 @@ describe SystemMessage do
       post = SystemMessage.create_from_system_user(user_de, :welcome_invite)
       topic = post.topic
 
-      expect(post.valid?).to eq(true)
-      expect(topic).to be_private_message
-      expect(topic).to be_valid
+      expect(topic.private_message?).to eq(true)
       expect(topic.title).to eq(I18n.with_locale(:de) { I18n.t("system_messages.welcome_invite.subject_template", site_name: SiteSetting.title) })
       expect(topic.subtype).to eq(TopicSubtype.system_message)
-      expect(topic.allowed_users.include?(user_de)).to eq(true)
-      expect(topic.allowed_users.include?(system_user)).to eq(true)
-      expect(UserArchivedMessage.where(user_id: system_user.id, topic_id: topic.id).length).to eq(0)
+
+      expect(topic.allowed_users.pluck(:user_id)).to contain_exactly(
+        user_de.id, system_user.id
+      )
+
+      expect(UserArchivedMessage.where(
+        user_id: system_user.id,
+        topic_id: topic.id
+      ).count).to eq(0)
     end
 
     it 'should allow site_contact_group_name' do
@@ -57,7 +64,7 @@ describe SystemMessage do
 
       group.update!(name: "anewname")
       post = SystemMessage.create(user, :welcome_invite)
-      expect(post.topic.allowed_groups).to contain_exactly()
+      expect(post.topic.allowed_groups).to eq([])
     end
   end

GitHub sha: 8858dbb5

2 Likes