Skip to content

Commit

Permalink
Merge branch 'master' into rubocop-happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Feb 20, 2018
2 parents 99d912d + 7c929e6 commit 6f2c68b
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Metrics/MethodLength:
Metrics/AbcSize:
Max: 27

Style/PercentLiteralDelimiters:
Enabled: false

Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sudo: false
rvm:
- 2.3.4
bundler_args: --without production
before_script:
- mkdir -p tmp/Dataload/EndowRpt
script:
- bundle exec rake db:test:prepare
- bundle exec rake spec
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ group :development, :test do
gem 'rspec-rails', '~> 3.0'

# Rubocop is a static code analyzer to enforce style.
gem 'rubocop', require: false
gem 'rubocop'

# scss-lint will test the scss files to enforce styles
gem 'scss_lint', require: false
Expand Down
45 changes: 30 additions & 15 deletions app/controllers/endowed_funds_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class EndowedFundsReportsController < ApplicationController
include SymphonyCgi
before_action :set_no_cache

after_action only: :create do
submit_endow_funds(batch_params)
end
Expand All @@ -20,7 +21,6 @@ def new
def create
@endowed_funds_report = EndowedFundsReport.new(batch_params)
if @endowed_funds_report.valid?
keys = catalog_keys
# write keys to file to Symphony mount [/symphony] on libsys-webforms-dev
if keys.any?
@endowed_funds_report.write_keys(keys)
Expand All @@ -36,35 +36,50 @@ def create
end
end

def catalog_keys
if @endowed_funds_report.fund
catalog_keys = EndowedFundsReport.ol_cat_key_fund(@endowed_funds_report.fund, date_start, date_end)
elsif @endowed_funds_report.fund_begin
catalog_keys = EndowedFundsReport.ol_cat_key_fund_begin(@endowed_funds_report.fund_begin, date_start, date_end)
def keys
if !@endowed_funds_report.fund.nil?
@endowed_funds_report.fiscal_years.any? ? funds_fy : funds_keys
elsif !@endowed_funds_report.fund_begin.nil?
@endowed_funds_report.fiscal_years.any? ? funds_fy_begin : funds_keys_begin
end
catalog_keys
end

def funds_keys
EndowedFundsReport.ol_cat_key_fund(@endowed_funds_report.fund, date_start, date_end)
end

def funds_fy
EndowedFundsReport.ol_cat_key_fy(@endowed_funds_report.fund, date_start, date_end)
end

def funds_keys_begin
EndowedFundsReport.ol_cat_key_fund_begin(@endowed_funds_report.fund, date_start, date_end)
end

def funds_fy_begin
EndowedFundsReport.ol_cat_key_fy_begin(@endowed_funds_report.fund, date_start, date_end)
end

def date_start
if @endowed_funds_report.fiscal_years.any?
start_date = Time.zone.parse("#{@endowed_funds_report.fiscal_years[0]}-09-01") - 1.year
start_date = @endowed_funds_report.fiscal_years[0]
elsif @endowed_funds_report.calendar_years.any?
start_date = Time.zone.parse("#{@endowed_funds_report.calendar_years[0]}-01-01")
start_date = Time.zone.parse("#{@endowed_funds_report.calendar_years[0]}-01-01").strftime('%Y-%m-%d')
elsif @endowed_funds_report.paid_years.any?
start_date = Time.zone.parse(@endowed_funds_report.paid_years[0].to_s)
start_date = Time.zone.parse(@endowed_funds_report.paid_years[0].to_s).strftime('%Y-%m-%d')
end
start_date.strftime('%Y-%m-%d')
start_date
end

def date_end
if @endowed_funds_report.fiscal_years.any?
end_date = Time.zone.parse("#{@endowed_funds_report.fiscal_years[1]}-08-31")
end_date = @endowed_funds_report.fiscal_years[1]
elsif @endowed_funds_report.calendar_years.any?
end_date = Time.zone.parse("#{@endowed_funds_report.calendar_years[1]}-12-31")
end_date = Time.zone.parse("#{@endowed_funds_report.calendar_years[1]}-12-31").strftime('%Y-%m-%d')
elsif @endowed_funds_report.paid_years.any?
end_date = Time.zone.parse(@endowed_funds_report.paid_years[1].to_s)
end_date = Time.zone.parse(@endowed_funds_report.paid_years[1].to_s).strftime('%Y-%m-%d')
end
end_date.strftime('%Y-%m-%d')
end_date
end

def batch_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/sal3_batch_requests_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.locations
'Archive of Recorded Sound - Redwood City' => 'RA',
'Earth Sciences' => 'DE',
'Preservation - Book Repair' => 'BR',
'Green' => 'DS'
'Green Loading Dock' => 'DS'
}
end

Expand Down
3 changes: 1 addition & 2 deletions config/settings/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ symphony_env: '/s/SUL/Config/sirsi.env'
symphony_host: 'morison.stanford.edu'
symphony_cgi_url: 'http://morison.stanford.edu/cgi-bin/webforms'
symphony_catalogdump: '/s/sirsi/Unicorn/Bin/catalogdump -om -kc -h -z -j -n dumpjunktag.Bibframe 2>/dev/null'
symphony_dataload_endowrpt: '/symphony/Dataload/EndowRpt'
# Note: the dumpjunktag.Bibframe file is located on the Symphony server under /s/sirsi/Unicorn/Custom/.
# It contains the tag listing '001' which instructs the catalogdump to remove all '001' fields of
# the MARC record. The -kc flag then adds back in an '001' field with the ckey as the value
Expand All @@ -17,7 +18,6 @@ pl_sql_jobs:
- 'jgreben'
- 'dlrueda'
- 'sdoljack'
- 'mahmed'
delphi_pay_test_job:
text: 'Delphi payment test run'
confirm: 'Delphi payment test run started'
Expand All @@ -26,4 +26,3 @@ pl_sql_jobs:
- 'jgreben'
- 'dlrueda'
- 'sdoljack'
- 'mahmed'
4 changes: 2 additions & 2 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
symphony_cgi_url: 'https://morison.stanford.edu/cgi-bin/webforms/'
symphony_cgi_url: 'https://example.com'
symphony_dataload_endowrpt: 'tmp/Dataload/EndowRpt'
# PL/SQL jobs
pl_sql_jobs:
circ_stats_job:
Expand All @@ -21,4 +22,3 @@ pl_sql_jobs:
- 'dlrueda'
- 'sdoljack'
- 'mahmed'

92 changes: 55 additions & 37 deletions spec/controllers/endowed_funds_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,70 @@
end
end

describe 'post#create' do
xit 'redirects to root_url if create is successful' do
post :create, endowed_funds_report: { fund: ['1000501-1-AACIZ'], fund_begin: nil }
expect(response).to redirect_to root_path
end
describe 'post#create gets a set of catalog keys' do
before { allow(controller).to receive(:keys).and_return(%w[123 456 789]) }

it 'renders the new template if create is unsuccessful' do
post :create, endowed_funds_report: { fund: nil, fund_begin: nil }
expect(response).to render_template('new')
end
xit 'gets a set of catalog keys' do
post :create, endowed_funds_report: { fund: nil, fund_begin: ['1000501-1-AACIZ'] }
it 'redirects to root_url if create returns and writes ckeys and is successful' do
params = { fund: ['1065032-101-KARJZ'], email: 'some@one.com',
pd_start: '03-OCT-96', pd_end: '30-NOV-96', report_format: 'n',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(response).to redirect_to root_path
end
xit 'creates the cgi params for a get request to symphony using fund string and fy' do
post :create, endowed_funds_report: { fund: ['1000501-1-AACIZ', '1000502-1-AACIX'],
fund_begin: nil, report_format: 'n',
email: 'some@one.com', fy_start: 'FY 2015' }
expect(response).to have_http_status(302)
expect(:fund).to be_present
expect(:fy_end).to be_present
it 'creates the params for a symphony request using several fund strings and fiscal year dates' do
params = { fund: ['1000501-1-AACIZ', '1000502-1-AACIX'], fund_begin: nil,
report_format: 'n', email: 'some@one.com', fy_start: 'FY 2015',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(EndowedFundsReport.new(params)).to have_attributes(fy_start: 'FY 2015')
end
xit 'creates the cgi params for a get request to symphony using fund_begins string and cal' do
post :create, endowed_funds_report: { fund: nil, fund_begin: '1000501-1-AACIZ-',
report_format: 'n', email: 'some@one.com',
cal_start: '2015' }
expect(response).to have_http_status(302)
expect(:fund_begin).to be_present
expect(:cal_end).to be_present
it 'creates the params for a symphony request using fund_begin string and calendar dates' do
params = { fund: nil, fund_begin: '1000501-1-AACIZ-', report_format: 'n',
email: 'some@one.com', cal_start: '2015', cal_end: '2016',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(controller.date_start).to eq '2015-01-01'
expect(controller.date_end).to eq '2016-12-31'
end
it 'creates the params for a symphony request using fund_begin string and paid dates' do
params = { fund: nil, fund_begin: '1000501-1-AACIZ-', report_format: 'n',
email: 'some@one.com', pd_start: '22-DEC-98', pd_end: '22-DEC-99',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(controller.date_start).to eq '0098-12-22'
expect(controller.date_end).to eq '0099-12-22'
end
xit 'creates the cgi params for a get request to symphony using fund_egins string and pd' do
post :create, endowed_funds_report: { fund: nil, fund_begin: '1000501-1-AACIZ-',
report_format: 'n', email: 'some@one.com',
pd_start: '22-DEC-99' }
expect(response).to have_http_status(302)
expect(:fund_begin).to be_present
expect(:pd_end).to be_present
end

describe 'rescue_from RecordNotFound' do
before { allow(controller).to receive(:funds_keys).and_raise(ActiveRecord::RecordNotFound) }
it 'renders the correct template' do
params = { fund: ['1065032-101-KARJZ'], email: 'some@one.com',
pd_start: '03-OCT-96', pd_end: '30-NOV-96', report_format: 'n',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(response).to render_template('new')
end
xit 'sets the date_start for filtering report sql qury by date' do
post :create, endowed_funds_report: { fund: ['1000501-1-AACIZ', '1000502-1-AACIX'],
fund_begin: nil, report_format: 'n',
email: 'some@one.com', fy_start: 'FY 2015',
fy_end: 'FY 2016' }
expect(:date_start).to be_present
expect(:date_start).to equal('2015-07-01')
expect(:date_end).to be_present
expect(:date_end).to equal('2016-06-30')
end

describe 'no ckeys found for query' do
before { allow(controller).to receive(:keys).and_return([]) }
it 'renders the correct template' do
params = { fund: ['1065032-101-KARJZ'], email: 'some@one.com',
pd_start: '03-OCT-96', pd_end: '30-NOV-96', report_format: 'n',
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(response).to render_template('new')
end
end
end
46 changes: 26 additions & 20 deletions spec/models/endowed_funds_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
require 'rails_helper'

RSpec.describe EndowedFundsReport, type: :model do
before do
@endow_funds = FactoryGirl.create(:expenditures)
end
describe 'querying from expenditures' do
subject { EndowedFundsReport.ol_cat_key_fund(@endow_funds.ta_fund_code, '2015-07-01', '2016-06-30') }
let(:ckeys) { class_double('EndowedFundsReport') }
it 'should retrieve a set of catalog keys' do
begin
expect(@endow_funds.ol_cat_key).to eq('1234567')
expect(subject).to be_kind_of(Array)
rescue ActiveRecord::StatementInvalid
end
allow(ckeys).to receive(:ol_cat_key_fund)
.with(['1000501-1-AACIZ', '1000502-1-AACIX'], '2015-07-01', '2016-06-30')
.and_return(%w[123 456 789])

subject = ckeys.ol_cat_key_fund(['1000501-1-AACIZ', '1000502-1-AACIX'], '2015-07-01', '2016-06-30')
expect(subject).to be_kind_of(Array)
expect(subject.size).to be 3
end
subject { EndowedFundsReport.ol_cat_key_fund_begin('All SUL Funds', '2015-07-01', '2016-06-30') }
it 'should handle the All SUL Funds selection' do
begin
expect(subject).to be_kind_of(Array)
rescue ActiveRecord::StatementInvalid
end
allow(ckeys).to receive(:ol_cat_key_fund)
.with('All SUL Funds', '2015-07-01', '2016-06-30')
.and_return(%w[456 789 101 112 131 415])

subject = ckeys.ol_cat_key_fund('All SUL Funds', '2015-07-01', '2016-06-30')
expect(subject).to be_kind_of(Array)
expect(subject.size).to be 6
end
subject { EndowedFundsReport.ol_cat_key_fund(['1000501-1-AACIZ', '1008930-1-HAGOY'], '2015-07-01', '2016-06-30') }
it 'should initialize a container of fund codes' do
begin
expect(subject).to be_kind_of(Array)
rescue ActiveRecord::StatementInvalid
end
it 'should retrieve a set of catalog keys' do
allow(ckeys).to receive(:ol_cat_key_fund)
.with('1065032-101-NAANF-', '2012-09-01', '2013-08-31')
.and_return(%w[101 112 131 415])

subject = ckeys.ol_cat_key_fund('1065032-101-NAANF-', '2012-09-01', '2013-08-31')
expect(subject).to be_kind_of(Array)
expect(subject.size).to be 4
end
end

describe 'fiscal_years' do
report = EndowedFundsReport.new(fy_start: 'FY 2010', fy_end: 'FY2011')
it 'should strip off the FY and include the year strings in the array' do
Expand All @@ -38,6 +42,7 @@
expect(report.paid_years.any?).to be_falsey
end
end

describe 'calendar_years' do
report = EndowedFundsReport.new(cal_start: '2010', cal_end: '2011')
it 'should include the year strings in the array' do
Expand All @@ -47,6 +52,7 @@
expect(report.paid_years.any?).to be_falsey
end
end

describe 'paid_years' do
report = EndowedFundsReport.new(pd_start: '11-DEC-16', pd_end: '20-JAN-16')
it 'should include the dates in the array' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/sal3_batch_requests_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'Archive of Recorded Sound - Redwood City' => 'RA',
'Earth Sciences' => 'DE',
'Preservation - Book Repair' => 'BR',
'Green' => 'DS')
'Green Loading Dock' => 'DS')
end
it 'Defines a batch_media hash' do
expect(Sal3BatchRequestsBatch.batch_media).to include(book: %w[BOOK Book], unknown: %w[UNKNOWN Unknown])
Expand Down

0 comments on commit 6f2c68b

Please sign in to comment.