summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-10 03:59:39 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-06-13 17:59:11 -0400
commit94d3c1433df9380ca83f1f35a540074ff0690410 (patch)
tree98da5a0832c587199b848af871e499a8980c4bf7
parent2bc4fd2d047c1c4c4637f045ed3a51d414359c2a (diff)
downloadgitlab-ce-94d3c1433df9380ca83f1f35a540074ff0690410.tar.gz
Add RootController
This controller is now the target for `root_url`. It sub-classes DashboardController so we can render the old default without a redirect if the user hasn't customized their dashboard location.
-rw-r--r--app/controllers/root_controller.rb18
-rw-r--r--app/views/layouts/nav/_dashboard.html.haml2
-rw-r--r--config/routes.rb2
-rw-r--r--spec/controllers/root_controller_spec.rb32
-rw-r--r--spec/routing/routing_spec.rb10
5 files changed, 60 insertions, 4 deletions
diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb
new file mode 100644
index 00000000000..7606d2d0fbe
--- /dev/null
+++ b/app/controllers/root_controller.rb
@@ -0,0 +1,18 @@
+# RootController
+#
+# This controller exists solely to handle requests to `root_url`. When a user is
+# logged in and has customized their `dashboard` setting, they will be
+# redirected to their preferred location.
+#
+# For users who haven't customized the setting, we simply delegate to
+# `DashboardController#show`, which is the default.
+class RootController < DashboardController
+ def show
+ case current_user.try(:dashboard)
+ when 'stars'
+ redirect_to starred_dashboard_projects_path
+ else
+ super
+ end
+ end
+end
diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml
index d46dba4a240..83e6fe863f9 100644
--- a/app/views/layouts/nav/_dashboard.html.haml
+++ b/app/views/layouts/nav/_dashboard.html.haml
@@ -1,6 +1,6 @@
%ul.nav.nav-sidebar
= nav_link(path: 'dashboard#show', html_options: {class: 'home'}) do
- = link_to root_path, title: 'Home', class: 'shortcuts-activity', data: {placement: 'right'} do
+ = link_to dashboard_path, title: 'Home', class: 'shortcuts-activity', data: {placement: 'right'} do
= icon('dashboard fw')
%span
Your Projects
diff --git a/config/routes.rb b/config/routes.rb
index 52c98541daf..d60bc796fdb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -293,7 +293,7 @@ Gitlab::Application.routes.draw do
get '/users/auth/:provider/omniauth_error' => 'omniauth_callbacks#omniauth_error', as: :omniauth_error
end
- root to: "dashboard#show"
+ root to: "root#show"
#
# Project Area
diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb
new file mode 100644
index 00000000000..abbbf6855fc
--- /dev/null
+++ b/spec/controllers/root_controller_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe RootController do
+ describe 'GET show' do
+ context 'with a user' do
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+ allow(subject).to receive(:current_user).and_return(user)
+ end
+
+ context 'who has customized their dashboard setting' do
+ before do
+ user.update_attribute(:dashboard, 'stars')
+ end
+
+ it 'redirects to their specified dashboard' do
+ get :show
+ expect(response).to redirect_to starred_dashboard_projects_path
+ end
+ end
+
+ context 'who uses the default dashboard setting' do
+ it 'renders the default dashboard' do
+ get :show
+ expect(response).to render_template 'dashboard/show'
+ end
+ end
+ end
+ end
+end
diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb
index 199851be482..f268e4755d1 100644
--- a/spec/routing/routing_spec.rb
+++ b/spec/routing/routing_spec.rb
@@ -204,11 +204,9 @@ end
# dashboard GET /dashboard(.:format) dashboard#show
# dashboard_issues GET /dashboard/issues(.:format) dashboard#issues
# dashboard_merge_requests GET /dashboard/merge_requests(.:format) dashboard#merge_requests
-# root / dashboard#show
describe DashboardController, "routing" do
it "to #index" do
expect(get("/dashboard")).to route_to('dashboard#show')
- expect(get("/")).to route_to('dashboard#show')
end
it "to #issues" do
@@ -220,6 +218,14 @@ describe DashboardController, "routing" do
end
end
+# root / root#show
+describe RootController, 'routing' do
+ it 'to #show' do
+ expect(get('/')).to route_to('root#show')
+ end
+end
+
+
# new_user_session GET /users/sign_in(.:format) devise/sessions#new
# user_session POST /users/sign_in(.:format) devise/sessions#create
# destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy