FIX: display validation errors when converting topics (#27064)

When converting a PM to a public topic (and vice versa), if there was a validation error (like a topic already used, or a tag required or not allowed) the error message wasn't bubbled up nor shown to the user.

This fix ensures we properly stop the conversion whenever a validation error happens and bubble up the errors back to the user so they can be informed.

Internal ref - t/128795
This commit is contained in:
Régis Hanol
2024-05-17 16:36:25 +02:00
committed by GitHub
parent 9264479c27
commit e04ac5e2d8
5 changed files with 76 additions and 58 deletions

View File

@ -4613,7 +4613,7 @@ RSpec.describe TopicsController do
end
context "with success" do
it "returns success" do
it "returns success and the new url" do
sign_in(admin)
put "/t/#{topic.id}/convert-topic/public.json?category_id=#{category.id}"
@ -4627,6 +4627,20 @@ RSpec.describe TopicsController do
expect(result["url"]).to be_present
end
end
context "with some errors" do
it "returns the error messages" do
Fabricate(:topic, title: topic.title, category: category)
sign_in(admin)
put "/t/#{topic.id}/convert-topic/public.json?category_id=#{category.id}"
expect(response.status).to eq(422)
expect(response.parsed_body["errors"][0]).to end_with(
I18n.t("errors.messages.has_already_been_used"),
)
end
end
end
end