2023-02-02 21:44:40 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe SidebarUrl do
|
2023-03-31 00:26:56 -05:00
|
|
|
it "validates external URLs" do
|
2023-03-08 17:44:54 -06:00
|
|
|
expect(
|
|
|
|
SidebarUrl.new(
|
|
|
|
icon: "link",
|
|
|
|
name: "external",
|
|
|
|
value: "https://www.test.com/discourse-test",
|
|
|
|
).valid?,
|
|
|
|
).to eq(true)
|
2023-05-23 17:59:19 -05:00
|
|
|
expect(
|
|
|
|
SidebarUrl.new(
|
|
|
|
icon: "link",
|
|
|
|
name: "categories",
|
|
|
|
value: "http://#{Discourse.current_hostname}/pub/test",
|
|
|
|
).valid?,
|
|
|
|
).to eq(true)
|
2023-08-16 23:46:24 -05:00
|
|
|
expect(
|
|
|
|
SidebarUrl.new(
|
|
|
|
icon: "link",
|
|
|
|
name: "external",
|
|
|
|
value: "https://www.test.com/" + "a" * 979,
|
|
|
|
).valid?,
|
|
|
|
).to eq(true)
|
|
|
|
expect(
|
|
|
|
SidebarUrl.new(
|
|
|
|
icon: "link",
|
|
|
|
name: "external",
|
|
|
|
value: "https://www.test.com/" + "a" * 980,
|
|
|
|
).valid?,
|
|
|
|
).to eq(false)
|
2023-03-08 17:44:54 -06:00
|
|
|
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
|
2023-02-02 21:44:40 -06:00
|
|
|
end
|
|
|
|
end
|