FIX: Permalink.create didn't work as expected anymore (#29895)

This moves the logic of setting the correct permalink values back into the controller. And it replaces the validation with a simpler one, that always works, even when the model is loaded from the DB.

Follow-up to #29634 which broke import scripts and lots of documentation on Meta.
This commit is contained in:
Gerhard Schlager
2024-11-22 21:11:26 +01:00
committed by GitHub
parent 44fbf1048c
commit 0295b4165c
9 changed files with 78 additions and 216 deletions

View File

@ -10,20 +10,10 @@ RSpec.describe Admin::PermalinksController do
before { sign_in(admin) }
it "filters url" do
Fabricate(:permalink, url: "/forum/23", permalink_type_value: "1", permalink_type: "topic")
Fabricate(:permalink, url: "/forum/98", permalink_type_value: "1", permalink_type: "topic")
Fabricate(
:permalink,
url: "/discuss/topic/45",
permalink_type_value: "1",
permalink_type: "topic",
)
Fabricate(
:permalink,
url: "/discuss/topic/76",
permalink_type_value: "1",
permalink_type: "topic",
)
Fabricate(:permalink, url: "/forum/23", topic_id: 1)
Fabricate(:permalink, url: "/forum/98", topic_id: 1)
Fabricate(:permalink, url: "/discuss/topic/45", topic_id: 1)
Fabricate(:permalink, url: "/discuss/topic/76", topic_id: 1)
get "/admin/permalinks.json", params: { filter: "topic" }
@ -33,26 +23,10 @@ RSpec.describe Admin::PermalinksController do
end
it "filters external url" do
Fabricate(
:permalink,
permalink_type_value: "http://google.com",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://wikipedia.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://www.discourse.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
permalink_type_value: "http://try.discourse.org",
permalink_type: "external_url",
)
Fabricate(:permalink, external_url: "http://google.com")
Fabricate(:permalink, external_url: "http://wikipedia.org")
Fabricate(:permalink, external_url: "http://www.discourse.org")
Fabricate(:permalink, external_url: "http://try.discourse.org")
get "/admin/permalinks.json", params: { filter: "discourse" }
@ -62,30 +36,10 @@ RSpec.describe Admin::PermalinksController do
end
it "filters url and external url both" do
Fabricate(
:permalink,
url: "/forum/23",
permalink_type_value: "http://google.com",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discourse/98",
permalink_type_value: "http://wikipedia.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discuss/topic/45",
permalink_type_value: "http://discourse.org",
permalink_type: "external_url",
)
Fabricate(
:permalink,
url: "/discuss/topic/76",
permalink_type_value: "http://try.discourse.org",
permalink_type: "external_url",
)
Fabricate(:permalink, url: "/forum/23", external_url: "http://google.com")
Fabricate(:permalink, url: "/discourse/98", external_url: "http://wikipedia.org")
Fabricate(:permalink, url: "/discuss/topic/45", external_url: "http://discourse.org")
Fabricate(:permalink, url: "/discuss/topic/76", external_url: "http://try.discourse.org")
get "/admin/permalinks.json", params: { filter: "discourse" }