From 5f2c3a1955ba6adbe48bc816fbc9bfbde91f08fe Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 30 Aug 2018 03:14:41 +0800 Subject: [PATCH] Remove order link in non-user failed payment email --- .../failed_payment_email.html.haml | 7 ++--- spec/mailers/subscription_mailer_spec.rb | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/views/subscription_mailer/failed_payment_email.html.haml b/app/views/subscription_mailer/failed_payment_email.html.haml index 72715a929d..36fa8d8741 100644 --- a/app/views/subscription_mailer/failed_payment_email.html.haml +++ b/app/views/subscription_mailer/failed_payment_email.html.haml @@ -2,9 +2,10 @@ %p.callout = t("email_so_failed_payment_explainer_html", distributor: @order.distributor.name) - = t("email_so_edit_false_html", - orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format), - order_url: spree.order_url(@order)) + - if @order.user.present? + = t("email_so_edit_false_html", + orders_close_at: l(@order.order_cycle.orders_close_at, format: mail_long_datetime_format), + order_url: spree.order_url(@order)) = t("email_so_contact_distributor_html", distributor: @order.distributor.name, email: @order.distributor.contact.email) - if @order.errors.any? diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index 7e8ce249d4..7a10b39909 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -129,7 +129,8 @@ describe SubscriptionMailer do end describe "failed payment notification" do - let(:subscription) { create(:subscription, with_items: true) } + let(:customer) { create(:customer) } + let(:subscription) { create(:subscription, customer: customer, with_items: true) } let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } @@ -150,6 +151,29 @@ describe SubscriptionMailer do expect(body).to include strip_tags(details) expect(body).to include "This is a payment failure error" end + + describe "linking to order page" do + let(:order_link_href) { "href=\"#{spree.order_url(order)}\"" } + + let(:email) { SubscriptionMailer.deliveries.last } + let(:body) { email.body.encoded } + + context "when the customer has a user account" do + let(:customer) { create(:customer) } + + it "provides link to view details" do + expect(body).to match /#{order_link_href}/ + end + end + + context "when the customer has no user account" do + let(:customer) { create(:customer, user: nil) } + + it "does not provide link" do + expect(body).to_not match /#{order_link_href}/ + end + end + end end describe "order placement summary" do