From 3a389ba31425fa6737cffc949894143d440cdc38 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 5 Jun 2024 16:45:26 +1000 Subject: [PATCH] Update spec for quotation mark replacement I'm not sure why, but the pre-compiling of assets triggered Rails to render `style="..."` instead of `style='...'` in this case. But when assets are compiled on-demand, we get the single quotes. So I changed the spec to be agnostic of this detail. We actually just want to know about the link and its href. --- spec/mailers/subscription_mailer_spec.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index 93e4b82523..aca63f8f58 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -41,11 +41,9 @@ RSpec.describe SubscriptionMailer, type: :mailer do end describe "linking to order page" do - let(:order_link_href) { "href=\"#{order_url(order)}\"" } - let(:order_link_style) { "style='[^']+'" } - let(:shop) { create(:enterprise, allow_order_changes: true) } + let(:content) { Capybara::Node::Simple.new(body) } let(:body) { SubscriptionMailer.deliveries.last.body.encoded } before { email.deliver_now } @@ -54,19 +52,16 @@ RSpec.describe SubscriptionMailer, type: :mailer do let(:customer) { create(:customer, enterprise: shop) } it "provides link to make changes" do - expect(body).to match %r{make changes} - expect(body).not_to match %r{ - view details of this order - } + expect(content).to have_link "make changes", href: order_url(order) + expect(content).not_to have_link "view details of this order", href: order_url(order) end context "when the distributor does not allow changes to the order" do let(:shop) { create(:enterprise, allow_order_changes: false) } it "provides link to view details" do - expect(body).not_to match %r{make changes} - expect(body) - .to match %r{view details of this order} + expect(content).not_to have_link "make changes", href: order_url(order) + expect(content).to have_link "view details of this order", href: order_url(order) end end end @@ -75,14 +70,14 @@ RSpec.describe SubscriptionMailer, type: :mailer do let(:customer) { create(:customer, enterprise: shop, user: nil) } it "does not provide link" do - expect(body).not_to match /#{order_link_href}/ + expect(body).not_to match order_url(order) end context "when the distributor does not allow changes to the order" do let(:shop) { create(:enterprise, allow_order_changes: false) } it "does not provide link" do - expect(body).not_to match /#{order_link_href}/ + expect(body).not_to match order_url(order) end end end