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
2 changes: 1 addition & 1 deletion app/views/donations/_donation_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/product_drive_participants/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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('<option value="">---Create new Participant---</option>');
$("#donation_product_drive_participant_id").val('<%= @product_drive_participant[:id] %>');
28 changes: 28 additions & 0 deletions spec/system/donation_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -273,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']")
Expand Down