FIX: prevent scheduled publishing to deleted category

FIX: prevent scheduled publishing to deleted category

We missed a dependency which left timers firing on missing categories.

Co-authored-by: tshenry

diff --git a/app/models/category.rb b/app/models/category.rb
index bb4a8d5..6e0a073 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -42,6 +42,7 @@ class Category < ActiveRecord::Base
 
   has_many :category_groups, dependent: :destroy
   has_many :groups, through: :category_groups
+  has_many :topic_timers, dependent: :destroy
 
   has_and_belongs_to_many :web_hooks
 
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index ff5110a..8451936 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -46,7 +46,7 @@ describe CategoriesController do
     end
 
     it "respects permalinks before redirecting /category paths to /c paths" do
-      perm = Permalink.create!(url: "category/something", category_id: category.id)
+      _perm = Permalink.create!(url: "category/something", category_id: category.id)
 
       get "/category/something"
       expect(response.status).to eq(301)
@@ -218,11 +218,15 @@ describe CategoriesController do
 
       it "deletes the record" do
         sign_in(admin)
+
+        id = Fabricate(:topic_timer, category: category).id
+
         expect do
           delete "/categories/#{category.slug}.json"
         end.to change(Category, :count).by(-1)
         expect(response.status).to eq(200)
         expect(UserHistory.count).to eq(1)
+        expect(TopicTimer.where(id: id).exists?).to eq(false)
       end
     end
   end
@@ -321,7 +325,7 @@ describe CategoriesController do
       end
 
       it "returns 422 if email_in address is already in use for other category" do
-        other_category = Fabricate(:category, name: "Other", email_in: "mail@examle.com")
+        _other_category = Fabricate(:category, name: "Other", email_in: "mail@examle.com")
 
         put "/categories/#{category.id}.json", params: {
           name: "Email",

GitHub sha: 46a96222