-
Notifications
You must be signed in to change notification settings - Fork 71
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
1756 add button to remove holds on an item #1835
base: main
Are you sure you want to change the base?
Changes from all commits
4999934
0ce9363
acdb78a
f8158ba
0fab47d
79a89b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,9 @@ | ||||||||||||||||||||||||||||||||
module Admin | ||||||||||||||||||||||||||||||||
module Items | ||||||||||||||||||||||||||||||||
class HoldsController < BaseController | ||||||||||||||||||||||||||||||||
before_action :set_item | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def index | ||||||||||||||||||||||||||||||||
@item = Item.find(params[:item_id]) | ||||||||||||||||||||||||||||||||
holds_scope = @item.holds.ordered_by_position.includes(:member) | ||||||||||||||||||||||||||||||||
@holds = | ||||||||||||||||||||||||||||||||
if params[:inactive] | ||||||||||||||||||||||||||||||||
|
@@ -11,6 +12,18 @@ def index | |||||||||||||||||||||||||||||||
holds_scope.active | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def remove | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could also see this using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good thought! I think originally it was proper if we were going to destroy the hold, but since we decided to just timestamp Do you prefer something like this that is more generic?
Additionally - when I was working on this I remembered a team I worked on where we discussed creating new controllers for variations of main resources, for example we could have a single concern Where does your intuition point to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel too strongly to be honest. I'd like to say we have a strong pattern in the app for this kind of thing, but it's probably a bit ad-hoc since we've had a lot of different people/perspectives in the code over the years. I guess whether the hold is deleted or not depends on the perspective: in the database we're not deleting it, but from the UI perspective it's gone! But if we're to say that we're going to keep the controllers in line with the the database-view, then I agree that this isn't really deleting the hold. I actually like the new controller option. Now that you mention it, I did something similar to implement reordering of the holds to avoid overloading the
So I guess that's my preference, but TBH this is also totally fine as-is and there are other things to implement. I'll leave it up to you if you want to change this or merge it as-is and move on to the next thing 😄. I appreciate the thought you put into this! |
||||||||||||||||||||||||||||||||
@hold = @item.holds.find(params[:hold_id]) | ||||||||||||||||||||||||||||||||
@hold.update(ended_at: Time.current) | ||||||||||||||||||||||||||||||||
redirect_to admin_item_holds_path(@item), flash: {success: "Hold ended."}, status: :see_other | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
private | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def set_item | ||||||||||||||||||||||||||||||||
@item = Item.find(params[:item_id]) | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,4 +196,24 @@ def setup | |
reloaded_hold_ids = all(".item-holds-table tr[data-hold-id]").pluck("data-hold-id") | ||
assert_equal expected_hold_ids, reloaded_hold_ids | ||
end | ||
|
||
test "ending a specific hold on an item" do | ||
# use factory bot to create a few started holds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL about |
||
@holds = create_list(:started_hold, 3) | ||
@a_hold = @holds.first | ||
@item = @a_hold.item | ||
|
||
# visit the admin item holds page | ||
visit admin_item_holds_path(@item) | ||
|
||
# end the hold we're testing and verify the # of active holds has decreased by 1 | ||
within "[data-hold-id='#{@a_hold.id}']" do | ||
assert_difference("@item.active_holds.count", -1) do | ||
accept_confirm { click_on "Remove Hold" } | ||
end | ||
end | ||
|
||
# confirm the hold we ended now has a truthy ended_at | ||
assert @a_hold.reload.ended_at.present? | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love to see some refactoring 😄