Skip to content
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
5 changes: 5 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def next_hold
before_validation :strip_whitespace

before_save :cache_description_as_plain_text
before_save :clear_hold_duration_when_holds_disabled
after_update :clear_holds_if_inactive, :pause_next_hold_if_maintenance

def self.ransackable_attributes(auth_object = nil)
Expand Down Expand Up @@ -232,6 +233,10 @@ def strip_whitespace
end
end

def clear_hold_duration_when_holds_disabled
self.hold_duration = nil unless holds_enabled
end

def clear_holds_if_inactive
return unless saved_change_to_status? && status == Item.statuses[:retired]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ConvertNoHoldsItemsToOneDayHolds < ActiveRecord::Migration[8.0]
def up
Item.where(status: "active", holds_enabled: false).find_each do |item|
item.update!(
holds_enabled: true,
hold_duration: 1,
audit_comment: "Converted from no-holds to 1-day hold (issue #2157)"
)
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_04_11_221407) do
ActiveRecord::Schema[8.1].define(version: 2026_04_24_150504) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pg_trgm"
Expand Down
6 changes: 6 additions & 0 deletions test/models/item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ class ItemTest < ActiveSupport::TestCase
refute item.holdable?
end

test "clears hold_duration when holds are disabled" do
item = create(:item, holds_enabled: true, hold_duration: 1)
item.update!(holds_enabled: false)
assert_nil item.reload.hold_duration
end

test "has a next_hold" do
item = create(:item)
hold = create(:hold, item: item, created_at: 2.days.ago)
Expand Down
Loading