Skip to content

Commit

Permalink
Set activerecord default timezone globally in rails application confi…
Browse files Browse the repository at this point in the history
…g (not oracle initializer)

Set default sort order for EdiErrorReport query and display run date for correct sorting
Fix datatable script to match new date format
  • Loading branch information
jgreben committed Sep 14, 2018
1 parent bb2bcd3 commit ced4dcc
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 44 deletions.
23 changes: 2 additions & 21 deletions app/assets/javascripts/edi_error_reports.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
jQuery(document).ready(function($) {
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
var ukDatea = a.split('/');
var yearWithoutTime = ukDatea[2].split(' ')[0];
return (yearWithoutTime + ukDatea[1] + ukDatea[0]) * 1;
},
"date-uk-asc": function ( a, b ) {
console.log("asc");
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-uk-desc": function ( a, b ) {
console.log("desc");
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );

$(document).ready(function() {
$('table').DataTable({
"order": [[ 0, "desc" ]],
columnDefs: [
{ type: 'date-uk', targets: 0 } // define 'run' column as date
]
"order": [[ 0, "desc" ]]
});

$('input#edi_errors_day').on('change', function() {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/edi_error_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EdiErrorReportsController < ApplicationController
has_scope :type

def index
@edi_error_report = apply_scopes(EdiErrorReport).all
@edi_error_report = apply_scopes(EdiErrorReport.order(run: :desc)).all
rescue StandardError => e
flash[:error] = e.message
redirect_to edi_error_reports_path
Expand Down
6 changes: 3 additions & 3 deletions app/models/edi_error_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class EdiErrorReport < ActiveRecord::Base
# which rails uses to define the subclass of a model that should be loaded.
self.inheritance_column = 'inheritance_type'

scope :day, ->(day) { where(date_query, day.to_date) }
scope :level, ->(level) { where(err_lvl: level) }
scope :type, ->(type) { where(type: type) }
scope :day, ->(day) { where(date_query, day.to_date).order(run: :desc) }
scope :level, ->(level) { where(err_lvl: level).order(run: :desc) }
scope :type, ->(type) { where(type: type).order(run: :desc) }

self.table_name = 'edi_error_report'

Expand Down
2 changes: 1 addition & 1 deletion app/views/edi_error_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<tbody>
<% @edi_error_report.each do |eer| %>
<tr class='<%= cycle("odd", "even") %>'>
<td><%= eer.run.present? ? eer.run.strftime('%x %H:%M') : '' %></td>
<td><%= eer.run.present? ? eer.run.strftime('%Y-%m-%d %H:%M') : '' %></td>
<td><%= eer.type %></td>
<td><%= eer.error %></td>
<td><%= eer.err_lvl %></td>
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib)
config.sass.load_paths << File.expand_path('../../vendor/assets/stylesheets/')
config.time_zone = 'Pacific Time (US & Canada)'
config.active_record.default_timezone = :local
config.email_pattern = /(\A([\w\.%\+\-]+)@([\w\-]+\.)([\w]{2,}\s*)([;,\s]+([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,}))*\z)/i
end
end
3 changes: 0 additions & 3 deletions config/initializers/oracle.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Set time zone in TZ environment variable so that the same timezone will be used by Ruby and by Oracle session
ENV['TZ'] = 'PST'

# This is for the rails 4.2 version. See https://github.com/rsim/oracle-enhanced#rails-42
# When upgrading to rails 5 we can remove the deprecated self.emulate_* lines from config/initializers/oracle.rb
if Rails.env.development? || Rails.env.production?
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/endowed_funds_reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@
ckeys_file: 'endow123.txt' }

post :create, endowed_funds_report: params
expect(controller.date_start).to eq '2014-12-31'
expect(controller.date_end).to eq '2016-12-30'
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 '1998-12-21'
expect(controller.date_end).to eq '1999-12-21'
expect(controller.date_start).to eq '1998-12-22'
expect(controller.date_end).to eq '1999-12-22'
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/models/expenditure_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
expect(@report.send(:write_fy_end, '2011')).to eq('2011-AUG-25')
expect(@report.send(:check_fy)).to eq('2011-AUG-25')

expect(@report.send(:write_cal_start, '2011')).to eq('2010-12-31')
expect(@report.send(:write_cal_end, '2011')).to eq('2011-12-30')
expect(@report.send(:write_pd_start, '04-OCT-96')).to eq('1996-OCT-03')
expect(@report.send(:write_pd_end, '04-OCT-97')).to eq('1997-OCT-03')
expect(@report.send(:write_cal_start, '2011')).to eq('2011-01-01')
expect(@report.send(:write_cal_end, '2011')).to eq('2011-12-31')
expect(@report.send(:write_pd_start, '04-OCT-96')).to eq('1996-OCT-04')
expect(@report.send(:write_pd_end, '04-OCT-97')).to eq('1997-OCT-04')
end
it 'sets the attribute for fund_acct with a fund_begin value' do
@report.update_attributes(fund: nil)
Expand Down
8 changes: 4 additions & 4 deletions spec/models/expenditures_with_circ_stats_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
expect(@report.send(:write_fy_end, '2011')).to eq('2011-AUG-25')
expect(@report.send(:check_fy)).to eq('2011-AUG-25')

expect(@report.send(:write_cal_start, '2011')).to eq('2010-12-31')
expect(@report.send(:write_cal_end, '2011')).to eq('2011-12-30')
expect(@report.send(:write_pd_start, '04-OCT-96')).to eq('1996-OCT-03')
expect(@report.send(:write_pd_end, '04-OCT-97')).to eq('1997-OCT-03')
expect(@report.send(:write_cal_start, '2011')).to eq('2011-01-01')
expect(@report.send(:write_cal_end, '2011')).to eq('2011-12-31')
expect(@report.send(:write_pd_start, '04-OCT-96')).to eq('1996-OCT-04')
expect(@report.send(:write_pd_end, '04-OCT-97')).to eq('1997-OCT-04')
end
it 'sets the attribute for fund_acct with a fund_begin value' do
@report.update_attributes(fund: nil)
Expand Down
4 changes: 1 addition & 3 deletions spec/views/edi_error_reports/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
assert_select 'h1', text: 'EDIFACT invoice errors'.to_s
end
it 'should display an error line' do
assert_select 'td', text: '02/02/18 14:05'.to_s
assert_select 'td', text: /EDI_PROCESS_ORDER.do_inv_line_order:xcptn==stop_this_line ||===|| vendor==CASALI*/
assert_select 'td', text: /failed step==firm:verify_po on err==supplied PO# not in Unicorn:CAS6729454 edi_ckey:*/
assert_select 'td', text: '2018-02-02 14:05'.to_s
assert_select 'td', text: 'notify'.to_s
end
end
Expand Down

0 comments on commit ced4dcc

Please sign in to comment.