Skip to content

Commit

Permalink
Merge pull request #2079 from tvdeyen/preview-url-fixes
Browse files Browse the repository at this point in the history
Preview url fixes
  • Loading branch information
tvdeyen authored Apr 23, 2021
2 parents ff836ad + 7cc978b commit c998f08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/alchemy/admin/preview_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def url_for(page)
if @preview_config && uri
uri_class.build(
host: uri.host,
port: uri.port,
path: page.url_path,
userinfo: userinfo,
query: { alchemy_preview_mode: true }.to_param,
).to_s
else
routes.admin_page_path(page)
Expand Down
24 changes: 18 additions & 6 deletions spec/libraries/admin/preview_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

it "returns the configured preview url" do
is_expected.to eq "http://www.example.com/#{page.urlname}"
is_expected.to eq "http://www.example.com/#{page.urlname}?alchemy_preview_mode=true"
end
end

Expand All @@ -51,7 +51,7 @@
end

it "returns the configured preview url with https" do
is_expected.to eq "https://www.example.com/#{page.urlname}"
is_expected.to eq "https://www.example.com/#{page.urlname}?alchemy_preview_mode=true"
end
end

Expand All @@ -67,7 +67,19 @@
end

it "returns the configured preview url with userinfo" do
is_expected.to eq "https://foo:baz@www.example.com/#{page.urlname}"
is_expected.to eq "https://foo:baz@www.example.com/#{page.urlname}?alchemy_preview_mode=true"
end
end

context "with a port configured" do
before do
stub_alchemy_config(:preview, {
"host" => "https://www.example.com:8080",
})
end

it "returns the configured preview url with userinfo" do
is_expected.to eq "https://www.example.com:8080/#{page.urlname}?alchemy_preview_mode=true"
end
end

Expand All @@ -86,7 +98,7 @@
end

it "returns the configured preview url for that site" do
is_expected.to eq "http://new.example.com/#{page.urlname}"
is_expected.to eq "http://new.example.com/#{page.urlname}?alchemy_preview_mode=true"
end
end

Expand All @@ -102,7 +114,7 @@
end

it "returns the default configured preview url" do
is_expected.to eq "http://www.example.com/#{page.urlname}"
is_expected.to eq "http://www.example.com/#{page.urlname}?alchemy_preview_mode=true"
end
end

Expand Down Expand Up @@ -132,7 +144,7 @@
end

it "returns the preview url without urlname" do
is_expected.to eq "https://www.example.com/"
is_expected.to eq "https://www.example.com/?alchemy_preview_mode=true"
end
end
end
Expand Down

0 comments on commit c998f08

Please sign in to comment.