From b6c53cd855af16d90bac5f9b0d78b8c5f6cf5baf Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Fri, 10 Apr 2015 09:38:55 -0700 Subject: [PATCH 1/2] Redirect / to /dashboard --- lib/vmpooler/api.rb | 14 +++++++++++--- lib/vmpooler/dashboard.rb | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 lib/vmpooler/dashboard.rb diff --git a/lib/vmpooler/api.rb b/lib/vmpooler/api.rb index 2219614..70bd319 100644 --- a/lib/vmpooler/api.rb +++ b/lib/vmpooler/api.rb @@ -17,11 +17,19 @@ module Vmpooler end get '/' do - erb :dashboard, locals: { - site_name: $config[:config]['site_name'] || 'vmpooler' - } + redirect to('/dashboard/') end + # Load dashboard components + begin + require "dashboard" + rescue LoadError + require File.expand_path(File.join(File.dirname(__FILE__), 'dashboard')) + end + + use Vmpooler::Dashboard + + # Load API components %w( dashboard reroute v1 ).each do |lib| begin require "api/#{lib}" diff --git a/lib/vmpooler/dashboard.rb b/lib/vmpooler/dashboard.rb new file mode 100644 index 0000000..56259d6 --- /dev/null +++ b/lib/vmpooler/dashboard.rb @@ -0,0 +1,9 @@ +module Vmpooler + class Dashboard < Sinatra::Base + get '/dashboard/?' do + erb :dashboard, locals: { + site_name: $config[:config]['site_name'] || 'vmpooler' + } + end + end +end From 6224a20792f9f811eb9ed457a7bf6293f81a0e0c Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Fri, 10 Apr 2015 10:03:33 -0700 Subject: [PATCH 2/2] Add spec tests for dashboard redirect --- spec/vmpooler/api_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/vmpooler/api_spec.rb b/spec/vmpooler/api_spec.rb index 5707e83..246503f 100644 --- a/spec/vmpooler/api_spec.rb +++ b/spec/vmpooler/api_spec.rb @@ -11,13 +11,20 @@ describe Vmpooler::API do describe 'Dashboard' do context '/' do + before { get '/' } + + it { expect(last_response.status).to eq(302) } + it { expect(last_response.location).to eq('http://example.org/dashboard/') } + end + + context '/dashboard/' do let(:config) { { config: {'site_name' => 'test pooler'} } } before do $config = config - get '/' + get '/dashboard/' end it { expect(last_response).to be_ok } @@ -166,4 +173,4 @@ describe Vmpooler::API do end -end \ No newline at end of file +end