From b13b2b9b95b63d906b44c367bf6aecfbf74a464f Mon Sep 17 00:00:00 2001 From: vishaldeepak Date: Thu, 2 Sep 2021 18:59:11 +0530 Subject: [PATCH] Customer Information on mail show be displayed depending on order cycle coordinator's customer names flag --- app/mailers/producer_mailer.rb | 2 +- spec/mailers/producer_mailer_spec.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index e6abee7109..66a47d91c9 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -77,7 +77,7 @@ class ProducerMailer < Spree::BaseMailer end def set_customer_data(line_items) - return unless @producer.preferred_show_customer_names_to_suppliers + return unless @coordinator.preferred_show_customer_names_to_suppliers line_items.map do |line_item| { sku: line_item.variant.sku, diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index d746fc44b5..e3a22d4ab2 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -129,7 +129,9 @@ describe ProducerMailer, type: :mailer do end context 'when flag preferred_show_customer_names_to_suppliers is true' do - let(:s1) { create(:supplier_enterprise, preferred_show_customer_names_to_suppliers: true) } + before do + order_cycle.coordinator.set_preference(:show_customer_names_to_suppliers, true) + end it "adds customer names table" do expect(body_as_html(mail).find(".order-summary.customer-order")).to_not be_nil @@ -155,7 +157,9 @@ describe ProducerMailer, type: :mailer do end context 'when flag preferred_show_customer_names_to_suppliers is false' do - let(:s1) { create(:supplier_enterprise, preferred_show_customer_names_to_suppliers: false) } + before do + order_cycle.coordinator.set_preference(:show_customer_names_to_suppliers, false) + end it "does not add customer names table" do expect { body_as_html(mail).find(".order-summary.customer-order") }.to raise_error(Capybara::ElementNotFound)