From d15baae2fc7708116b089b493f2598c42024af29 Mon Sep 17 00:00:00 2001 From: Brian Bonus Date: Fri, 25 Apr 2025 15:33:09 -0700 Subject: [PATCH 1/3] bug-4976 Defaults dropdown menu to use contact name when no business name is present --- app/views/donations/_donation_form.html.erb | 2 +- spec/system/donation_system_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/donations/_donation_form.html.erb b/app/views/donations/_donation_form.html.erb index 977ef7319c..4c1bddf0e5 100644 --- a/app/views/donations/_donation_form.html.erb +++ b/app/views/donations/_donation_form.html.erb @@ -41,7 +41,7 @@ collection: @product_drive_participants, selected: donation_form.product_drive_participant_id, include_blank: true, - label_method: lambda { |x| "#{x.try(:business_name) }" }, + label_method: lambda { |x| "#{x.try(:business_name).presence || x.try(:contact_name)}" }, label: "Product Drive Participant", error: "Which product drive participant was this from?", wrapper: :input_group %> diff --git a/spec/system/donation_system_spec.rb b/spec/system/donation_system_spec.rb index e94e8789a7..97e8eeaa97 100644 --- a/spec/system/donation_system_spec.rb +++ b/spec/system/donation_system_spec.rb @@ -161,6 +161,7 @@ create(:donation_site, organization: organization) create(:product_drive, organization: organization) create(:product_drive_participant, organization: organization) + create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") create(:manufacturer, organization: organization) organization.reload end @@ -248,6 +249,12 @@ end.to change { Donation.count }.by(1) end + it "Displays ProductDrive Participants sources by business name then contact name" do + select Donation::SOURCES[:product_drive], from: "donation_source" + select ProductDrive.first.name, from: "donation_product_drive_id" + expect(page).to have_select('donation_product_drive_participant_id', with_options: ['contact without business name']) + end + it "Allows User to create a Product Drive from donation" do select Donation::SOURCES[:product_drive], from: "donation_source" select "---Create new Product Drive---", from: "donation_product_drive_id" From abfe8fab5d2e53d3508f8ff2ccea073b4745255c Mon Sep 17 00:00:00 2001 From: Brian Bonus Date: Sat, 26 Apr 2025 10:54:25 -0700 Subject: [PATCH 2/3] bug-4976 updates rendering for contact-name & business name when creating a drive participant 'on-the-fly' --- .../product_drive_participants/create.js.erb | 2 +- spec/system/donation_system_spec.rb | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/views/product_drive_participants/create.js.erb b/app/views/product_drive_participants/create.js.erb index 4fb11ddbe1..9f291950f7 100644 --- a/app/views/product_drive_participants/create.js.erb +++ b/app/views/product_drive_participants/create.js.erb @@ -2,6 +2,6 @@ $("#modal_new").modal("hide"); $("#donation_product_drive_participant_id").empty(); $("#donation_product_drive_participant_id"). -html('<%= j options_from_collection_for_select(current_organization.product_drive_participants, :id, :business_name) %>'); +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 }) %>'); $("#donation_product_drive_participant_id").append(''); $("#donation_product_drive_participant_id").val('<%= @product_drive_participant[:id] %>'); diff --git a/spec/system/donation_system_spec.rb b/spec/system/donation_system_spec.rb index 97e8eeaa97..8f7eeb0338 100644 --- a/spec/system/donation_system_spec.rb +++ b/spec/system/donation_system_spec.rb @@ -280,9 +280,30 @@ fill_in "product_drive_participant_email", with: "123@mail.ru" fill_in "product_drive_participant_comment", with: "test comment" click_on "product-drive-participant-submit" + expect(page).to have_select('donation_product_drive_participant_id', with_options: ['businesstest']) + select "businesstest", from: "donation_product_drive_participant_id" end + #seems like a duplicate check but this update happens via JS, so we have to test that code works too + it "Renders ProductDrive Participants sources by business name then contact name after creating a participant" do + select Donation::SOURCES[:product_drive], from: "donation_source" + select "---Create new Participant---", from: "donation_product_drive_participant_id" + + find(".modal-content") + expect(page).to have_content("New Product Drive Participant") + + fill_in "product_drive_participant_business_name", with: "" + fill_in "product_drive_participant_contact_name", with: "2nd contact without business name" + fill_in "product_drive_participant_email", with: "1233@mail.ru" + fill_in "product_drive_participant_comment", with: "test comment" + click_on "product-drive-participant-submit" + + select ProductDrive.first.name, from: "donation_product_drive_id" + #note that I'm not explicitly testing the business name here, this is handled in the previous test + expect(page).to have_select('donation_product_drive_participant_id', with_options: ['2nd contact without business name']) + end + it "Allows User to create a donation for a Manufacturer source" do select Donation::SOURCES[:manufacturer], from: "donation_source" expect(page).to have_xpath("//select[@id='donation_manufacturer_id']") From 1ad4ff925cdbc3fc4267100497395d6ff8896386 Mon Sep 17 00:00:00 2001 From: Brian Bonus Date: Mon, 28 Apr 2025 10:25:34 -0700 Subject: [PATCH 3/3] Fixes silly linter mistake in spec file --- spec/system/donation_system_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/donation_system_spec.rb b/spec/system/donation_system_spec.rb index 8f7eeb0338..25a6909e95 100644 --- a/spec/system/donation_system_spec.rb +++ b/spec/system/donation_system_spec.rb @@ -285,7 +285,7 @@ select "businesstest", from: "donation_product_drive_participant_id" end - #seems like a duplicate check but this update happens via JS, so we have to test that code works too + # seems like a duplicate check but this update happens via JS, so we have to test that code works too it "Renders ProductDrive Participants sources by business name then contact name after creating a participant" do select Donation::SOURCES[:product_drive], from: "donation_source" select "---Create new Participant---", from: "donation_product_drive_participant_id" @@ -300,7 +300,7 @@ click_on "product-drive-participant-submit" select ProductDrive.first.name, from: "donation_product_drive_id" - #note that I'm not explicitly testing the business name here, this is handled in the previous test + # note that I'm not explicitly testing the business name here, this is handled in the previous test expect(page).to have_select('donation_product_drive_participant_id', with_options: ['2nd contact without business name']) end