Skip to content

Commit

Permalink
update spec files
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Jan 13, 2019
1 parent 270355b commit 035212e
Show file tree
Hide file tree
Showing 353 changed files with 2,906 additions and 2,013 deletions.
70 changes: 70 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/ruby:2.5.3-node-browsers
environment:
PGHOST: 127.0.0.1
PGUSER: postgres

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/postgres:10
environment:
POSTGRES_USER: postgres
POSTGRES_DB: enju_inventory_dummy_test

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

# Database setup
- run:
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
- run: bundle exec rake app:sunspot:solr:start RAILS_ENV=test

# run tests!
- run:
name: run tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
$TEST_FILES
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
20 changes: 12 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ gemspec
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
gem "enju_seed", github: "next-l/enju_seed"
gem "enju_leaf", github: "next-l/enju_leaf"
gem "enju_biblio", github: "next-l/enju_biblio"
gem "enju_library", github: "next-l/enju_library"
gem "enju_manifestation_viewer", github: "next-l/enju_manifestation_viewer"
gem "codeclimate-test-reporter", group: :test, require: false
gem "jquery-rails"
gem "rails-controller-testing"
gem 'jquery-rails'
gem 'mobility'
gem 'enju_seed', github: 'next-l/enju_seed'
gem 'enju_leaf', github: 'next-l/enju_leaf'
gem 'enju_library', github: 'next-l/enju_library'
gem 'enju_biblio', github: 'next-l/enju_biblio'
gem 'enju_subject', github: 'next-l/enju_subject'
gem 'enju_circulation', github: 'next-l/enju_circulation'
gem 'enju_message', github: 'next-l/enju_message'
gem 'enju_event', github: 'next-l/enju_event'
gem 'rspec_junit_formatter'

# To use debugger
# gem 'debugger'
gem 'rails-controller-testing'
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
= EnjuInventory
{<img src="https://travis-ci.org/next-l/enju_inventory.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/next-l/enju_inventory]
{<img src="https://codeclimate.com/github/next-l/enju_inventory/badges/coverage.svg" />}[https://codeclimate.com/github/next-l/enju_inventory/coverage]
{<img src="https://coveralls.io/repos/next-l/enju_inventory/badge.svg?branch=master&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_inventory?branch=master]
{<img src="https://hakiri.io/github/next-l/enju_inventory/master.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_inventory/master]

This project rocks and uses MIT-LICENSE.

== 製作者・貢献者 (Authors and contributors)
* {TANABE, Kosuke}[https://github.com/nabeta] ({@nabeta}[https://twitter.com/nabeta])
* {Project Next-L}[http://www.next-l.jp] ({@ProjectNextL}[https://twitter.com/ProjectNextL])
* {Project Next-L}[https://www.next-l.jp] ({@ProjectNextL}[https://twitter.com/ProjectNextL])
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.pattern = FileList['spec/**/*_spec.rb']
end

task default: :spec
2 changes: 1 addition & 1 deletion app/controllers/concerns/enju_inventory/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module EnjuInventory
module Controller
extend ActiveSupport::Concern

def set_inventory_file
def get_inventory_file
@inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
end
end
Expand Down
15 changes: 13 additions & 2 deletions 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_file @inventory_file.attachment.download.path, filename: @inventory_file.attachment.metadata['filename'], type: 'application/octet-stream'
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 Expand Up @@ -96,6 +107,6 @@ def check_policy
end

def inventory_file_params
params.require(:inventory_file).permit(:attachment, :note)
params.require(:inventory_file).permit(:inventory, :note)
end
end
2 changes: 2 additions & 0 deletions app/models/concerns/enju_inventory/enju_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def self.inventory_items(inventory_file, mode = 'not_on_shelf')
when 'not_in_catalog'
Item.where(id: (inventory_item_ids - item_ids))
end
rescue
nil
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Inventory < ActiveRecord::Base
# Table name: inventories
#
# id :integer not null, primary key
# item_id :uuid
# item_id :integer
# inventory_file_id :integer
# note :text
# created_at :datetime not null
# updated_at :datetime not null
# created_at :datetime
# updated_at :datetime
#
53 changes: 36 additions & 17 deletions app/models/inventory_file.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
class InventoryFile < ActiveRecord::Base
include AttachmentUploader[:attachment]
has_many :inventories, dependent: :destroy
has_many :items, through: :inventories
belongs_to :user
validates :user, presence: true
validates :attachment, presence: true, on: :create
validates_presence_of :user

if ENV['ENJU_STORAGE'] == 's3'
has_attached_file :inventory, storage: :s3,
s3_credentials: {
access_key: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
s3_permissions: :private
else
has_attached_file :inventory,
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

paginates_per 10

def import
reload
file = File.open(attachment.download.path)
self.reload
file = File.open(self.inventory.path)
reader = file.read
reader.split.each do |row|
item = Item.where(item_identifier: row.to_s.strip).first
next unless item
items << item unless items.where(id: item.id).select('items.id').first
if item
unless self.items.where(id: item.id).select('items.id').first
self.items << item
end
end
end
file.close
true
Expand All @@ -26,14 +42,17 @@ def import
#
# Table name: inventory_files
#
# 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
# inventory_fingerprint :string
# attachment_data :jsonb
# id :integer not null, primary key
# filename :string
# content_type :string
# size :integer
# user_id :integer
# note :text
# created_at :datetime
# updated_at :datetime
# inventory_file_name :string
# inventory_content_type :string
# inventory_file_size :integer
# inventory_updated_at :datetime
# inventory_fingerprint :string
#
33 changes: 33 additions & 0 deletions app/views/inventories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div id="content_detail" class="ui-corner-all ui-widget-content">
<h1 class="title"><%= t('page.editing', :model => t('activerecord.models.inventory')) -%> </h1>
<div id="content_list">

<%= form_for(@inventory) do |f| -%>
<%= f.error_messages -%>

<div class="field">
<%= f.label :item_id -%><br />
<%= f.text_field :item_id -%>
</div>
<div class="field">
<%= f.label :inventory_file_id -%><br />
<%= f.text_field :inventory_file_id -%>
</div>
<div class="field">
<%= f.label :note -%><br />
<%= f.text_area :note -%>
</div>
<div class="actions">
<%= f.submit %>
</div>
<%- end -%>

</div>
</div>

<div id="submenu" class="ui-corner-all ui-widget-content">
<ul>
<li><%= link_to t('page.show'), @inventory -%></li>
<li><%= link_to t('page.back'), inventories_path -%></li>
</ul>
</div>
27 changes: 0 additions & 27 deletions app/views/inventories/edit.html.slim

This file was deleted.

34 changes: 34 additions & 0 deletions app/views/inventories/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div id="content_detail" class="ui-corner-all ui-widget-content">
<h1 class="title"><%= t('page.listing', :model => t('activerecord.models.inventory')) -%></h1>
<div id="content_list">

<table class="table table-striped index">
<tr>
<th><%= t('activerecord.models.inventory_file') -%> </th>
<th><%= t('activerecord.models.item') -%> </th>
<th></th>
</tr>

<%- @inventories.each do |inventory| -%>
<tr class="line<%= cycle("0", "1") -%>">
<td><%= link_to inventory.inventory_file_id, inventory.inventory_file -%></td>
<td><%= link_to inventory.item.item_identifier, inventory.item -%></td>
<td>
<%= link_to t('page.show'), inventory -%>
<%= link_to t('page.edit'), edit_inventory_path(inventory) -%>
<%= link_to t('page.destroy'), inventory, :data => {:confirm => t('page.are_you_sure')}, :method => :delete -%>
</td>
</tr>
<%- end -%>
</table>

<%= paginate(@inventories) -%>

</div>
</div>

<div id="submenu" class="ui-corner-all ui-widget-content">
<ul>
<li><%= link_to t('page.new', :model => t('activerecord.models.inventory')), new_inventory_path -%></li>
</ul>
</div>
29 changes: 0 additions & 29 deletions app/views/inventories/index.html.slim

This file was deleted.

Loading

0 comments on commit 035212e

Please sign in to comment.