Skip to content

Commit

Permalink
FIX: error when changing a topic's category and creating a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
nlalonde committed Mar 30, 2020
1 parent 339ddb8 commit 29e7338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/topics_controller.rb
Expand Up @@ -342,6 +342,8 @@ def update
end
end

invalid_tags = Tag.where_name(invalid_tags).pluck(:name)

if !invalid_tags.empty?
if (invalid_tags & DiscourseTagging.hidden_tag_names).present?
return render_json_error(I18n.t('category.errors.disallowed_tags_generic'))
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/topics_controller_spec.rb
Expand Up @@ -1038,6 +1038,32 @@ def topic_user_post_timings_count(user, topic)
expect(topic.tags.pluck(:id)).to contain_exactly(tag.id)
end

it "can create a tag" do
SiteSetting.min_trust_to_create_tag = 0
expect do
put "/t/#{topic.slug}/#{topic.id}.json", params: {
tags: ["newtag"]
}
end.to change { topic.reload.first_post.revisions.count }.by(1)

expect(response.status).to eq(200)
expect(topic.reload.tags.pluck(:name)).to contain_exactly("newtag")
end

it "can change the category and create a new tag" do
SiteSetting.min_trust_to_create_tag = 0
category = Fabricate(:category)
expect do
put "/t/#{topic.slug}/#{topic.id}.json", params: {
tags: ["newtag"],
category_id: category.id
}
end.to change { topic.reload.first_post.revisions.count }.by(1)

expect(response.status).to eq(200)
expect(topic.reload.tags.pluck(:name)).to contain_exactly("newtag")
end

it "can add a tag to wiki topic" do
SiteSetting.min_trust_to_edit_wiki_post = 2
topic.first_post.update!(wiki: true)
Expand Down

1 comment on commit 29e7338

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/cant-create-new-tag-and-change-category-at-the-same-time/145728/10

Please sign in to comment.