Skip to content

Commit

Permalink
update dummy files
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Dec 29, 2019
1 parent b8e961a commit a150cbb
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 102 deletions.
13 changes: 12 additions & 1 deletion app/controllers/inventory_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@ def index
# GET /inventory_files/1
# GET /inventory_files/1.json
def show
if @inventory_file.inventory.path
unless ENV['ENJU_STORAGE'] == 's3'
file = @inventory_file.inventory.path
end
end

respond_to do |format|
format.html # show.html.erb
format.json { render json: @inventory_file }
format.download {
send_data @inventory_file.inventory.download, filename: @inventory_file.inventory.filename.to_s, type: @inventory_file.inventory.content_type, disposition: disposition
if ENV['ENJU_STORAGE'] == 's3'
send_data Faraday.get(@inventory_file.inventory.expiring_url).body.force_encoding('UTF-8'),
filename: File.basename(@inventory_file.inventory_file_name), type: 'application/octet-stream'
else
send_file file, filename: @inventory_file.inventory_file_name, type: 'application/octet-stream'
end
}
end
end
Expand Down
36 changes: 10 additions & 26 deletions app/models/inventory_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InventoryFile < ApplicationRecord
path: ":rails_root/private/system/:class/:attachment/:id_partition/:style/:filename"
end
validates_attachment_content_type :inventory, content_type: ['text/csv', 'text/plain', 'text/tab-separated-values']
validates_attachment_presence :inventory
validates_attachment_presence :inventory, on: :create

paginates_per 10

Expand All @@ -35,27 +35,8 @@ def import
end
end
end
end

def export(col_sep: "\t")
file = Tempfile.create do |f|
inventories.each do |inventory|
f.write inventory.to_hash.values.to_csv(col_sep)
end

f.rewind
f.read
end

file
end

def missing_items
Item.where(Inventory.where('items.id = inventories.item_id AND inventories.inventory_file_id = ?', id).exists.not)
end

def found_items
items
file.close
true
end

def missing_items
Expand All @@ -71,11 +52,14 @@ def found_items
#
# Table name: inventory_files
#
# id :bigint not null, primary key
# user_id :bigint
# id :integer not null, primary key
# filename :string
# content_type :string
# size :integer
# user_id :integer
# note :text
# created_at :datetime not null
# updated_at :datetime not null
# created_at :datetime
# updated_at :datetime
# inventory_file_name :string
# inventory_content_type :string
# inventory_file_size :integer
Expand Down
20 changes: 20 additions & 0 deletions app/views/inventory_files/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
<%= form_for(@inventory_file) do |f| -%>
<%= f.error_messages -%>

<div class="field">
<%= f.label :inventory_file_name -%> <br />
<%= f.text_field :inventory_file_name -%>
</div>
<div class="field">
<%= f.label :inventory_content_type -%> <br />
<%= f.text_field :inventory_content_type -%>
</div>
<div class="field">
<%= f.label :inventory_file_size -%> <br />
<%= f.text_field :inventory_file_size -%>
</div>
<div class="field">
<%= f.label :inventory_fingerprint -%> <br />
<%= f.text_field :inventory_fingerprint -%>
</div>
<div class="field">
<%= f.label :user_id -%> <br />
<%= f.text_field :user_id -%>
</div>
<div class="field">
<%= f.label :note -%> <br />
<%= f.text_area :note -%>
Expand Down
3 changes: 1 addition & 2 deletions app/views/inventory_files/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
</tr>

<%- @inventory_files.each do |inventory_file| -%>
<% next unless inventory_file.inventory.attached? -%>
<tr class="line<%= cycle("0", "1") -%>">
<td>
<%= link_to inventory_file.inventory.filename, inventory_file -%>
<%= link_to inventory_file.inventory_file_name, inventory_file -%>
<br />
<%= inventory_file.created_at -%>
</td>
Expand Down
11 changes: 8 additions & 3 deletions app/views/inventory_files/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@

<p>
<strong><%= t('activerecord.attributes.inventory_file.inventory_file_name') -%> :</strong>
<%= @inventory_file.inventory.filename -%>
<%= @inventory_file.inventory_file_name -%>
</p>

<p>
<strong><%= t('activerecord.attributes.inventory_file.inventory_content_type') -%> :</strong>
<%= @inventory_file.inventory.content_type -%>
<%= @inventory_file.inventory_content_type -%>
</p>

<p>
<strong><%= t('activerecord.attributes.inventory_file.inventory_file_size') -%> :</strong>
<%= @inventory_file.inventory.byte_size -%>
<%= @inventory_file.inventory_file_size -%>
</p>

<p>
<strong><%= t('activerecord.attributes.inventory_file.inventory_fingerprint') -%> :</strong>
<%= @inventory_file.inventory_fingerprint -%>
</p>

<p>
Expand Down
19 changes: 8 additions & 11 deletions spec/controllers/inventory_files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,33 @@
login_fixture_admin

it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: inventory_files(:inventory_file_00001) }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(inventory_files(:inventory_file_00001).id))
expect(response).to be_successful
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end

describe "When logged in as Librarian" do
login_fixture_librarian

it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: inventory_files(:inventory_file_00001) }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(inventory_files(:inventory_file_00001).id))
expect(response).to be_successful
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end

describe "When logged in as User" do
login_fixture_user

it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: inventory_files(:inventory_file_00001) }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(inventory_files(:inventory_file_00001).id))
expect(response).to be_forbidden
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
end
end

describe "When not logged in" do
it "assigns the requested inventory_file as @inventory_file" do
get :show, params: { id: inventory_files(:inventory_file_00001) }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(inventory_files(:inventory_file_00001).id))
get :show, params: { id: 1 }
expect(assigns(:inventory_file)).to eq(InventoryFile.find(1))
expect(response).to redirect_to(new_user_session_url)
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
include EnjuLibrary::Controller
include EnjuInventory::Controller
after_action :verify_authorized
before_action :set_paper_trail_whodunnit

include Pundit
end
4 changes: 2 additions & 2 deletions spec/dummy/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
devise :database_authenticatable, # :registerable,
:recoverable, :rememberable, # :validatable
devise :database_authenticatable, #:registerable,
:recoverable, :rememberable, :trackable, # , :validatable
:lockable, lock_strategy: :none, unlock_strategy: :none

include EnjuSeed::EnjuUser
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 3 additions & 1 deletion spec/dummy/bin/setup
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
Expand All @@ -20,6 +21,7 @@ chdir APP_ROOT do
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')


# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
Expand Down
6 changes: 2 additions & 4 deletions spec/dummy/bin/update
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
Expand All @@ -17,9 +18,6 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

# Install JavaScript dependencies if using Yarn
# system('bin/yarn')

puts "\n== Updating database =="
system! 'bin/rails db:migrate'

Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/bin/yarn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg", *ARGV
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.load_defaults 5.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
11 changes: 2 additions & 9 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@
config.consider_all_requests_local = true

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true

config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
}
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
end

# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

Expand All @@ -41,9 +37,6 @@
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
Expand Down
11 changes: 4 additions & 7 deletions spec/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
Expand All @@ -38,9 +39,6 @@
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local

# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
Expand All @@ -62,7 +60,6 @@
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "dummy_#{Rails.env}"

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
8 changes: 1 addition & 7 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}

# Show full error reports and disable caching.
Expand All @@ -27,10 +27,6 @@

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Store uploaded files on the local file system in a temporary directory
config.active_storage.service = :test

config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
Expand All @@ -43,6 +39,4 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = {host: 'localhost:3000'}
config.active_job.queue_adapter = :inline
end
2 changes: 1 addition & 1 deletion spec/dummy/config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('../../', 'node_modules')
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
Expand Down

0 comments on commit a150cbb

Please sign in to comment.