From 469f22d382ad07b3c8db8aac7b3b9c7fade2c31e Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Fri, 12 Apr 2024 13:21:43 -0400 Subject: [PATCH] fix: flaky donation spec Spec was not using hard coded values which resulted in issues with when Html was escaped. --- spec/requests/donations_requests_spec.rb | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/spec/requests/donations_requests_spec.rb b/spec/requests/donations_requests_spec.rb index c3dfcb1505..698b9c4f9f 100644 --- a/spec/requests/donations_requests_spec.rb +++ b/spec/requests/donations_requests_spec.rb @@ -30,46 +30,48 @@ end context "when given a product drive" do - let(:product_drive) { create(:product_drive) } + let(:product_drive) { create(:product_drive, name: "Drive Name") } let(:donation) { create(:donation, source: "Product Drive", product_drive: product_drive) } it "should display Product Drive and the name of the drive" do donation - expect(subject.body).to include("#{donation.source}") - expect(subject.body).to include("#{product_drive.name}") + expect(subject.body).to include("Product Drive") + expect(subject.body).to include("Drive Name") end end context "when given a donation site" do - let(:donation_site) { create(:donation_site) } + let(:donation_site) { create(:donation_site, name: "Site Name") } let(:donation) { create(:donation, source: "Donation Site", donation_site: donation_site) } it "should display Donation Site and the name of the site" do donation - expect(subject.body).to include("#{donation.source}") - expect(subject.body).to include("#{donation_site.name}") + expect(subject.body).to include("Donation Site") + expect(subject.body).to include("Site Name") end end context "when given a manufacturer" do - let(:manufacturer) { create(:manufacturer) } + let(:manufacturer) { create(:manufacturer, name: "Manufacturer Name") } let(:donation) { create(:donation, source: "Manufacturer", manufacturer: manufacturer) } it "should display Manufacturer and the manufacturer name" do donation - expect(subject.body).to include("#{donation.source}") - expect(subject.body).to include("#{manufacturer.name}") + expect(subject.body).to include("Manufacturer") + expect(subject.body).to include("Manufacturer Name") end end context "when given a misc donation" do - let(:donation) { create(:donation, source: "Misc. Donation", comment: Faker::Lorem.paragraph) } + let(:full_comment) { Faker::Lorem.paragraph } + let(:donation) { create(:donation, source: "Misc. Donation", comment: full_comment) } it "should display Misc Donation and a truncated comment" do donation - short_comment = donation.comment.truncate(25, separator: /\s/) - expect(subject.body).to include("#{donation.source}") + short_comment = full_comment.truncate(25, separator: /\s/) + expect(subject.body).to include("Misc. Donation") expect(subject.body).to include("#{short_comment}") + expect(subject.body).to_not include("#{full_comment}") end end end