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 7, 2018
1 parent f93f8c2 commit d859373
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
6 changes: 3 additions & 3 deletions app/models/checked_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CheckedItem < ActiveRecord::Base
belongs_to :item # , validate: true
belongs_to :basket # , validate: true
belongs_to :librarian, class_name: 'User' # , validate: true
belongs_to :item
belongs_to :basket
belongs_to :librarian, class_name: 'User', optional: true

validates_associated :item, :basket, on: :update
validates :item, :basket, :due_date, presence: { on: :update }
Expand Down
6 changes: 3 additions & 3 deletions app/models/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class Checkout < ActiveRecord::Base
scope :completed, lambda {|start_date, end_date| where('checkouts.created_at >= ? AND checkouts.created_at < ?', start_date, end_date)}
scope :on, lambda {|date| where('created_at >= ? AND created_at < ?', date.beginning_of_day, date.tomorrow.beginning_of_day)}

belongs_to :user
belongs_to :user, optional: true
delegate :username, :user_number, to: :user, prefix: true
belongs_to :item, touch: true
belongs_to :checkin, optional: true
belongs_to :librarian, class_name: 'User'
belongs_to :basket
belongs_to :shelf
belongs_to :library
belongs_to :shelf, optional: true
belongs_to :library, optional: true

validates_associated :user, :item, :librarian, :checkin # , :basket
# TODO: 貸出履歴を保存しない場合は、ユーザ名を削除する
Expand Down
5 changes: 2 additions & 3 deletions app/models/concerns/enju_circulation/enju_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@ def available_for_checkout?
end

def checkout!(user)
self.circulation_status = CirculationStatus.find_by(name: 'On Loan')
if reserved_by_user?(user)
manifestation.next_reservation.update(checked_out_at: Time.zone.now)
manifestation.next_reservation.transition_to!(:completed)
manifestation.reload
end
manifestation.reload
save!
update!(circulation_status: CirculationStatus.find_by(name: 'On Loan'))
end

def checkin!
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/bookstore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :bookstore do |f|
f.sequence(:name){|n| "bookstore_#{n}"}
end
end
18 changes: 18 additions & 0 deletions spec/factories/budget_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FactoryBot.define do
factory :budget_type do |f|
f.sequence(:name){|n| "budget_type_#{n}"}
end
end

# == Schema Information
#
# Table name: budget_types
#
# id :integer not null, primary key
# name :string
# display_name :text
# note :text
# position :integer
# created_at :datetime
# updated_at :datetime
#
10 changes: 6 additions & 4 deletions spec/factories/item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FactoryBot.define do
factory :item do |f|
f.sequence(:item_identifier){|n| "item_#{n}"}
f.circulation_status_id{CirculationStatus.find(1).id} if defined?(EnjuCircuation)
f.manifestation_id{FactoryBot.create(:manifestation).id}
factory :item do
sequence(:item_identifier){|n| "item_#{n}"}
circulation_status_id{CirculationStatus.find(1).id} if defined?(EnjuCircuation)
manifestation_id{FactoryBot.create(:manifestation).id}
association :bookstore
association :budget_type
end
end

0 comments on commit d859373

Please sign in to comment.