Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2件目以上の予約の取り置きが行われないのを修正 #1925

Merged
merged 7 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/models/reserve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Reserve < ApplicationRecord
]
scope :hold, -> { where.not(item_id: nil) }
scope :not_hold, -> { where(item_id: nil) }
scope :waiting, -> {not_in_state(:completed, :canceled, :expired).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now).order('reserves.id DESC')}
scope :waiting, -> {not_in_state(:completed, :canceled, :expired).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now)}
scope :retained, -> {in_state(:retained).where.not(retained_at: nil)}
scope :completed, -> {in_state(:completed).where.not(checked_out_at: nil)}
scope :canceled, -> {in_state(:canceled).where.not(canceled_at: nil)}
Expand Down Expand Up @@ -162,9 +162,7 @@ def check_expired_at
end

def next_reservation
if item
Reserve.waiting.where(manifestation_id: item.manifestation.id).readonly(false).first
end
Reserve.waiting.where.not(id: id).order(:created_at).find_by(manifestation_id: manifestation_id)
end

def send_message(sender = nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/enju_leaf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module EnjuLeaf
VERSION = "1.4.9".freeze
VERSION = "1.4.10".freeze
end
6 changes: 6 additions & 0 deletions spec/fixtures/reserve_transitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ reserve_transition_00015:
reserve_id: 15
sort_key: 0
most_recent: true
reserve_transition_00016:
id: 16
to_state: requested
reserve_id: 16
sort_key: 0
most_recent: true

# == Schema Information
#
Expand Down
13 changes: 11 additions & 2 deletions spec/fixtures/reserves.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ reserve_00012:
reserve_00013:
updated_at: 2007-09-03 14:20:07.530854 +09:00
manifestation_id: 11
user_id: 4
user_id: 5
request_status_type_id: 3
id: 13
created_at: 2007-09-03 14:20:07.530854 +09:00
Expand All @@ -132,12 +132,21 @@ reserve_00014:
reserve_00015:
updated_at: 2007-09-03 14:20:09.530854 +09:00
manifestation_id: 11
user_id: 4
user_id: 6
request_status_type_id: 3
id: 15
created_at: 2007-09-03 14:20:09.530854 +09:00
expired_at: <%= 1.day.from_now.to_s(:db) %>
lock_version: 0
reserve_00016:
updated_at: 2007-09-03 14:20:10.530854 +09:00
manifestation_id: 11
user_id: 2
request_status_type_id: 3
id: 16
created_at: 2007-09-03 14:20:10.530854 +09:00
expired_at: <%= 1.day.from_now.to_s(:db) %>
lock_version: 0

# == Schema Information
#
Expand Down
6 changes: 5 additions & 1 deletion spec/models/reserve_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
fixtures :all

it "should have next reservation" do
reserves(:reserve_00014).next_reservation.should be_truthy
expect(reserves(:reserve_00014).state_machine.current_state).to eq "retained"
expect(reserves(:reserve_00014).next_reservation).to eq reserves(:reserve_00015)
reserves(:reserve_00014).transition_to!(:canceled)
expect(reserves(:reserve_00015).state_machine.current_state).to eq "retained"
expect(reserves(:reserve_00015).next_reservation).to eq reserves(:reserve_00016)
end

it "should notify a next reservation" do
Expand Down
Loading