Skip to content

Commit

Permalink
Make Sufia::Admin::StatsController a resourceful route
Browse files Browse the repository at this point in the history
* Moved it into the Sufia namespace
* Fixed view tests that weren't previously testing link href.
  • Loading branch information
jcoyne committed Aug 29, 2016
1 parent 85bfbb7 commit 97e9f2f
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 38 deletions.
3 changes: 0 additions & 3 deletions app/controllers/admin/stats_controller.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/controllers/concerns/sufia/admin/stats_behavior.rb
Expand Up @@ -6,14 +6,14 @@ module StatsBehavior
layout 'admin'
end

def index
def show
authorize! :read, Sufia::Statistics
stats_filters = params.fetch(:stats_filters, {})
limit = params.fetch(:limit, "5").to_i
@presenter = AdminStatsPresenter.new(stats_filters, limit)
add_breadcrumb 'Home', root_path
add_breadcrumb 'Repository Dashboard', sufia.admin_path
add_breadcrumb 'Statistics', sufia.stats_admin_path
add_breadcrumb 'Statistics', sufia.admin_stats_path
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/sufia/admin/stats_controller.rb
@@ -0,0 +1,5 @@
module Sufia
class Admin::StatsController < ApplicationController
include Sufia::Admin::StatsBehavior
end
end
7 changes: 0 additions & 7 deletions app/views/admin/stats/index.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/layouts/admin.html.erb
Expand Up @@ -28,7 +28,7 @@
<% end %>
<a href="#" class="x-navigation-control"></a>
</li>
<li><%= link_to sufia.stats_admin_path do %>
<li><%= link_to sufia.admin_stats_path do %>
<span class="fa fa-bar-chart"></span> Statistics
<% end %>
</li>
Expand Down
@@ -1,4 +1,4 @@
<%= form_for "stats_filters", url: sufia.stats_admin_path, method: "GET" do |f| %>
<%= form_for "stats_filters", url: sufia.admin_stats_path, method: "GET" do |f| %>
<%= f.label "Start *" %>
<input type="date" name="stats_filters[start_date]" value="<%= @presenter.stats_filters[:start_date] %>" placeholder="yyyy-mm-dd" ></input>
<%= f.label "end [defaults to now]" %>
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -2,7 +2,7 @@
<p>Statistics in this section are filtered by the dates entered in the form below.
The data is unfiltered unless the date form has been filled in. Start date is required and the default end is now.
</p>
<%= render "admin/stats/date_form" %>
<%= render "admin/stats/works" %>
<%= render "admin/stats/new_users" %>
<%= render "admin/stats/deposits" %>
<%= render "date_form" %>
<%= render "works" %>
<%= render "new_users" %>
<%= render "deposits" %>
@@ -1,9 +1,9 @@
<h2>Top File Formats and Users</h2>
<h3>Statistics in this section shows the top <%= @presenter.limit %> items for each category</h3>
<% if @presenter.limit == 5 %>
<p><%= link_to "View top 20", Sufia::Engine.routes.url_for(controller: "admin/stats", action:"index", limit: "20", only_path: true) %> </p>
<p><%= link_to "View top 20", sufia.admin_stats_path(limit: '20') %> </p>
<% else %>
<p><%= link_to "View top 5", Sufia::Engine.routes.url_for(controller: "admin/stats", action:"index", only_path: true) %> </p>
<p><%= link_to "View top 5", sufia.admin_stats_path %> </p>
<% end %>

<h3>Top File Formats (top <%= @presenter.top_formats.count %>)</h3>
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions app/views/sufia/admin/stats/show.html.erb
@@ -0,0 +1,7 @@
<div class="row">
<div class="col-sm-12">
<%= render "stats_by_date" %>
<hr/>
<%= render "top_data" %>
</div>
</div>
11 changes: 5 additions & 6 deletions config/routes.rb
Expand Up @@ -143,12 +143,11 @@
end
end

resource :admin, controller: 'sufia/admin', only: [:show] do
collection do
get 'stats' => 'admin/stats#index'
end
resources :features, only: [:index], controller: 'sufia/admin/features' do
resources :strategies, only: [:update, :destroy], controller: 'sufia/admin/strategies'
resource :admin, controller: 'sufia/admin', only: [:show]
scope 'admin', module: 'sufia/admin', as: 'admin' do
resource 'stats', only: [:show]
resources :features, only: [:index] do
resources :strategies, only: [:update, :destroy]
end
end

Expand Down
@@ -1,10 +1,10 @@
describe Admin::StatsController, type: :controller do
describe Sufia::Admin::StatsController, type: :controller do
let(:user) { create(:user) }

context "a non admin" do
describe "#index" do
describe "#show" do
it 'is unauthorized' do
get :index
get :show
expect(response).to be_redirect
end
end
Expand All @@ -15,14 +15,14 @@
allow(controller).to receive(:authorize!).and_return(true)
end

describe "#index" do
describe "#show" do
let(:expected_params) do
Rails.version < '5.0.0' ? {} : ActionController::Parameters.new
end

it 'allows an authorized user to view the page' do
expect(Sufia::AdminStatsPresenter).to receive(:new).with(expected_params, 5).and_call_original
get :index
get :show
expect(response).to be_success
expect(assigns[:presenter]).to be_kind_of Sufia::AdminStatsPresenter
end
Expand Down
2 changes: 1 addition & 1 deletion spec/routing/route_spec.rb
Expand Up @@ -36,7 +36,7 @@
expect(get: '/admin').to route_to(controller: 'sufia/admin', action: 'show')
end
it 'routes the statistics page' do
expect(get: '/admin/stats').to route_to(controller: 'admin/stats', action: 'index')
expect(get: '/admin/stats').to route_to(controller: 'sufia/admin/stats', action: 'show')
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/views/_toolbar.html.erb_spec.rb
Expand Up @@ -26,16 +26,16 @@

it 'shows the admin menu' do
render
expect(rendered).to have_link 'Admin', sufia.stats_admin_path
expect(rendered).to have_link 'Admin', href: sufia.admin_path
end
end

it 'has dashboard links' do
render
expect(rendered).to have_link 'My Dashboard', sufia.dashboard_index_path
expect(rendered).to have_link 'Transfers', sufia.transfers_path
expect(rendered).to have_link 'Highlights', sufia.dashboard_highlights_path
expect(rendered).to have_link 'Shares', sufia.dashboard_shares_path
expect(rendered).to have_link 'My Dashboard', href: sufia.dashboard_index_path
expect(rendered).to have_link 'Transfers', href: sufia.transfers_path
expect(rendered).to have_link 'Highlights', href: sufia.dashboard_highlights_path
expect(rendered).to have_link 'Shares', href: sufia.dashboard_shares_path
end

describe "New Work button" do
Expand Down
@@ -1,4 +1,4 @@
describe "admin/stats/index.html.erb", type: :view do
describe "sufia/admin/stats/show.html.erb", type: :view do
let(:presenter) do
Sufia::AdminStatsPresenter.new({}, 5)
end
Expand Down

0 comments on commit 97e9f2f

Please sign in to comment.