diff --git a/app/controllers/short_url_requests_controller.rb b/app/controllers/short_url_requests_controller.rb index b57461ad..942bae7c 100644 --- a/app/controllers/short_url_requests_controller.rb +++ b/app/controllers/short_url_requests_controller.rb @@ -64,7 +64,10 @@ def update flash[:success] = "Your edit was successful." redirect_to short_url_request_path(@short_url_request) }, - failure: -> { render "edit" }, + failure: lambda { + # flash[:alert] = "Bah humbug." + render "edit" + }, ) end diff --git a/spec/controllers/short_url_requests_controller_spec.rb b/spec/controllers/short_url_requests_controller_spec.rb index fb0c9924..b9c3ad4d 100644 --- a/spec/controllers/short_url_requests_controller_spec.rb +++ b/spec/controllers/short_url_requests_controller_spec.rb @@ -314,17 +314,16 @@ describe "#update" do let!(:organisation) { create(:organisation) } let!(:short_url_request) { create(:short_url_request, from_path: "/original") } + let(:params) do + { + from_path: short_url_request.from_path, + to_path: "/somewhere/different", + reason: "Because wombles", + organisation_slug: organisation.slug, + } + end context "with valid parameters" do - let(:params) do - { - from_path: short_url_request.from_path, - to_path: "/somewhere/different", - reason: "Because wombles", - organisation_slug: organisation.slug, - } - end - it "saves the changes" do put :update, params: { id: short_url_request.id, short_url_request: params } expect(response).to redirect_to(short_url_request_path(short_url_request)) @@ -334,6 +333,27 @@ end end + context "route exists on publishing api already, and override has not been set to yes" do + before do + stub_request(:any, /#{Plek.find("publishing-api")}\/.*/) + .to_return( + body: { + error: { + code: 422, + message: "Base path /foo is already reserved by content-tagger", + }, + }.to_json, + status: 422, + ) + end + + it "should have a custom flash message" do + put :update, params: { id: short_url_request.id, short_url_request: params } + + expect(flash).to eq("foo") + end + end + context "with a change to the from_path" do let(:params) do { diff --git a/spec/features/short_url_manager_responds_to_furl_requests_spec.rb b/spec/features/short_url_manager_responds_to_furl_requests_spec.rb index bbc3e22b..326e087d 100644 --- a/spec/features/short_url_manager_responds_to_furl_requests_spec.rb +++ b/spec/features/short_url_manager_responds_to_furl_requests_spec.rb @@ -141,4 +141,46 @@ end end end + + describe "Approving a short URL request when there are complications in Publishing API" do + context "Publishing API is down" do + before { stub_publishing_api_isnt_available } + + it "shows error message to user" do + visit short_url_requests_path + + click_on "Ministry of Beards" + click_on "Accept and create redirect" + within(".form-errors") do + expect(page).to have_content "An error posting to the publishing API prevented this redirect from being created:" + end + end + end + + context "The route is owned by another application" do + before do + stub_request(:any, /#{Plek.find("publishing-api")}\/.*/) + .to_return( + body: { + error: { + code: 422, + message: "Base path /foo is already reserved by content-tagger", + }, + }.to_json, + status: 422, + ) + end + + it "shows error message to user" do + visit short_url_requests_path + + click_on "Ministry of Beards" + click_on "Accept and create redirect" + within(".form-errors") do + expect(page).to have_content "An error posting to the publishing API prevented this redirect from being created:" + expect(page).to have_content "Base path /foo is already reserved by content-tagger" + end + end + end + end end