Skip to content

Commit

Permalink
Remove existing pattern from Redis before update
Browse files Browse the repository at this point in the history
Fixes a bug when updating a Route, to ensure Redis
is kept in sync.
  • Loading branch information
lewispb committed Apr 30, 2024
1 parent 1ed32ac commit 37e20e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/mission_control/web/routes_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ def initialize(application)
end

def put(route)
remove(route)

if route.disabled?
add(route)
else
remove(route)
end
end

def remove(route)
redis.srem redis_key, route.pattern.to_s
redis.srem redis_key, [ route.pattern_previously_was.to_s, route.pattern.to_s ]
end

def disabled?(path)
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Application < Rails::Application
config.mission_control.web.redis = Redis.new(url: "redis://localhost:6379/15")
config.mission_control.web.administered_applications = [
{ name: "Dummy App", redis: Redis.new(url: "redis://localhost:6379/15") },
{ name: "Another Dummy App", redis: Redis.new(url: "redis://localhost:6379/15") },
{ name: "Another Dummy App", redis: Redis.new(url: "redis://localhost:6379/15") }
]

# Configuration for the application, engines, and railties goes here.
Expand Down
7 changes: 7 additions & 0 deletions test/models/mission_control/web/route_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class MissionControl::Web::RouteTest < ActiveSupport::TestCase
assert_not MissionControl::Web.host_application.route_disabled? "/campfire"
end

test "updating a Route with a new pattern deletes the old pattern" do
@route.update!(pattern: "/chat")

assert_not MissionControl::Web.host_application.route_disabled? "/campfire"
assert MissionControl::Web.host_application.route_disabled? "/chat"
end

test "destroying a Route removes the routes configuration" do
@route.destroy!

Expand Down

0 comments on commit 37e20e3

Please sign in to comment.