Commit a3f4bba

mo <mo.khan@gmail.com>
2018-09-01 22:26:56
move dashboard to "my" namespace.
1 parent ade5ba7
app/controllers/my/dashboards_controller.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module My
+  class DashboardsController < ApplicationController
+    def show
+      @metadatum = Saml::Kit.registry.to_a
+    end
+  end
+end
app/controllers/my/mfas_controller.rb
@@ -9,14 +9,14 @@ module My
 
     def create
       current_user.update!(params.require(:user).permit(:tfa_secret))
-      redirect_to dashboard_path, notice: "successfully updated!"
+      redirect_to my_dashboard_path, notice: "successfully updated!"
     end
 
     def edit; end
 
     def destroy
       current_user.tfa.disable!
-      redirect_to dashboard_path
+      redirect_to my_dashboard_path
     end
   end
 end
app/controllers/dashboards_controller.rb
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-class DashboardsController < ApplicationController
-  def show
-    @metadatum = Saml::Kit.registry.to_a
-  end
-end
app/controllers/sessions_controller.rb
@@ -24,7 +24,7 @@ class SessionsController < ApplicationController
     if (user = User.login(user_params[:email], user_params[:password]))
       unless session[:saml].present?
         login(user)
-        return redirect_to(dashboard_path)
+        return redirect_to(my_dashboard_path)
       end
 
       saml_request = Saml::Kit::AuthenticationRequest.new(session[:saml][:xml])
app/views/dashboards/show.html.erb → app/views/my/dashboards/show.html.erb
File renamed without changes
app/views/my/mfas/edit.html.erb
@@ -10,7 +10,7 @@
         <%= form_for current_user, url: tfa_path, method: :delete do |form| %>
           <%= form.hidden_field :tfa_secret, data: { target: 'tfa--setup.secret' } %>
           <%= form.submit "Disable", class: 'btn btn-danger', data: { disable_with: 'Saving…' } %>
-          <%= link_to "Cancel", dashboard_path, class: 'btn' %>
+          <%= link_to "Cancel", my_dashboard_path, class: 'btn' %>
         <% end %>
       </div>
     </div>
app/views/my/mfas/new.html.erb
@@ -10,7 +10,7 @@
         <%= form_for current_user, url: my_mfa_path, method: :post do |form| %>
           <%= form.hidden_field :tfa_secret, data: { target: 'tfa--setup.secret' } %>
           <%= form.submit "Save", class: 'btn btn-primary', data: { disable_with: 'Saving…' } %>
-          <%= link_to "Cancel", dashboard_path, class: 'btn' %>
+          <%= link_to "Cancel", my_dashboard_path, class: 'btn' %>
         <% end %>
       </div>
     </div>
config/routes.rb
@@ -4,9 +4,9 @@ Rails.application.routes.draw do
   post "/session/logout" => "sessions#destroy", as: :logout
   post "/session/new" => "sessions#new"
   resource :metadata, only: [:show]
-  resource :dashboard, only: [:show]
   resources :registrations, only: [:new, :create]
   namespace :my do
+    resource :dashboard, only: [:show]
     resource :mfa, only: [:new, :edit, :create, :destroy]
   end
   namespace :scim do
spec/requests/my/dashboard_spec.rb
@@ -0,0 +1,21 @@
+require 'rails_helper'
+
+RSpec.describe "/my/dashboard" do
+  context "when logged in" do
+    let(:current_user) { create(:user) }
+
+    before { http_login(current_user) }
+
+    describe "GET /my/dashboard" do
+      before { get '/my/dashboard' }
+
+      specify { expect(response).to have_http_status(:ok) }
+    end
+  end
+
+  context "when not logged in" do
+    before { get '/my/dashboard' }
+
+    specify { expect(response).to redirect_to(new_session_path) }
+  end
+end
spec/requests/my/mfas_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe '/my/mfa' do
         before { post '/my/mfa', params: { user: { tfa_secret: secret } } }
 
         specify { expect(current_user.reload.tfa_secret).to eql(secret) }
-        specify { expect(response).to redirect_to(dashboard_path) }
+        specify { expect(response).to redirect_to(my_dashboard_path) }
         specify { expect(flash[:notice]).to include("successfully updated!") }
       end
     end
@@ -39,8 +39,14 @@ RSpec.describe '/my/mfa' do
         before { delete '/my/mfa' }
 
         specify { expect(current_user.reload.tfa_secret).to be_nil }
-        specify { expect(response).to redirect_to(dashboard_path) }
+        specify { expect(response).to redirect_to(my_dashboard_path) }
       end
     end
   end
+
+  context "when not logged in" do
+    before { get '/my/mfa/new' }
+
+    specify { expect(response).to redirect_to(new_session_path) }
+  end
 end
spec/requests/sessions_controller_spec.rb
@@ -79,10 +79,9 @@ describe SessionsController do
     let(:user) { User.create!(email: FFaker::Internet.email, password: password) }
     let(:password) { FFaker::Internet.password }
 
-    it 'redirects to the dashboard when a SAMLRequest is not present' do
-      post '/session', params: { user: { email: user.email, password: password } }
-
-      expect(response).to redirect_to('/dashboard')
+    context "when a SAMLRequest is not present" do
+      before { post '/session', params: { user: { email: user.email, password: password } } }
+      specify { expect(response).to redirect_to(my_dashboard_path) }
     end
 
     it 'posts the response back to the ACS endpoint' do