Skip to content

Commit

Permalink
Merge 38e4028 into b5adcd2
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Aug 10, 2018
2 parents b5adcd2 + 38e4028 commit f4d1960
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ bundler_args: --without production
before_script:
- mkdir -p tmp/Dataload/EndowRpt
- mkdir -p tmp/Dataload/BookplateMerge/Batches/Queue
- sudo mkdir -p /symphony/sal3_batch_requests_batch/bc_file
- sudo chmod -R a+w /symphony
script:
- bundle exec rake db:test:prepare
- bundle exec rake db:seed
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ gem 'nokogiri'
gem 'systemu'
# For exception reporting
gem 'honeybadger'
# For uploading files from Ruby applications
gem 'carrierwave', '~> 1.0'

gem 'uglifier'
# For fiscal year functions
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
carrierwave (1.2.3)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
composite_primary_keys (8.1.4)
activerecord (~> 4.2.0)
concurrent-ruby (1.0.5)
Expand Down Expand Up @@ -167,6 +171,9 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
Expand Down Expand Up @@ -317,6 +324,7 @@ DEPENDENCIES
capistrano-passenger
capistrano-rails
capybara
carrierwave (~> 1.0)
composite_primary_keys (= 8.1.4)
config
coveralls
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/expenditure_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ExpenditureReportsController < ApplicationController
before_action :set_no_cache

rescue_from ActiveRecord::RecordNotFound do |exception|
rescue_from ActiveRecord::RecordNotFound do
flash[:error] = 'There are no records for the specified date range'
render action: 'new'
end
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/sal3_batch_requests_batches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def new
end

def create
file_obj = sal3_batch_requests_batch_params[:bc_file_obj]
sal3_batch_requests_batch_params[:bc_file] = file_obj.path unless file_obj.nil?
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.new(sal3_batch_requests_batch_params)
@sal3_batch_requests_batch.bc_file = sal3_batch_requests_batch_params[:bc_file]
if @sal3_batch_requests_batch.save
array_of_item_ids = @sal3_batch_requests_batch.parse_bc_file
begin
Expand Down Expand Up @@ -58,8 +57,8 @@ def update
def download
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.find(params[:id])
begin
send_file @sal3_batch_requests_batch[:bc_file], type: 'text/plain', disposition: 'attachment'
rescue TypeError
send_file @sal3_batch_requests_batch.bc_file.current_path, type: 'text/plain', disposition: 'attachment'
rescue StandardError
flash[:warning] = 'No barcode file exists for this batch.'
redirect_to root_path
end
Expand Down
11 changes: 8 additions & 3 deletions app/models/sal3_batch_requests_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
###
class Sal3BatchRequestsBatch < ActiveRecord::Base
include FileParser
attr_accessor :bc_file_obj

validates :bc_file_obj, presence: { message: 'You must upload a file of barcodes' }, on: :create
validates :bc_file, presence: { message: 'You must upload a file of barcodes' }, on: :create
validates :batch_numpullperday, numericality: { message: 'You must enter the number of items to pull per day' },
on: :update
validates :batch_startdate, presence: { message: 'You must enter a start date' },
Expand Down Expand Up @@ -37,6 +36,8 @@ class Sal3BatchRequestsBatch < ActiveRecord::Base
self.table_name = 'sal3_batch_requests_batch'
self.primary_key = 'batch_id'

mount_uploader :bc_file, BarcodeFileUploader

def self.locations
{
'Data Control' => 'DC',
Expand Down Expand Up @@ -87,8 +88,12 @@ def self.priority
%w[1 2 3]
end

def uploader
BarcodeFileUploader.new(self, 'bc_file')
end

def set_num_bcs
file_obj = bc_file_obj.path unless bc_file_obj.nil?
file_obj = bc_file.current_path
barcodes = IO.read(file_obj).split("\n").uniq.length
update_attributes(num_bcs: barcodes)
end
Expand Down
48 changes: 48 additions & 0 deletions app/uploaders/barcode_file_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Class provided by CarrierWave to set storage details
class BarcodeFileUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick

# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"/symphony/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
# version :thumb do
# process resize_to_fit: [50, 50]
# end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_whitelist
# %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
5 changes: 2 additions & 3 deletions app/views/sal3_batch_requests_batches/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
</div>
</div>
<div class='form-group row'>
<%= f.label :bc_file_obj, 'Upload barcode file', class: 'col-sm-2 form-control-label' %>
<%= f.label :bc_file, 'Upload barcode file', class: 'col-sm-2 form-control-label' %>
<div class='col-sm-10'>
<%= f.file_field 'bc_file_obj', class: 'form-control-file' %>
<%= f.file_field 'bc_file', class: 'form-control-file' %>
<span class='small'>Plain text file. Use Notepad or TextWrangler. One barcode per line. No punctuation.</span>
</div>
</div>
Expand All @@ -146,7 +146,6 @@
<%= f.hidden_field :ckey, value: '' %>
<%= f.hidden_field :priority, value: 3 %>
<%= f.hidden_field :status, value: 'NEW' %>
<%= f.hidden_field :bc_file, value: '' %>
<%= f.hidden_field :num_nonsymph_bcs, value: '' %>
<%= f.hidden_field :num_retrieval_err, value: '' %>
<%= f.hidden_field :pending, value: 'Y' %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveBcFileObFromSal3BatchRequestBatch < ActiveRecord::Migration
def change
remove_column :sal3_batch_requests_batch, :bc_file_obj, :string
end
end
8 changes: 4 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180725220246) do
ActiveRecord::Schema.define(version: 20180808230015) do

create_table "authorized_user", force: :cascade do |t|
t.string "user_id"
Expand Down Expand Up @@ -159,8 +159,9 @@
t.integer "edi_lin_num"
t.integer "edi_sublin_count"
t.string "vend_unique_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "barcode_num", limit: 6
end

create_table "edi_sumrz_bib", force: :cascade do |t|
Expand Down Expand Up @@ -354,7 +355,6 @@
t.datetime "last_action_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "bc_file_obj"
end

create_table "sal3_batch_requests_bcs", force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion lib/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def parse_uploaded_file
end

def parse_bc_file
bc_file_obj.read.split("\n")
bc_file.read.split("\n")
end
end
2 changes: 1 addition & 1 deletion spec/controllers/sal3_batch_request_bcs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
describe 'get#show' do
it 'is successful returning a show page' do
stub_current_user(FactoryBot.create(:authorized_user))
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file_obj: barcode_file,
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file: barcode_file,
pseudo_id: 'MAPSCANLAB',
batch_pullmon: 1,
batch_startdate: '11-APR-18',
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/sal3_batch_requests_batch_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
describe 'get#show' do
it 'is successful returning a show page' do
stub_current_user(FactoryBot.create(:authorized_user))
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file_obj: barcode_file,
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file: barcode_file,
batch_pullmon: 1,
pseudo_id: 'MAPSCANLAB',
batch_startdate: '11-APR-18',
Expand All @@ -41,7 +41,7 @@
batch_needbydate: '16-06-30',
batch_pullmon: 1,
last_action_date: nil,
bc_file_obj: barcode_file }
bc_file: barcode_file }

expect(response).to have_http_status(302)
end
Expand All @@ -53,7 +53,7 @@
end
describe 'get#edit' do
it 'is successful returning the edit view' do
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file_obj: barcode_file,
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file: barcode_file,
batch_pullmon: 1,
pseudo_id: 'MAPSCANLAB',
batch_startdate: '11-APR-18',
Expand All @@ -65,7 +65,7 @@
end
describe 'put#update' do
before :each do
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file_obj: barcode_file,
@sal3_batch_requests_batch = Sal3BatchRequestsBatch.create!(bc_file: barcode_file,
pseudo_id: 'MAPSCANLAB',
priority: 2,
batch_numpullperday: 10,
Expand Down
3 changes: 1 addition & 2 deletions spec/factories/sal3_batch_requests_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
pseudo_id 'MAPSCANLAB'
comments 'Test comment'
ckey '1234567'
bc_file_obj { fixture_file_upload(Rails.root.to_s + '/spec/fixtures/files/test_file.txt', 'text/plain') }
bc_file 'spec/fixtures/files/test_file.txt'
bc_file { Rack::Test::UploadedFile.new(Rails.root.join('spec/fixtures/files/test_file.txt')) }
num_bcs ''
num_nonsymph_bcs ''
pending ''
Expand Down
5 changes: 5 additions & 0 deletions spec/models/sal3_batch_requests_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@
expect(request).to_not be_valid
expect(request.errors.full_messages).to include('Please pick at least one day for items to be delivered.')
end
it 'Has an uploader mount' do
obj = Sal3BatchRequestsBatch.new
expect(obj.uploader.instance_variable_get(:@mounted_as)).to eq 'bc_file'
expect(obj.uploader.instance_variable_get(:@model).class.to_s.underscore).to eq 'sal3_batch_requests_batch'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
batch_needbydate: '16-06-20',
batch_pullmon: 1,
last_action_date: nil,
bc_file_obj: barcode_file
bc_file: barcode_file
))
end

Expand Down

0 comments on commit f4d1960

Please sign in to comment.