From 67065b7dc40f6e6cdcace418c6867295a421813c Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 1 Jun 2020 19:46:32 +1000 Subject: [PATCH] fix(matrix ui): fix home link --- lib/pact_broker/api/resources/base_resource.rb | 5 +++++ lib/pact_broker/api/resources/latest_pact.rb | 2 +- lib/pact_broker/api/resources/pact.rb | 4 ++-- lib/pact_broker/ui/views/matrix/show.haml | 2 +- spec/lib/pact_broker/api/resources/latest_pact_spec.rb | 1 + spec/lib/pact_broker/api/resources/pact_spec.rb | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pact_broker/api/resources/base_resource.rb b/lib/pact_broker/api/resources/base_resource.rb index 0aef60d21..73f28a68f 100644 --- a/lib/pact_broker/api/resources/base_resource.rb +++ b/lib/pact_broker/api/resources/base_resource.rb @@ -62,6 +62,11 @@ def base_url PactBroker.configuration.base_url || request.base_uri.to_s.chomp('/') end + # See comments for base_url in lib/pact_broker/doc/controllers/app.rb + def ui_base_url + PactBroker.configuration.base_url || '' + end + def charsets_provided [['utf-8', :encode]] end diff --git a/lib/pact_broker/api/resources/latest_pact.rb b/lib/pact_broker/api/resources/latest_pact.rb index 8b25fbcc1..f95a0c4b8 100644 --- a/lib/pact_broker/api/resources/latest_pact.rb +++ b/lib/pact_broker/api/resources/latest_pact.rb @@ -36,7 +36,7 @@ def to_extended_json def to_html PactBroker.configuration.html_pact_renderer.call( pact, { - base_url: base_url, + base_url: ui_base_url, badge_url: "#{resource_url}/badge.svg" }) end diff --git a/lib/pact_broker/api/resources/pact.rb b/lib/pact_broker/api/resources/pact.rb index 0f5abc955..21ac5b380 100644 --- a/lib/pact_broker/api/resources/pact.rb +++ b/lib/pact_broker/api/resources/pact.rb @@ -77,8 +77,8 @@ def to_extended_json def to_html PactBroker.configuration.html_pact_renderer.call( pact, { - base_url: base_url, - badge_url: badge_url_for_latest_pact(pact, base_url) + base_url: ui_base_url, + badge_url: badge_url_for_latest_pact(pact, ui_base_url) }) end diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml index d131fa5c6..92334bc8f 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -10,7 +10,7 @@ .container .navbar-right - %a{href: base_url} + %a{href: "#{base_url}/"} Home %h1.page-header = title diff --git a/spec/lib/pact_broker/api/resources/latest_pact_spec.rb b/spec/lib/pact_broker/api/resources/latest_pact_spec.rb index d74fe3188..308752190 100644 --- a/spec/lib/pact_broker/api/resources/latest_pact_spec.rb +++ b/spec/lib/pact_broker/api/resources/latest_pact_spec.rb @@ -21,6 +21,7 @@ module Resources before do allow(PactBroker::Pacts::Service).to receive(:find_latest_pact).and_return(pact) allow(PactBroker.configuration.html_pact_renderer).to receive(:call).and_return(html) + allow_any_instance_of(LatestPact).to receive(:ui_base_url).and_return('http://example.org') end subject { get(path, nil, 'HTTP_ACCEPT' => accept) } diff --git a/spec/lib/pact_broker/api/resources/pact_spec.rb b/spec/lib/pact_broker/api/resources/pact_spec.rb index 4704a68bc..c7b1bea2d 100644 --- a/spec/lib/pact_broker/api/resources/pact_spec.rb +++ b/spec/lib/pact_broker/api/resources/pact_spec.rb @@ -24,6 +24,7 @@ module Resources before do allow_any_instance_of(Pact).to receive(:badge_url_for_latest_pact).and_return('http://badge') + allow_any_instance_of(Pact).to receive(:ui_base_url).and_return('http://example.org') allow(PactBroker::Pacts::Service).to receive(:find_pact).and_return(pact) allow(PactBroker.configuration.html_pact_renderer).to receive(:call).and_return(html) end