FIX: Properly fabricate data for topic query specs. (#209)

FIX: Properly fabricate data for topic query specs. (#209)

We were creating PM topics that did not have any posts.

diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb
index 5cf0205..546b884 100644
--- a/spec/components/topic_query_spec.rb
+++ b/spec/components/topic_query_spec.rb
@@ -19,9 +19,12 @@ describe TopicQuery do
   end
 
   describe '#list_messages_assigned' do
-    fab!(:private_message) { Fabricate(:private_message_topic, user: user) }
-    fab!(:topic) { Fabricate(:topic, user: user) }
-    fab!(:group_topic) { Fabricate(:topic, user: user) }
+    fab!(:private_message) do
+      Fabricate(:private_message_post, user: user).topic
+    end
+
+    fab!(:topic) { Fabricate(:post, user: user).topic }
+    fab!(:group_topic) { Fabricate(:post, user: user).topic }
 
     before do
       assign_to(private_message, user, user)
@@ -58,9 +61,13 @@ describe TopicQuery do
 
   describe '#list_group_topics_assigned' do
 
-    fab!(:private_message) { Fabricate(:private_message_topic, user: user) }
-    fab!(:topic) { Fabricate(:topic, user: user) }
-    fab!(:group_topic) { Fabricate(:topic, user: user) }
+    fab!(:private_message) do
+      Fabricate(:private_message_post, user: user).topic
+    end
+
+    fab!(:topic) { Fabricate(:post, user: user).topic }
+
+    fab!(:group_topic) { Fabricate(:post, user: user).topic }
 
     before do
       assign_to(private_message, user, user)
@@ -91,42 +98,46 @@ describe TopicQuery do
 
   describe '#list_private_messages_assigned' do
     let(:user_topic) do
-      topic = Fabricate(:private_message_topic,
-        topic_allowed_users: [
-          Fabricate.build(:topic_allowed_user, user: user),
-          Fabricate.build(:topic_allowed_user, user: user2)
-        ],
-      )
+      topic = create_post(
+        user: Fabricate(:user),
+        target_usernames: [user.username, user2.username],
+        archetype: Archetype.private_message
+      ).topic
+
+      create_post(topic_id: topic.id, user: user)
 
-      topic.posts << Fabricate(:post)
       topic
     end
 
     let(:assigned_topic) do
-      topic = Fabricate(:private_message_topic,
-        topic_allowed_users: [
-          Fabricate.build(:topic_allowed_user, user: user),
-          Fabricate.build(:topic_allowed_user, user: user2)
-        ],
-      )
+      topic = create_post(
+        user: Fabricate(:user),
+        target_usernames: [user.username, user2.username],
+        archetype: Archetype.private_message
+      ).topic
+
       assign_to(topic, user, user)
     end
 
-    let(:group2) { Fabricate(:group) }
+    let(:group2) do
+      Fabricate(:group, messageable_level: Group::ALIAS_LEVELS[:everyone])
+    end
 
     let(:group_assigned_topic) do
-      topic = Fabricate(:private_message_topic,
-        topic_allowed_users: [],
-        topic_allowed_groups: [
-          Fabricate.build(:topic_allowed_group, group: assign_allowed_group),
-          Fabricate.build(:topic_allowed_group, group: group2)
-        ],
-      )
+      topic = create_post(
+        user: user,
+        target_group_names: [assign_allowed_group.name, group2.name],
+        archetype: Archetype.private_message
+      ).topic
 
       assign_to(topic, user, user)
     end
 
     before do
+      assign_allowed_group.update!(
+        messageable_level: Group::ALIAS_LEVELS[:everyone]
+      )
+
       user_topic
       assigned_topic
       group_assigned_topic
@@ -207,7 +218,6 @@ describe TopicQuery do
 
   def assign_to(topic, user, assignee)
     topic.tap do |t|
-      t.posts << Fabricate(:post)
       TopicAssigner.new(t, user).assign(assignee)
     end
   end

GitHub sha: 5f97e1603da24a131570f2f81c147820533244db

This commit appears in #209 which was approved by martin. It was merged by tgxworld.