Fix failing spec. (#22)

Fix failing spec. (#22)

Follow up to ce5e52ba317381fa516da1a08ea095940224457c

diff --git a/plugin.rb b/plugin.rb
index 1ee284c..1917b8e 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -93,10 +93,13 @@ after_initialize do
       .where("not topics.closed AND topics.category_id IN (?)", alerts_category_ids_cache)
   end
 
-  add_class_method(:topic, :firing_alerts) do
+  add_class_method(:topic, :firing_alerts) do |category_ids = []|
     joins(:alert_receiver_alerts)
       .where("alert_receiver_alerts.status": 'firing')
-      .where("not topics.closed AND topics.category_id IN (?)", alerts_category_ids_cache)
+      .where(
+        "not topics.closed AND topics.category_id IN (?)",
+        category_ids.present? ? category_ids : alerts_category_ids_cache
+      )
   end
 
   add_to_class(:user, :include_alert_counts?) do
@@ -141,10 +144,9 @@ after_initialize do
   ) do |results, topic_query|
 
     options = topic_query.options
-    category_id = Category.where(slug: 'alerts').pluck(:id).first # TODO: don't hardcode the category slug
 
-    if options[:category_id] == category_id && options[:status] == 'firing'
-      results = results.firing_alerts
+    if Topic.alerts_category_ids_cache.include?(options[:category_id]) && options[:status] == 'firing'
+      results = results.firing_alerts([options[:category_id]])
     end
 
     results
diff --git a/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb b/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
index f0889bf..5232b2f 100644
--- a/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
+++ b/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe DiscoursePrometheusAlertReceiver::ReceiverController do
   let(:plugin_name) { DiscoursePrometheusAlertReceiver::PLUGIN_NAME }
 
   before do
-    SiteSetting.assign_allowed_on_groups += "|#{assignee_group.id}"
+    SiteSetting.assign_allowed_on_groups = assignee_group.id.to_s
   end
 
   describe "#generate_receiver_url" do
diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rb
index 953b86b..1ff86f9 100644
--- a/spec/lib/topic_query_spec.rb
+++ b/spec/lib/topic_query_spec.rb
@@ -4,7 +4,16 @@ require 'rails_helper'
 
 RSpec.describe TopicQuery do
   let(:user) { Fabricate(:user) }
-  let(:category) { Fabricate(:category, name: 'alerts') }
+
+  fab!(:category) { Fabricate(:category, name: 'alerts') }
+
+  fab!(:plugin_store_row) do
+    PluginStore.set(
+      ::DiscoursePrometheusAlertReceiver::PLUGIN_NAME,
+      'sometoken',
+      { category_id: category.id }
+    )
+  end
 
   describe '#list_latest' do
     it 'should return the right topics' do
@@ -29,7 +38,7 @@ RSpec.describe TopicQuery do
         category: category.slug
       )
 
-      expect(topic_query.list_latest.topics).to eq([topic1])
+      expect(topic_query.list_latest.topics).to contain_exactly(topic1)
     end
   end
 end

GitHub sha: 4f95cda5cceedaad03e777dfeddf320620e2e2ca

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