Skip to content

Commit 1d5ad36

Browse files
author
Arne De Herdt
authored
[CIOPS-1082] Dynamic routing (#2)
### Description This pull request changes the way the Engine is mounted, using an initializer or default settings. This will allow us to change the settings in case there's a conflict with the selected routing. ### Changes * Mount the engine dynamically * Reload routes for testing * Updated the documentation ### Ticket [CIOPS-1082](https://customink.atlassian.net/browse/CIOPS-1082)
2 parents b2db6c4 + 148afeb commit 1d5ad36

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Is It Ready? CHANGELOG
22

3+
## 0.0.3
4+
* Make the mounting of the engine dynamic based upon the configuration
5+
36
## 0.0.2
47
* Enabled the CircleCI Pipeline
58
* Added the test matrix

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ end
5454
With the above snippet, the health check will be available under:
5555

5656
* https://your-domain/is_it_ready
57-
* https://your-domain/is_it_ready/is_it_ready
5857

5958
## Configuration
6059

@@ -68,8 +67,7 @@ or conflicts with another plugin. In this case, creating an initializer under `c
6867
# Overwrite the endpoint that's used for listening to the required calls from the ReadinessProbe.
6968
# Setting this value, changes the second entry to be the path defined here, as well as the path under which
7069
# the application has been mounted:
71-
# * https://your-domain/<mount-path>
72-
# * https://your-domain/<mount-path>/something_else
70+
# * https://your-domain/something_else
7371
# This is more for cosmetic purposes, or when mountain multiple engines under the same endpoint with distinct routes.
7472
::IsItReady.endpoint = '/something_else'
7573
```

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
# This follows the same pattern as standard Ruby on Rails routing, but is scoped to
55
# just the Rails Engine.
66
::IsItReady::Engine.routes.draw do
7-
get ::IsItReady.endpoint => 'application#is_it_ready'
87
root :to => 'application#is_it_ready'
98
end

lib/is_it_ready/engine.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ module IsItReady
66
# how users will use this Engine in their applications.
77
class Engine < ::Rails::Engine
88
isolate_namespace IsItReady
9+
10+
# Initialize the engine dynamically based upon the configuration.
11+
# This allows us to specify the configuration for the engine in the host application instead.
12+
initializer 'add_routing_paths' do |app|
13+
app.routes.append do
14+
mount ::IsItReady::Engine => ::IsItReady.endpoint
15+
end
16+
end
917
end
1018
end

lib/is_it_ready/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module IsItReady
4-
VERSION = '0.0.2'
4+
VERSION = '0.0.3'
55
end

test/dummy/config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Rails.application.routes.draw do
22

3-
mount IsItReady::Engine => "/is_it_ready"
43
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'test_helper'
2+
3+
module IsItReady
4+
class CustomNavigationTest < ActionDispatch::IntegrationTest
5+
include Engine.routes.url_helpers
6+
7+
setup do
8+
::IsItReady.endpoint = '/something_else'
9+
Rails.application.reload_routes!
10+
end
11+
12+
test('it returns the correct response status on the root') do
13+
get root_url
14+
15+
assert_response :success
16+
end
17+
18+
test('it returns the correct output on the root') do
19+
get root_url
20+
21+
response = ::JSON.parse(@response.body, symbolize_names: true)
22+
23+
assert_equal({ :status => "ok", :code => 200 }, response)
24+
end
25+
26+
test('it returns the not found response status on the default path') do
27+
assert_raises(ActionController::RoutingError) { get DEFAULT_PATH }
28+
end
29+
end
30+
end

test/integration/navigation_test.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,5 @@ class NavigationTest < ActionDispatch::IntegrationTest
1717

1818
assert_equal({ :status => "ok", :code => 200 }, response)
1919
end
20-
21-
test('it returns the correct response status on the default path') do
22-
get DEFAULT_PATH
23-
24-
assert_response :success
25-
end
26-
27-
test('it returns the correct output on the default path') do
28-
get DEFAULT_PATH
29-
30-
response = ::JSON.parse(@response.body, symbolize_names: true)
31-
32-
assert_equal({ :status => "ok", :code => 200 }, response)
33-
end
3420
end
3521
end

0 commit comments

Comments
 (0)