Skip to content

Commit

Permalink
update factory files
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Jul 6, 2018
1 parent eebb3e9 commit f93f8c2
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/models/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Checkout < ActiveRecord::Base
belongs_to :user
delegate :username, :user_number, to: :user, prefix: true
belongs_to :item, touch: true
belongs_to :checkin
belongs_to :checkin, optional: true
belongs_to :librarian, class_name: 'User'
belongs_to :basket
belongs_to :shelf
Expand Down
6 changes: 3 additions & 3 deletions app/models/reserve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Reserve < ActiveRecord::Base
scope :not_sent_cancel_notice_to_library, -> {in_state(:canceled).where(expiration_notice_to_library: false)}
belongs_to :user
belongs_to :manifestation, touch: true
belongs_to :librarian, class_name: 'User'
belongs_to :item, touch: true
belongs_to :librarian, class_name: 'User', optional: true
belongs_to :item, touch: true, optional: true
belongs_to :request_status_type
belongs_to :pickup_location, class_name: 'Library'
belongs_to :pickup_location, class_name: 'Library', optional: true

validates_associated :user, :librarian, :request_status_type
validates :manifestation, associated: true # , on: :create
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
22 changes: 5 additions & 17 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
require File.expand_path('../boot', __FILE__)
require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)
require 'enju_circulation'
require 'enju_leaf'
require 'globalize'
require 'globalize-accessors'
require 'resque/server'
require "enju_circulation"

module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Do not swallow errors in after_commit/after_rollback callbacks.
# config.active_record.raise_in_transactional_callbacks = true
end
end

9 changes: 9 additions & 0 deletions spec/dummy/config/cable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
development:
adapter: async

test:
adapter: async

production:
adapter: redis
url: redis://localhost:6379/1
47 changes: 47 additions & 0 deletions spec/dummy/config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch('PORT') { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch('RAILS_ENV') { 'development' }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!

# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
6 changes: 6 additions & 0 deletions spec/dummy/config/spring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%w(
.ruby-version
.rbenv-vars
tmp/restart.txt
tmp/caching-dev.txt
).each { |path| Spring.watch(path) }
7 changes: 4 additions & 3 deletions spec/factories/manifestation_checkout_stat.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :manifestation_checkout_stat do |f|
f.start_date 1.week.ago
f.end_date 1.day.ago
factory :manifestation_checkout_stat do
start_date 1.week.ago
end_date 1.day.ago
association :user, factory: :librarian
end
end
7 changes: 4 additions & 3 deletions spec/factories/manifestation_reserve_stat.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :manifestation_reserve_stat do |f|
f.start_date 1.week.ago
f.end_date 1.day.ago
factory :manifestation_reserve_stat do
start_date 1.week.ago
end_date 1.day.ago
association :user, factory: :librarian
end
end
5 changes: 2 additions & 3 deletions spec/factories/reserve.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FactoryBot.define do
factory :reserve do |f|
factory :reserve do
before(:create) do |reserve|
profile = FactoryBot.create(:profile)
user = User.new(FactoryBot.attributes_for(:user))
user.profile = profile
reserve.user = user
end
f.manifestation_id{FactoryBot.create(:manifestation).id}
# f.user{FactoryBot.create(:user)}
manifestation_id{FactoryBot.create(:manifestation).id}
end
end
7 changes: 4 additions & 3 deletions spec/factories/user_checkout_stat.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :user_checkout_stat do |f|
f.start_date 1.week.ago
f.end_date 1.day.ago
factory :user_checkout_stat do
start_date 1.week.ago
end_date 1.day.ago
association :user, factory: :librarian
end
end
7 changes: 4 additions & 3 deletions spec/factories/user_reserve_stat.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :user_reserve_stat do |f|
f.start_date 1.week.ago
f.end_date 1.day.ago
factory :user_reserve_stat do
start_date 1.week.ago
end_date 1.day.ago
association :user, factory: :librarian
end
end
98 changes: 98 additions & 0 deletions spec/fixtures/content_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
content_type_00001:
id: 1
name: text
display_name: "en: text\r\n\
ja: 文字"
note:
position: 1
content_type_00002:
id: 2
name: performed_music
display_name: "en: Performed music\r\n\
ja: 音楽"
note: 曲の演奏など
position: 2
content_type_00003:
id: 3
name: two_dimensional_moving_image
display_name: "en: Two-dimensional moving image\r\n\
ja: 動画"
note:
position: 3
content_type_00004:
id: 4
name: tactile_text
display_name: "en: Tactile text\r\n\
ja: 点字など"
note: 触ることのできる文字
position: 4
content_type_00005:
id: 5
name: still_image
display_name: "en: Still image\r\n\
ja: 画像"
note: 静止画像
position: 5
content_type_00006:
id: 6
name: cartographic_image
display_name: "en: Cartographic image\r\n\
ja: 地図"
note:
position: 6
content_type_00007:
id: 7
name: spoken_word
display_name: "en: Spoken word\r\n\
ja: 音声"
note: 読み上げ音声など
position: 7
content_type_00008:
id: 8
name: sounds
display_name: "en: Sounds\r\n\
ja: 音"
note: 波音など
position: 8
content_type_00009:
id: 9
name: notated_music
display_name: "en: Notated music\r\n\
ja: 楽譜"
note:
position: 9
content_type_00010:
id: 10
name: three_dimensional_moving_image
display_name: "en: Three-dimensional moving image\r\n\
ja: 3D動画"
note:
position: 10
content_type_00011:
id: 11
name: other
display_name: "en: Other\r\n\
ja: その他"
note: LCMARCに由来
position: 11
content_type_00012:
id: 12
name: unspecified
display_name: "en: Unspecified\r\n\
ja: 不明"
note: LCMARCに由来
position: 12

# == Schema Information
#
# Table name: content_types
#
# id :integer not null, primary key
# name :string not null
# display_name :text
# note :text
# position :integer
# created_at :datetime
# updated_at :datetime
#
68 changes: 68 additions & 0 deletions spec/fixtures/frequencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
frequency_00001:
name: unknown
display_name: "en: unknown\r\n\
ja: 不明・不定期刊"
id: 1
position: 1
frequency_00002:
name: daily
display_name: "en: daily\r\n\
ja: 日刊"
id: 2
position: 2
frequency_00003:
name: weekly
display_name: "en: weekly\r\n\
ja: 週刊"
id: 3
position: 3
frequency_00004:
name: biweekly
display_name: "en: biweekly\r\n\
ja: 隔週刊"
id: 4
position: 4
frequency_00005:
name: monthly
display_name: "en: monthly\r\n\
ja: 月刊"
id: 5
position: 5
frequency_00006:
name: bimonthly
display_name: "en: bimonthly\r\n\
ja: 隔月刊"
id: 6
position: 6
frequency_00007:
name: quarterly
display_name: "en: quarterly\r\n\
ja: 季刊"
id: 7
position: 7
frequency_00008:
name: yearly
display_name: "en: yearly\r\n\
ja: 年刊"
id: 8
position: 8
frequency_00009:
name: biyearly
display_name: "en: biyearly\r\n\
ja: 隔年刊"
id: 9
position: 9

# == Schema Information
#
# Table name: frequencies
#
# id :integer not null, primary key
# name :string not null
# display_name :text
# note :text
# position :integer
# created_at :datetime
# updated_at :datetime
#
2 changes: 2 additions & 0 deletions spec/models/checkin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
checkin = Checkin.new
checkin.item = user.checkouts.not_returned.first.item
checkin.basket = @basket
checkin.librarian = users(:librarian1)
# checkin.item_identifier = checkin.item.item_identifier
checkin.save!
checkin.item_checkin(user)
Expand All @@ -27,6 +28,7 @@
checkin = Checkin.new
checkin.item = user.checkouts.not_returned.first.item
checkin.basket = @basket
checkin.librarian = users(:librarian1)
checkin.save!
checkin.item_checkin(user)
user.checkouts.count.should eq checkouts_count - 1
Expand Down

0 comments on commit f93f8c2

Please sign in to comment.