Skip to content

Commit

Permalink
複数冊の予約取り置きの割り当てを修正 (#1940)
Browse files Browse the repository at this point in the history
* fix checkout

* fix checking state

* fix spec file

* update spec file
  • Loading branch information
nabeta authored Jan 19, 2025
1 parent bbe5f77 commit 9f3750d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions app/models/concerns/enju_circulation/enju_basket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ def basket_checkout(librarian)

Item.transaction do
checked_items.each do |checked_item|
checkout = user.checkouts.new(
checked_item.item.reload

checkout = user.checkouts.create!(
librarian: librarian,
item: checked_item.item,
basket: self,
library: librarian.profile.library,
shelf: checked_item.item.shelf,
due_date: checked_item.due_date
)
checkout.save!
checked_item.item.checkout!(user)
end
CheckedItem.where(basket_id: id).destroy_all
Expand Down
9 changes: 4 additions & 5 deletions app/models/concerns/enju_circulation/enju_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ def available_for_checkout?

def checkout!(user)
Item.transaction do
if user_reservation(user)
unless user_reservation.state_machine.in_state?(:completed)
user_reservation.checked_out_at = Time.zone.now
user_reservation.state_machine.transition_to!(:completed)
end
reserve = user_reservation(user)
if reserve && !reserve.state_machine.in_state?(:completed)
reserve.checked_out_at = Time.zone.now
reserve.state_machine.transition_to!(:completed)
end

update!(circulation_status: CirculationStatus.find_by(name: "On Loan"))
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/checked_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
it 'assigns a newly created checked_item as @checked_item' do
old_count = items(:item_00021).manifestation.reserves.waiting.count
post :create, params: { checked_item: { item_identifier: '00021' }, basket_id: 11 }
assigns(:checked_item).should be_valid
expect(items(:item_00021).user_reservation(Basket.find(11).user)).to be_truthy
expect(assigns(:checked_item)).not_to be_valid
expect(assigns(:checked_item).errors[:base]).to include(I18n.t('activerecord.errors.messages.checked_item.reserved_item_included'))
assigns(:checked_item).item.manifestation.reserves.waiting.count.should eq old_count
assigns(:checked_item).librarian.should eq users(:admin)
end
Expand Down

0 comments on commit 9f3750d

Please sign in to comment.