Skip to content

Commit fc95a66

Browse files
bsbonusBrian Bonus
andauthored
4976 enable defaulting to contact name (#5163)
* bug-4976 Defaults dropdown menu to use contact name when no business name is present * bug-4976 updates rendering for contact-name & business name when creating a drive participant 'on-the-fly' * Fixes silly linter mistake in spec file --------- Co-authored-by: Brian Bonus <bonus@MacBookPro.lan>
1 parent 310ab6d commit fc95a66

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

app/views/donations/_donation_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
collection: @product_drive_participants,
4242
selected: donation_form.product_drive_participant_id,
4343
include_blank: true,
44-
label_method: lambda { |x| "#{x.try(:business_name) }" },
44+
label_method: lambda { |x| "#{x.try(:business_name).presence || x.try(:contact_name)}" },
4545
label: "Product Drive Participant",
4646
error: "Which product drive participant was this from?",
4747
wrapper: :input_group %>

app/views/product_drive_participants/create.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
$("#modal_new").modal("hide");
33
$("#donation_product_drive_participant_id").empty();
44
$("#donation_product_drive_participant_id").
5-
html('<%= j options_from_collection_for_select(current_organization.product_drive_participants, :id, :business_name) %>');
5+
html('<%= j options_from_collection_for_select(current_organization.product_drive_participants, :id, lambda { |p| p.business_name.present? ? p.business_name : p.contact_name }) %>');
66
$("#donation_product_drive_participant_id").append('<option value="">---Create new Participant---</option>');
77
$("#donation_product_drive_participant_id").val('<%= @product_drive_participant[:id] %>');

spec/system/donation_system_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
create(:donation_site, organization: organization)
162162
create(:product_drive, organization: organization)
163163
create(:product_drive_participant, organization: organization)
164+
create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "")
164165
create(:manufacturer, organization: organization)
165166
organization.reload
166167
end
@@ -248,6 +249,12 @@
248249
end.to change { Donation.count }.by(1)
249250
end
250251

252+
it "Displays ProductDrive Participants sources by business name then contact name" do
253+
select Donation::SOURCES[:product_drive], from: "donation_source"
254+
select ProductDrive.first.name, from: "donation_product_drive_id"
255+
expect(page).to have_select('donation_product_drive_participant_id', with_options: ['contact without business name'])
256+
end
257+
251258
it "Allows User to create a Product Drive from donation" do
252259
select Donation::SOURCES[:product_drive], from: "donation_source"
253260
select "---Create new Product Drive---", from: "donation_product_drive_id"
@@ -273,9 +280,30 @@
273280
fill_in "product_drive_participant_email", with: "123@mail.ru"
274281
fill_in "product_drive_participant_comment", with: "test comment"
275282
click_on "product-drive-participant-submit"
283+
expect(page).to have_select('donation_product_drive_participant_id', with_options: ['businesstest'])
284+
276285
select "businesstest", from: "donation_product_drive_participant_id"
277286
end
278287

288+
# seems like a duplicate check but this update happens via JS, so we have to test that code works too
289+
it "Renders ProductDrive Participants sources by business name then contact name after creating a participant" do
290+
select Donation::SOURCES[:product_drive], from: "donation_source"
291+
select "---Create new Participant---", from: "donation_product_drive_participant_id"
292+
293+
find(".modal-content")
294+
expect(page).to have_content("New Product Drive Participant")
295+
296+
fill_in "product_drive_participant_business_name", with: ""
297+
fill_in "product_drive_participant_contact_name", with: "2nd contact without business name"
298+
fill_in "product_drive_participant_email", with: "1233@mail.ru"
299+
fill_in "product_drive_participant_comment", with: "test comment"
300+
click_on "product-drive-participant-submit"
301+
302+
select ProductDrive.first.name, from: "donation_product_drive_id"
303+
# note that I'm not explicitly testing the business name here, this is handled in the previous test
304+
expect(page).to have_select('donation_product_drive_participant_id', with_options: ['2nd contact without business name'])
305+
end
306+
279307
it "Allows User to create a donation for a Manufacturer source" do
280308
select Donation::SOURCES[:manufacturer], from: "donation_source"
281309
expect(page).to have_xpath("//select[@id='donation_manufacturer_id']")

0 commit comments

Comments
 (0)