mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
FIX: set external flag before validation (#20599)
Previously, `before_save` callback was used but `before_validation` has to be used to set external flag.
This commit is contained in:
parent
008f71b961
commit
22bccef8f4
@ -7,7 +7,7 @@ class SidebarUrl < ActiveRecord::Base
|
||||
|
||||
validate :path_validator
|
||||
|
||||
before_save :remove_internal_hostname, :set_external
|
||||
before_validation :remove_internal_hostname, :set_external
|
||||
|
||||
def path_validator
|
||||
if external?
|
||||
|
@ -8,5 +8,39 @@ RSpec.describe SidebarUrl do
|
||||
expect(SidebarUrl.new(icon: "link", name: "categories", value: "/invalid_path").valid?).to eq(
|
||||
false,
|
||||
)
|
||||
expect(
|
||||
SidebarUrl.new(
|
||||
icon: "link",
|
||||
name: "external",
|
||||
value: "https://www.test.com/discourse-test",
|
||||
).valid?,
|
||||
).to eq(true)
|
||||
end
|
||||
|
||||
it "sets external flag" do
|
||||
expect(
|
||||
SidebarUrl.create!(icon: "link", name: "categories", value: "/categories").external,
|
||||
).to be false
|
||||
expect(
|
||||
SidebarUrl.create!(
|
||||
icon: "link",
|
||||
name: "categories",
|
||||
value: "http://#{Discourse.current_hostname}/categories",
|
||||
).external,
|
||||
).to be false
|
||||
expect(
|
||||
SidebarUrl.create!(
|
||||
icon: "link",
|
||||
name: "categories",
|
||||
value: "https://#{Discourse.current_hostname}/categories",
|
||||
).external,
|
||||
).to be false
|
||||
expect(
|
||||
SidebarUrl.create!(
|
||||
icon: "link",
|
||||
name: "categories",
|
||||
value: "https://www.test.com/discourse-test",
|
||||
).external,
|
||||
).to be true
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user