Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Unset the backend_id for redirects and gone routes
Browse files Browse the repository at this point in the history
Backends should only be set for routes with the "backend" handler.
Redirects and gone routes are handled directly in router and are not
proxied. This creates confusion in the data model, as redirect can
currently have a backend (however, its not sent to the backend).
  • Loading branch information
theseanything committed Aug 30, 2024
1 parent b38397e commit 0634428
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Route
end

before_validation :default_segments_mode
before_save :remove_backend_id_for_non_backend_routes
after_create :cleanup_child_gone_routes

scope :excluding, ->(route) { where(id: { :$ne => route.id }) }
Expand Down Expand Up @@ -132,6 +133,10 @@ def validate_backend_id
end
end

def remove_backend_id_for_non_backend_routes
self.backend_id = nil unless backend?
end

def cleanup_child_gone_routes
return unless route_type == "prefix"

Expand Down
20 changes: 20 additions & 0 deletions spec/models/route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@
end
end

describe "backend_id" do
it "is set to nil" do
expect(route.backend_id).to be nil
end
end

context "and segments_mode set to 'ignore'" do
subject(:route) { FactoryBot.build(:redirect_route, segments_mode: "ignore") }

Expand Down Expand Up @@ -249,6 +255,20 @@
end
end

describe "changing backend route to redirect route" do
it "will clear the backend_id" do
route = FactoryBot.create(:backend_route)
route.update!(
handler: "redirect",
redirect_to: "/",
redirect_type: "permanent",
)
route.reload

expect(route.backend_id).to be nil
end
end

describe "as_json" do
subject(:route) { FactoryBot.build(:redirect_route) }

Expand Down

0 comments on commit 0634428

Please sign in to comment.