Commit 2831cad

mo <mo.khan@gmail.com>
2018-09-23 22:14:38
display sessions.
1 parent 03b6030
Changed files (7)
app
controllers
views
config
spec
requests
app/controllers/my/sessions_controller.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module My
+  class SessionsController < ApplicationController
+    def index
+      @sessions = current_user.sessions
+    end
+  end
+end
app/views/application/_navbar.html.erb
@@ -9,6 +9,7 @@
         <%= link_to t(".home"), my_dashboard_path, class: 'nav-item nav-link active' %>
         <%= link_to t(".clients"), my_clients_path, class: 'nav-item nav-link' %>
         <%= link_to t(".mfa"), my_mfa_path, class: 'nav-item nav-link' %>
+        <%= link_to t(".sessions"), my_sessions_path, class: 'nav-item nav-link' %>
         <%= button_to t(".logout"), session_path, method: :delete, class: 'nav-item nav-link' %>
       </div>
     </div>
app/views/my/clients/index.html.erb
@@ -1,7 +1,7 @@
 <div class="container">
   <div class="row">
     <div class="col">
-      <h1>Dashboard</h1>
+      <h1><%= t('.title') %></h1>
       <%= link_to t(".new"), new_my_client_path, class: 'btn' %>
       <table class="table">
         <thead>
app/views/my/sessions/index.html.erb
@@ -0,0 +1,19 @@
+<div class="container">
+  <div class="row">
+    <div class="col">
+      <h1><%= t('.title') %></h1>
+      <table class="table">
+        <thead>
+          <th>User Agent</th>
+        </thead>
+        <tbody>
+        <% @sessions.each do |user_session| %>
+          <tr>
+            <td><%= user_session.user_agent %></td>
+          </tr>
+        <% end %>
+        </tbody>
+      </table>
+    </div>
+  </div>
+</div>
config/locales/en.yml
@@ -27,6 +27,7 @@ en:
     clients:
       index:
         new: New
+        title: OAuth Clients
       new:
         cancel: Cancel
         enable: Enable
config/routes.rb
@@ -19,6 +19,7 @@ Rails.application.routes.draw do
     resource :dashboard, only: [:show]
     resource :mfa, only: [:show, :new, :edit, :create, :destroy]
     resources :clients, only: [:index, :new, :create]
+    resources :sessions, only: [:index]
   end
 
   namespace :scim do
spec/requests/my/sessions_spec.rb
@@ -0,0 +1,17 @@
+require 'rails_helper'
+
+RSpec.describe "/my/sessions" do
+  describe "when logged in" do
+    let(:current_user) { create(:user) }
+
+    before { http_login(current_user) }
+
+    describe "GET /my/sessions" do
+      let!(:active_session) { create(:user_session, user: current_user) }
+
+      before { get '/my/sessions' }
+
+      specify { expect(response.body).to include(active_session.user_agent) }
+    end
+  end
+end