From 47f8fc2da0d6cb74f20a414f04a64d915d43e654 Mon Sep 17 00:00:00 2001 From: Anthony Truskinger Date: Thu, 1 Dec 2016 16:09:04 +1000 Subject: [PATCH] Simplified analysis_jobs routing Having the client and server both use the `/analysis_jobs` route was nearly impossible to get working. Instead, the client moved its UI to `/audio_analysis` in https://github.com/QutBioacoustics/baw-client/commit/21b0fc8c6041fd4861daa3afdb3896b791c6f771. Also committing unit tests for the Rack::Rewrite rewrite rules which were previously untested. --- config/application.rb | 8 +------ spec/routing/rack_rewrite_spec.rb | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 spec/routing/rack_rewrite_spec.rb diff --git a/config/application.rb b/config/application.rb index 79fe27f7..5df0d77b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -137,12 +137,6 @@ class Application < Rails::Application # for generating documentation from tests Raddocs.configuration.docs_dir = "doc/api" - def should_route_to_client(rack_env) - (rack_env['REQUEST_METHOD'] == 'GET' && - !(Mime::Type.parse(rack_env['HTTP_ACCEPT'] || '')).include?(Mime::JSON) && - File.extname(rack_env['REQUEST_PATH'] || '') == '') - end - # middleware to rewrite angular urls # insert at the start of the Rack stack. config.middleware.insert_before 0, Rack::Rewrite do @@ -153,7 +147,7 @@ def should_route_to_client(rack_env) rewrite /^\/library.*/i, '/listen_to/index.html' rewrite /^\/demo.*/i, '/listen_to/index.html' rewrite /^\/visualize.*/i, '/listen_to/index.html' - rewrite /^\/analysis_jobs.*/i, '/listen_to/index.html', if: Application.method(:should_route_to_client) + rewrite /^\/audio_analysis.*/i, '/listen_to/index.html' end # allow any origin, with any header, to access the array of methods diff --git a/spec/routing/rack_rewrite_spec.rb b/spec/routing/rack_rewrite_spec.rb new file mode 100644 index 00000000..6731cab7 --- /dev/null +++ b/spec/routing/rack_rewrite_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +describe 'Rack rewrite', :type => :feature do # :type => :routing + describe :routing do + + client_app_content = 'Client application placeholder This is the page that will be rendered if a client side view needs to be rendered.' + + it { + visit '/listen' + expect(page.text).to include(client_app_content) + } + + it { + visit '/birdwalks' + expect(page.text).to include(client_app_content) + } + + it { + visit '/library' + expect(page.text).to include(client_app_content) + } + + it { + visit '/demo' + expect(page.text).to include(client_app_content) + } + + it { + visit '/visualize' + expect(page.text).to include(client_app_content) + } + + it { + visit '/audio_analysis' + expect(page.text).to include(client_app_content) + } + + end +end \ No newline at end of file