FIX: Notify tag watchers when publishing topic (#17576)

When a topic was published from a shared draft and it had tags, the
users watching the tags were not notified. The problem was that the
topics are usually created in a secret category and publishing it just
moves an existent topic to the target category, without making any
changes to the tags.
This commit is contained in:
Bianca Nenciu
2022-07-20 19:07:18 +03:00
committed by GitHub
parent 7a668460e0
commit f75a99e932
3 changed files with 29 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ describe TopicPublisher do
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
fab!(:moderator) { Fabricate(:moderator) }
fab!(:op) { Fabricate(:post, topic: topic) }
fab!(:user) { Fabricate(:user) }
fab!(:tag) { Fabricate(:tag) }
before do
# Create a revision
@@ -51,6 +53,24 @@ describe TopicPublisher do
expect(op.last_version_at).to eq_time(published_at)
end
end
it "will notify users watching tag" do
Jobs.run_immediately!
TagUser.create!(
user_id: user.id,
tag_id: tag.id,
notification_level: NotificationLevels.topic_levels[:watching]
)
topic.update!(tags: [tag])
expect { TopicPublisher.new(topic, moderator, shared_draft.category_id).publish! }
.to change { Notification.count }.by(1)
topic.reload
expect(topic.tags).to contain_exactly(tag)
end
end
end