Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/short_url_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 29 additions & 9 deletions spec/controllers/short_url_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")}\/.*/)

Check failure on line 338 in spec/controllers/short_url_requests_controller_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
.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
{
Expand Down
42 changes: 42 additions & 0 deletions spec/features/short_url_manager_responds_to_furl_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")}\/.*/)

Check failure on line 162 in spec/features/short_url_manager_responds_to_furl_requests_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
.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
Loading