Skip to content

Commit

Permalink
Set up index page for sal3 batches
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Nov 15, 2016
1 parent e245cee commit daa9128
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class ApplicationController < ActionController::Base
redirect_to root_url
end

# https://github.com/ryanb/cancan/issues/835#issuecomment-18663815
before_action do
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end

def current_user
@current_user ||= begin
AuthorizedUser.find_by(user_id: user_id)
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/sal3_batch_requests_batches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Controller to handle the SAL3 Batch Requests landing page
class Sal3BatchRequestsBatchesController < ApplicationController
load_and_authorize_resource
def index
@sal3_batch_requests_batches = Sal3BatchRequestsBatch.all
end

def new
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.new
@current_user_name = current_user_name
end

def create
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.new(batch_params)
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.new(sal3_batch_requests_batch_params)
if @sal3_batch_requests_batch.save
array_of_item_ids = @sal3_batch_requests_batch.parse_bc_file
Sal3BatchRequestBcs.create_sal3_request(array_of_item_ids, bcs_params(@sal3_batch_requests_batch))
Expand All @@ -18,7 +23,7 @@ def create
end
end

def batch_params
def sal3_batch_requests_batch_params
params.require(:sal3_batch_requests_batch).permit!
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ul>
<li><%= link_to "Place batch request", new_sal3_batch_requests_batch_path %></li>
<% if can? :read, Sal3BatchRequestsBatch and can? :update, Sal3BatchRequestsBatch %>
<li><%= link_to "Review batches", root_path %></li>
<li><%= link_to "Review batches", sal3_batch_requests_batches_path %></li>
<% end %>
</ul>
</div>
Expand Down
23 changes: 23 additions & 0 deletions app/views/sal3_batch_requests_batches/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h2>SAL3 Batch Requests</h2>
<table class="table table-striped">
<thead>
<tr>
<th class='col-xs-1'>Batch</th>
<th class='col-xs-2'>Batch name</th>
<th class='col-xs-3'>User name</th>
<th class='col-xs-4'>User email</th>
<th class='col-xs-5'>Comments</th>
</tr>
</thead>
<tbody>
<% @sal3_batch_requests_batches.each do |batch| %>
<tr class='<%= cycle("odd", "even") %>'>
<td class='col-xs-1'><%= batch.batch_id %></td>
<td class='col-xs-2'><%= batch.batch_name %></td>
<td class='col-xs-3'><%= batch.user_name %></td>
<td class='col-xs-4'><%= batch.user_email %></td>
<td class='col-xs-5'><%= batch.comments %></td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
resources :uni_updates_batches, only: [:show, :destroy]
resources :withdraw_items, only: [:new, :create]
resources :transfer_items, only: [:new, :create]
resources :sal3_batch_requests_batches, only: [:new, :create]
resources :sal3_batch_requests_batches, only: [:index, :new, :create]
resources :encumbrance_reports, only: [:new, :create]
resources :expenditure_reports, only: [:new, :create]
resources :circulation_statistics_reports, only: [:new, :create]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
require 'rails_helper'

RSpec.describe Sal3BatchRequestsBatchesController, type: :controller do
describe 'get#index' do
it 'is successful returning the index page' do
stub_current_user(FactoryGirl.create(:authorized_user))
get 'index'
expect(response).to render_template('index')
end
end
describe 'get#new' do
it 'be succesful returning the index page' do
it 'be succesful returning the new page' do
stub_current_user(FactoryGirl.create(:authorized_user))
get 'new'
expect(response).to render_template('new')
Expand Down

0 comments on commit daa9128

Please sign in to comment.