Skip to content

Commit 180edd2

Browse files
[5302] Conditionally Display Inactive Donation Sites on Edit (#5305)
* Conditionally display inactive donation sites in dropdown * Preserve alphabetization of donation site list * Move donations_controller_spec tests to donations_requests_spec
1 parent 57fe274 commit 180edd2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

app/controllers/donations_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ def destroy
127127

128128
def load_form_collections
129129
@storage_locations = current_organization.storage_locations.active.alphabetized
130-
@donation_sites = current_organization.donation_sites.active.alphabetized
131130
@product_drives = current_organization.product_drives.alphabetized
132131
@product_drive_participants = current_organization.product_drive_participants.alphabetized
133132
@manufacturers = current_organization.manufacturers.alphabetized
134133
@items = current_organization.items.active.alphabetized
134+
# Return all active donation sites, or the donation site that was selected for the donation if it's inactive
135+
@donation_sites = current_organization.donation_sites.active.or(DonationSite.where(id: @donation.donation_site_id)).alphabetized
135136
end
136137

137138
def clean_donation_money_raised

spec/requests/donations_requests_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@
100100
it "should include the storage location name" do
101101
expect(subject.body).to include("Pawane Location")
102102
end
103+
104+
context "when creating a new donation" do
105+
let!(:inactive_donation_site) { create(:donation_site, organization: organization, active: false) }
106+
107+
it "does not include inactive donation sites" do
108+
subject
109+
expect(response.body).not_to include(inactive_donation_site.name)
110+
end
111+
end
103112
end
104113

105114
describe "POST #create" do
@@ -265,6 +274,29 @@
265274
expect(response.body).to include("you’ll need to make an adjustment to the inventory as well.")
266275
end
267276
end
277+
278+
context "when editing a donation with an inactive donation site" do
279+
let!(:active_donation_site) { create(:donation_site, organization: organization, name: "Active Donation Site") }
280+
let!(:inactive_donation_site) { create(:donation_site, organization: organization, active: false, name: "Inactive Donation Site") }
281+
let!(:donation_with_inactive_site) { create(:donation, organization: organization, donation_site: inactive_donation_site) }
282+
283+
it "includes the inactive donation site in the dropdown" do
284+
get edit_donation_path(donation_with_inactive_site)
285+
expect(response.body).to include(inactive_donation_site.name)
286+
end
287+
288+
it "displays the donation site names alphabetically" do
289+
get edit_donation_path(donation_with_inactive_site)
290+
291+
# Get all donation site names that should be in the dropdown and sort them
292+
donation_sites = [active_donation_site, inactive_donation_site]
293+
sorted_names = donation_sites.map(&:name).sort
294+
295+
# Verify that the donation sites are alphabetized
296+
expect(sorted_names[0]).to eq(active_donation_site.name)
297+
expect(sorted_names[1]).to eq(inactive_donation_site.name)
298+
end
299+
end
268300
end
269301

270302
context "when an non-finalized audit has been performed on the donated items" do

0 commit comments

Comments
 (0)