diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c43904..c00b197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Is It Ready? CHANGELOG +## 0.0.3 +* Make the mounting of the engine dynamic based upon the configuration + ## 0.0.2 * Enabled the CircleCI Pipeline * Added the test matrix diff --git a/README.md b/README.md index b170e5e..da6049c 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ end With the above snippet, the health check will be available under: * https://your-domain/is_it_ready -* https://your-domain/is_it_ready/is_it_ready ## Configuration @@ -68,8 +67,7 @@ or conflicts with another plugin. In this case, creating an initializer under `c # Overwrite the endpoint that's used for listening to the required calls from the ReadinessProbe. # Setting this value, changes the second entry to be the path defined here, as well as the path under which # the application has been mounted: -# * https://your-domain/ -# * https://your-domain//something_else +# * https://your-domain/something_else # This is more for cosmetic purposes, or when mountain multiple engines under the same endpoint with distinct routes. ::IsItReady.endpoint = '/something_else' ``` diff --git a/config/routes.rb b/config/routes.rb index 5788d8d..1422781 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,5 @@ # This follows the same pattern as standard Ruby on Rails routing, but is scoped to # just the Rails Engine. ::IsItReady::Engine.routes.draw do - get ::IsItReady.endpoint => 'application#is_it_ready' root :to => 'application#is_it_ready' end diff --git a/lib/is_it_ready/engine.rb b/lib/is_it_ready/engine.rb index 8c7ec80..2a02e8c 100644 --- a/lib/is_it_ready/engine.rb +++ b/lib/is_it_ready/engine.rb @@ -6,5 +6,13 @@ module IsItReady # how users will use this Engine in their applications. class Engine < ::Rails::Engine isolate_namespace IsItReady + + # Initialize the engine dynamically based upon the configuration. + # This allows us to specify the configuration for the engine in the host application instead. + initializer 'add_routing_paths' do |app| + app.routes.append do + mount ::IsItReady::Engine => ::IsItReady.endpoint + end + end end end diff --git a/lib/is_it_ready/version.rb b/lib/is_it_ready/version.rb index 0549d4e..e11147a 100644 --- a/lib/is_it_ready/version.rb +++ b/lib/is_it_ready/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module IsItReady - VERSION = '0.0.2' + VERSION = '0.0.3' end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index fcfa96b..9240ef4 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,4 +1,3 @@ Rails.application.routes.draw do - mount IsItReady::Engine => "/is_it_ready" end diff --git a/test/integration/custom_navigation_test.rb b/test/integration/custom_navigation_test.rb new file mode 100644 index 0000000..f02b9d1 --- /dev/null +++ b/test/integration/custom_navigation_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +module IsItReady + class CustomNavigationTest < ActionDispatch::IntegrationTest + include Engine.routes.url_helpers + + setup do + ::IsItReady.endpoint = '/something_else' + Rails.application.reload_routes! + end + + test('it returns the correct response status on the root') do + get root_url + + assert_response :success + end + + test('it returns the correct output on the root') do + get root_url + + response = ::JSON.parse(@response.body, symbolize_names: true) + + assert_equal({ :status => "ok", :code => 200 }, response) + end + + test('it returns the not found response status on the default path') do + assert_raises(ActionController::RoutingError) { get DEFAULT_PATH } + end + end +end diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index a7f7f0e..e888f92 100644 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -17,19 +17,5 @@ class NavigationTest < ActionDispatch::IntegrationTest assert_equal({ :status => "ok", :code => 200 }, response) end - - test('it returns the correct response status on the default path') do - get DEFAULT_PATH - - assert_response :success - end - - test('it returns the correct output on the default path') do - get DEFAULT_PATH - - response = ::JSON.parse(@response.body, symbolize_names: true) - - assert_equal({ :status => "ok", :code => 200 }, response) - end end end