Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Fixes topic creation double-ups #69

Merged
merged 1 commit into from Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/jobs/yearly_review.rb
Expand Up @@ -625,10 +625,13 @@ def most_bookmarked_topic_sql
end

def review_topic_exists?(review_year)
TopicCustomField
.find_by(name: ::YearlyReview::POST_CUSTOM_FIELD, value: review_year.to_s)
&.topic
.present?
TopicCustomField.joins(:topic).exists?(
name: ::YearlyReview::POST_CUSTOM_FIELD,
value: review_year.to_s,
topic: {
deleted_at: nil,
},
)
end
end
end
11 changes: 11 additions & 0 deletions spec/jobs/yearly_review_spec.rb
Expand Up @@ -64,6 +64,17 @@ class Helper
@yearly_review_topic.update!(title: "This is a test for yearly review")
expect { Jobs::YearlyReview.new.execute({}) }.not_to change { Topic.count }
end

it "doesn't publish the review topic again if it already exists and a previous version was deleted" do
@yearly_review_topic.trash!
expect { Jobs::YearlyReview.new.execute({}) }.to change { Topic.count }
expect { Jobs::YearlyReview.new.execute({}) }.not_to change { Topic.count }
end

it "doesn't publish the review topic again if it already exists and has been moved to another category" do
@yearly_review_topic.update!(category: Fabricate(:category))
expect { Jobs::YearlyReview.new.execute({}) }.not_to change { Topic.count }
end
end
end

Expand Down