FIX: prevent scheduled publishing to deleted category

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

Co-authored-by: tshenry
This commit is contained in:
Sam Saffron 2020-03-24 16:59:42 +11:00
parent 5b3bb4b2f0
commit 46a9622246
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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",