From c6cd695b3c901f66bf4194521c5599caaf659736 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 13:28:11 +0100 Subject: [PATCH 01/10] Bring remaing mailers from spree_core --- app/mailers/spree/base_mailer.rb | 12 ++ app/mailers/spree/order_mailer.rb | 17 +++ app/mailers/spree/shipment_mailer.rb | 10 ++ app/mailers/spree/test_mailer.rb | 9 ++ spec/mailers/order_mailer_from_spree_spec.rb | 120 +++++++++++++++++++ spec/mailers/shipment_mailer_spec.rb | 59 +++++++++ spec/mailers/test_mailer_spec.rb | 23 ++++ 7 files changed, 250 insertions(+) create mode 100644 app/mailers/spree/base_mailer.rb create mode 100644 app/mailers/spree/order_mailer.rb create mode 100644 app/mailers/spree/shipment_mailer.rb create mode 100644 app/mailers/spree/test_mailer.rb create mode 100644 spec/mailers/order_mailer_from_spree_spec.rb create mode 100644 spec/mailers/shipment_mailer_spec.rb create mode 100644 spec/mailers/test_mailer_spec.rb diff --git a/app/mailers/spree/base_mailer.rb b/app/mailers/spree/base_mailer.rb new file mode 100644 index 00000000000..7d35ecdd432 --- /dev/null +++ b/app/mailers/spree/base_mailer.rb @@ -0,0 +1,12 @@ +module Spree + class BaseMailer < ActionMailer::Base + def from_address + Spree::Config[:mails_from] + end + + def money(amount) + Spree::Money.new(amount).to_s + end + helper_method :money + end +end diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb new file mode 100644 index 00000000000..1af6b31cb40 --- /dev/null +++ b/app/mailers/spree/order_mailer.rb @@ -0,0 +1,17 @@ +module Spree + class OrderMailer < BaseMailer + def confirm_email(order, resend = false) + @order = order.respond_to?(:id) ? order : Spree::Order.find(order) + subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}" + mail(to: @order.email, from: from_address, subject: subject) + end + + def cancel_email(order, resend = false) + @order = order.respond_to?(:id) ? order : Spree::Order.find(order) + subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{Spree.t('order_mailer.cancel_email.subject')} ##{@order.number}" + mail(to: @order.email, from: from_address, subject: subject) + end + end +end diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb new file mode 100644 index 00000000000..d9f00671a1d --- /dev/null +++ b/app/mailers/spree/shipment_mailer.rb @@ -0,0 +1,10 @@ +module Spree + class ShipmentMailer < BaseMailer + def shipped_email(shipment, resend = false) + @shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment) + subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{Spree.t('shipment_mailer.shipped_email.subject')} ##{@shipment.order.number}" + mail(to: @shipment.order.email, from: from_address, subject: subject) + end + end +end diff --git a/app/mailers/spree/test_mailer.rb b/app/mailers/spree/test_mailer.rb new file mode 100644 index 00000000000..8a547427226 --- /dev/null +++ b/app/mailers/spree/test_mailer.rb @@ -0,0 +1,9 @@ +module Spree + class TestMailer < BaseMailer + def test_email(user) + recipient = user.respond_to?(:id) ? user : Spree.user_class.find(user) + subject = "#{Spree::Config[:site_name]} #{Spree.t('test_mailer.test_email.subject')}" + mail(to: recipient.email, from: from_address, subject: subject) + end + end +end diff --git a/spec/mailers/order_mailer_from_spree_spec.rb b/spec/mailers/order_mailer_from_spree_spec.rb new file mode 100644 index 00000000000..399c097fd43 --- /dev/null +++ b/spec/mailers/order_mailer_from_spree_spec.rb @@ -0,0 +1,120 @@ +require 'spec_helper' +require 'email_spec' + +describe Spree::OrderMailer do + include EmailSpec::Helpers + include EmailSpec::Matchers + + let(:order) do + order = stub_model(Spree::Order) + product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) + variant = stub_model(Spree::Variant, :product => product) + price = stub_model(Spree::Price, :variant => variant, :amount => 5.00) + line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 4.99) + variant.stub(:default_price => price) + order.stub(:line_items => [line_item]) + order + end + + context ":from not set explicitly" do + it "falls back to spree config" do + message = Spree::OrderMailer.confirm_email(order) + message.from.should == [Spree::Config[:mails_from]] + end + end + + it "doesn't aggressively escape double quotes in confirmation body" do + confirmation_email = Spree::OrderMailer.confirm_email(order) + confirmation_email.body.should_not include(""") + end + + it "confirm_email accepts an order id as an alternative to an Order object" do + Spree::Order.should_receive(:find).with(order.id).and_return(order) + lambda { + confirmation_email = Spree::OrderMailer.confirm_email(order.id) + }.should_not raise_error + end + + it "cancel_email accepts an order id as an alternative to an Order object" do + Spree::Order.should_receive(:find).with(order.id).and_return(order) + lambda { + cancel_email = Spree::OrderMailer.cancel_email(order.id) + }.should_not raise_error + end + + context "only shows eligible adjustments in emails" do + before do + order.adjustments.create( + :label => "Eligible Adjustment", + :amount => 10, + :eligible => true + ) + + order.adjustments.create!( + :label => "Ineligible Adjustment", + :amount => -10, + :eligible => false + ) + end + + let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) } + let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } + + specify do + confirmation_email.body.should_not include("Ineligible Adjustment") + end + + specify do + cancel_email.body.should_not include("Ineligible Adjustment") + end + end + + context "displays unit costs from line item" do + # Regression test for #2772 + + # Tests mailer view spree/order_mailer/confirm_email.text.erb + specify do + confirmation_email = Spree::OrderMailer.confirm_email(order) + confirmation_email.body.should include("4.99") + confirmation_email.body.should_not include("5.00") + end + + # Tests mailer view spree/order_mailer/cancel_email.text.erb + specify do + cancel_email = Spree::OrderMailer.cancel_email(order) + cancel_email.body.should include("4.99") + cancel_email.body.should_not include("5.00") + end + end + + context "emails must be translatable" do + + context "pt-BR locale" do + before do + pt_br_confirm_mail = { :spree => { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } } } + pt_br_cancel_mail = { :spree => { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } } } + I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail + I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail + I18n.locale = :'pt-BR' + end + + after do + I18n.locale = I18n.default_locale + end + + context "confirm_email" do + specify do + confirmation_email = Spree::OrderMailer.confirm_email(order) + confirmation_email.body.should include("Caro Cliente,") + end + end + + context "cancel_email" do + specify do + cancel_email = Spree::OrderMailer.cancel_email(order) + cancel_email.body.should include("Resumo da Pedido [CANCELADA]") + end + end + end + end +end diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb new file mode 100644 index 00000000000..c7a0da61728 --- /dev/null +++ b/spec/mailers/shipment_mailer_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' +require 'email_spec' + +describe Spree::ShipmentMailer do + include EmailSpec::Helpers + include EmailSpec::Matchers + + let(:shipment) do + order = stub_model(Spree::Order) + product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) + variant = stub_model(Spree::Variant, :product => product) + line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 5) + shipment = stub_model(Spree::Shipment) + shipment.stub(:line_items => [line_item], :order => order) + shipment.stub(:tracking_url => "TRACK_ME") + shipment + end + + context ":from not set explicitly" do + it "falls back to spree config" do + message = Spree::ShipmentMailer.shipped_email(shipment) + message.from.should == [Spree::Config[:mails_from]] + end + end + + # Regression test for #2196 + it "doesn't include out of stock in the email body" do + shipment_email = Spree::ShipmentMailer.shipped_email(shipment) + shipment_email.body.should_not include(%Q{Out of Stock}) + end + + it "shipment_email accepts an shipment id as an alternative to an Shipment object" do + Spree::Shipment.should_receive(:find).with(shipment.id).and_return(shipment) + lambda { + shipped_email = Spree::ShipmentMailer.shipped_email(shipment.id) + }.should_not raise_error + end + + context "emails must be translatable" do + context "shipped_email" do + context "pt-BR locale" do + before do + pt_br_shipped_email = { :spree => { :shipment_mailer => { :shipped_email => { :dear_customer => 'Caro Cliente,' } } } } + I18n.backend.store_translations :'pt-BR', pt_br_shipped_email + I18n.locale = :'pt-BR' + end + + after do + I18n.locale = I18n.default_locale + end + + specify do + shipped_email = Spree::ShipmentMailer.shipped_email(shipment) + shipped_email.body.should include("Caro Cliente,") + end + end + end + end +end diff --git a/spec/mailers/test_mailer_spec.rb b/spec/mailers/test_mailer_spec.rb new file mode 100644 index 00000000000..6ed147ad10a --- /dev/null +++ b/spec/mailers/test_mailer_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' +require 'email_spec' + +describe Spree::TestMailer do + include EmailSpec::Helpers + include EmailSpec::Matchers + + let(:user) { create(:user) } + + context ":from not set explicitly" do + it "falls back to spree config" do + message = Spree::TestMailer.test_email(user) + message.from.should == [Spree::Config[:mails_from]] + end + end + + it "confirm_email accepts a user id as an alternative to a User object" do + Spree.user_class.should_receive(:find).with(user.id).and_return(user) + lambda { + test_email = Spree::TestMailer.test_email(user.id) + }.should_not raise_error + end +end \ No newline at end of file From d12495f3db05ba7ba824cdda411ffeee675bb136 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 13:38:11 +0100 Subject: [PATCH 02/10] Merge decorators with original classes brought from spree and merge order_mailer specs --- app/mailers/spree/base_mailer.rb | 13 ++ app/mailers/spree/base_mailer_decorator.rb | 14 --- app/mailers/spree/order_mailer.rb | 69 +++++++++-- app/mailers/spree/order_mailer_decorator.rb | 64 ---------- spec/mailers/order_mailer_from_spree_spec.rb | 120 ------------------- spec/mailers/order_mailer_spec.rb | 110 +++++++++++++++++ 6 files changed, 182 insertions(+), 208 deletions(-) delete mode 100644 app/mailers/spree/base_mailer_decorator.rb delete mode 100644 app/mailers/spree/order_mailer_decorator.rb delete mode 100644 spec/mailers/order_mailer_from_spree_spec.rb diff --git a/app/mailers/spree/base_mailer.rb b/app/mailers/spree/base_mailer.rb index 7d35ecdd432..5d6e616b1f3 100644 --- a/app/mailers/spree/base_mailer.rb +++ b/app/mailers/spree/base_mailer.rb @@ -1,5 +1,11 @@ module Spree class BaseMailer < ActionMailer::Base + # Inline stylesheets + include Roadie::Rails::Automatic + + # Define layout + layout 'mailer' + def from_address Spree::Config[:mails_from] end @@ -8,5 +14,12 @@ def money(amount) Spree::Money.new(amount).to_s end helper_method :money + + protected + + def roadie_options + # This lets us specify assets using relative paths in email templates + super.merge(url_options: { host: URI(main_app.root_url).host }) + end end end diff --git a/app/mailers/spree/base_mailer_decorator.rb b/app/mailers/spree/base_mailer_decorator.rb deleted file mode 100644 index 4c15268676d..00000000000 --- a/app/mailers/spree/base_mailer_decorator.rb +++ /dev/null @@ -1,14 +0,0 @@ -Spree::BaseMailer.class_eval do - # Inline stylesheets - include Roadie::Rails::Automatic - - # Define layout - layout 'mailer' - - protected - - def roadie_options - # This lets us specify assets using relative paths in email templates - super.merge(url_options: { host: URI(main_app.root_url).host }) - end -end diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index 1af6b31cb40..cb90f25b688 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -1,17 +1,66 @@ module Spree class OrderMailer < BaseMailer - def confirm_email(order, resend = false) - @order = order.respond_to?(:id) ? order : Spree::Order.find(order) - subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{Spree.t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(to: @order.email, from: from_address, subject: subject) + helper HtmlHelper + helper CheckoutHelper + helper SpreeCurrencyHelper + helper OrderHelper + include I18nHelper + + def cancel_email(order_or_order_id, resend = false) + @order = find_order(order_or_order_id) + I18n.with_locale valid_locale(@order.user) do + mail(to: @order.email, + from: from_address, + subject: mail_subject(t('spree.order_mailer.cancel_email.subject'), resend)) + end + end + + def confirm_email_for_customer(order_or_order_id, resend = false) + @order = find_order(order_or_order_id) + I18n.with_locale valid_locale(@order.user) do + subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend) + mail(to: @order.email, + from: from_address, + subject: subject, + reply_to: @order.distributor.contact.email) + end + end + + def confirm_email_for_shop(order_or_order_id, resend = false) + @order = find_order(order_or_order_id) + I18n.with_locale valid_locale(@order.user) do + subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend) + mail(to: @order.distributor.contact.email, + from: from_address, + subject: subject) + end + end + + def invoice_email(order_or_order_id, pdf) + @order = find_order(order_or_order_id) + attach_file("invoice-#{@order.number}.pdf", pdf) + I18n.with_locale valid_locale(@order.user) do + mail(to: @order.email, + from: from_address, + subject: mail_subject(t(:invoice), false), + reply_to: @order.distributor.contact.email) + end + end + + private + + # Finds an order instance from an order or from an order id + def find_order(order_or_order_id) + order_or_order_id.respond_to?(:id) ? order_or_order_id : Spree::Order.find(order_or_order_id) + end + + def mail_subject(base_subject, resend) + resend_prefix = (resend ? "[#{t(:resend).upcase}] " : '') + "#{resend_prefix}#{Spree::Config[:site_name]} #{base_subject} ##{@order.number}" end - def cancel_email(order, resend = false) - @order = order.respond_to?(:id) ? order : Spree::Order.find(order) - subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{Spree.t('order_mailer.cancel_email.subject')} ##{@order.number}" - mail(to: @order.email, from: from_address, subject: subject) + def attach_file(filename, file) + attachments[filename] = file if file.present? end end end diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb deleted file mode 100644 index fbf17013b88..00000000000 --- a/app/mailers/spree/order_mailer_decorator.rb +++ /dev/null @@ -1,64 +0,0 @@ -Spree::OrderMailer.class_eval do - helper HtmlHelper - helper CheckoutHelper - helper SpreeCurrencyHelper - helper OrderHelper - include I18nHelper - - def cancel_email(order_or_order_id, resend = false) - @order = find_order(order_or_order_id) - I18n.with_locale valid_locale(@order.user) do - mail(to: @order.email, - from: from_address, - subject: mail_subject(t('spree.order_mailer.cancel_email.subject'), resend)) - end - end - - def confirm_email_for_customer(order_or_order_id, resend = false) - @order = find_order(order_or_order_id) - I18n.with_locale valid_locale(@order.user) do - subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend) - mail(to: @order.email, - from: from_address, - subject: subject, - reply_to: @order.distributor.contact.email) - end - end - - def confirm_email_for_shop(order_or_order_id, resend = false) - @order = find_order(order_or_order_id) - I18n.with_locale valid_locale(@order.user) do - subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend) - mail(to: @order.distributor.contact.email, - from: from_address, - subject: subject) - end - end - - def invoice_email(order_or_order_id, pdf) - @order = find_order(order_or_order_id) - attach_file("invoice-#{@order.number}.pdf", pdf) - I18n.with_locale valid_locale(@order.user) do - mail(to: @order.email, - from: from_address, - subject: mail_subject(t(:invoice), false), - reply_to: @order.distributor.contact.email) - end - end - - private - - # Finds an order instance from an order or from an order id - def find_order(order_or_order_id) - order_or_order_id.respond_to?(:id) ? order_or_order_id : Spree::Order.find(order_or_order_id) - end - - def mail_subject(base_subject, resend) - resend_prefix = (resend ? "[#{t(:resend).upcase}] " : '') - "#{resend_prefix}#{Spree::Config[:site_name]} #{base_subject} ##{@order.number}" - end - - def attach_file(filename, file) - attachments[filename] = file if file.present? - end -end diff --git a/spec/mailers/order_mailer_from_spree_spec.rb b/spec/mailers/order_mailer_from_spree_spec.rb deleted file mode 100644 index 399c097fd43..00000000000 --- a/spec/mailers/order_mailer_from_spree_spec.rb +++ /dev/null @@ -1,120 +0,0 @@ -require 'spec_helper' -require 'email_spec' - -describe Spree::OrderMailer do - include EmailSpec::Helpers - include EmailSpec::Matchers - - let(:order) do - order = stub_model(Spree::Order) - product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) - variant = stub_model(Spree::Variant, :product => product) - price = stub_model(Spree::Price, :variant => variant, :amount => 5.00) - line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 4.99) - variant.stub(:default_price => price) - order.stub(:line_items => [line_item]) - order - end - - context ":from not set explicitly" do - it "falls back to spree config" do - message = Spree::OrderMailer.confirm_email(order) - message.from.should == [Spree::Config[:mails_from]] - end - end - - it "doesn't aggressively escape double quotes in confirmation body" do - confirmation_email = Spree::OrderMailer.confirm_email(order) - confirmation_email.body.should_not include(""") - end - - it "confirm_email accepts an order id as an alternative to an Order object" do - Spree::Order.should_receive(:find).with(order.id).and_return(order) - lambda { - confirmation_email = Spree::OrderMailer.confirm_email(order.id) - }.should_not raise_error - end - - it "cancel_email accepts an order id as an alternative to an Order object" do - Spree::Order.should_receive(:find).with(order.id).and_return(order) - lambda { - cancel_email = Spree::OrderMailer.cancel_email(order.id) - }.should_not raise_error - end - - context "only shows eligible adjustments in emails" do - before do - order.adjustments.create( - :label => "Eligible Adjustment", - :amount => 10, - :eligible => true - ) - - order.adjustments.create!( - :label => "Ineligible Adjustment", - :amount => -10, - :eligible => false - ) - end - - let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) } - let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } - - specify do - confirmation_email.body.should_not include("Ineligible Adjustment") - end - - specify do - cancel_email.body.should_not include("Ineligible Adjustment") - end - end - - context "displays unit costs from line item" do - # Regression test for #2772 - - # Tests mailer view spree/order_mailer/confirm_email.text.erb - specify do - confirmation_email = Spree::OrderMailer.confirm_email(order) - confirmation_email.body.should include("4.99") - confirmation_email.body.should_not include("5.00") - end - - # Tests mailer view spree/order_mailer/cancel_email.text.erb - specify do - cancel_email = Spree::OrderMailer.cancel_email(order) - cancel_email.body.should include("4.99") - cancel_email.body.should_not include("5.00") - end - end - - context "emails must be translatable" do - - context "pt-BR locale" do - before do - pt_br_confirm_mail = { :spree => { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } } } - pt_br_cancel_mail = { :spree => { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } } } - I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail - I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail - I18n.locale = :'pt-BR' - end - - after do - I18n.locale = I18n.default_locale - end - - context "confirm_email" do - specify do - confirmation_email = Spree::OrderMailer.confirm_email(order) - confirmation_email.body.should include("Caro Cliente,") - end - end - - context "cancel_email" do - specify do - cancel_email = Spree::OrderMailer.cancel_email(order) - cancel_email.body.should include("Resumo da Pedido [CANCELADA]") - end - end - end - end -end diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index deb5230f817..3af2b503396 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -3,6 +3,116 @@ describe Spree::OrderMailer do include OpenFoodNetwork::EmailHelper + contect "original spree specs" do + let(:order) do + order = stub_model(Spree::Order) + product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) + variant = stub_model(Spree::Variant, :product => product) + price = stub_model(Spree::Price, :variant => variant, :amount => 5.00) + line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 4.99) + variant.stub(:default_price => price) + order.stub(:line_items => [line_item]) + order + end + + context ":from not set explicitly" do + it "falls back to spree config" do + message = Spree::OrderMailer.confirm_email_for_customer(order) + message.from.should == [Spree::Config[:mails_from]] + end + end + + it "doesn't aggressively escape double quotes in confirmation body" do + confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) + confirmation_email.body.should_not include(""") + end + + it "confirm_email_for_customer accepts an order id as an alternative to an Order object" do + Spree::Order.should_receive(:find).with(order.id).and_return(order) + lambda { + confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order.id) + }.should_not raise_error + end + + it "cancel_email accepts an order id as an alternative to an Order object" do + Spree::Order.should_receive(:find).with(order.id).and_return(order) + lambda { + cancel_email = Spree::OrderMailer.cancel_email(order.id) + }.should_not raise_error + end + + context "only shows eligible adjustments in emails" do + before do + order.adjustments.create( + :label => "Eligible Adjustment", + :amount => 10, + :eligible => true + ) + + order.adjustments.create!( + :label => "Ineligible Adjustment", + :amount => -10, + :eligible => false + ) + end + + let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) } + let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } + + specify do + confirmation_email.body.should_not include("Ineligible Adjustment") + end + + specify do + cancel_email.body.should_not include("Ineligible Adjustment") + end + end + + context "displays unit costs from line item" do + specify do + confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) + confirmation_email.body.should include("4.99") + confirmation_email.body.should_not include("5.00") + end + + specify do + cancel_email = Spree::OrderMailer.cancel_email(order) + cancel_email.body.should include("4.99") + cancel_email.body.should_not include("5.00") + end + end + + context "emails must be translatable" do + context "pt-BR locale" do + before do + pt_br_confirm_mail = { :spree => { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } } } + pt_br_cancel_mail = { :spree => { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } } } + I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail + I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail + I18n.locale = :'pt-BR' + end + + after do + I18n.locale = I18n.default_locale + end + + context "confirm_email" do + specify do + confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) + confirmation_email.body.should include("Caro Cliente,") + end + end + + context "cancel_email" do + specify do + cancel_email = Spree::OrderMailer.cancel_email(order) + cancel_email.body.should include("Resumo da Pedido [CANCELADA]") + end + end + end + end + end + describe "order confimation" do let(:bill_address) { create(:address) } let(:distributor_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") } From 5162964936781fe4a49cc060333795cd6715fd25 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 13:46:01 +0100 Subject: [PATCH 03/10] Fix easy rubocop issues --- app/mailers/spree/base_mailer.rb | 2 ++ app/mailers/spree/order_mailer.rb | 2 ++ app/mailers/spree/shipment_mailer.rb | 5 ++++- app/mailers/spree/test_mailer.rb | 2 ++ spec/mailers/order_mailer_spec.rb | 30 +++++++++++++++------------- spec/mailers/shipment_mailer_spec.rb | 18 ++++++++++------- spec/mailers/test_mailer_spec.rb | 4 +++- 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/app/mailers/spree/base_mailer.rb b/app/mailers/spree/base_mailer.rb index 5d6e616b1f3..d0f86d8aceb 100644 --- a/app/mailers/spree/base_mailer.rb +++ b/app/mailers/spree/base_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class BaseMailer < ActionMailer::Base # Inline stylesheets diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index cb90f25b688..4cd6676c59d 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class OrderMailer < BaseMailer helper HtmlHelper diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index d9f00671a1d..ccbac24efe9 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + module Spree class ShipmentMailer < BaseMailer def shipped_email(shipment, resend = false) @shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment) subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{Spree.t('shipment_mailer.shipped_email.subject')} ##{@shipment.order.number}" + base_subject = Spree.t('shipment_mailer.shipped_email.subject') + subject += "#{Spree::Config[:site_name]} #{base_subject} ##{@shipment.order.number}" mail(to: @shipment.order.email, from: from_address, subject: subject) end end diff --git a/app/mailers/spree/test_mailer.rb b/app/mailers/spree/test_mailer.rb index 8a547427226..1f41f55a52f 100644 --- a/app/mailers/spree/test_mailer.rb +++ b/app/mailers/spree/test_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Spree class TestMailer < BaseMailer def test_email(user) diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 3af2b503396..2261edc8024 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Spree::OrderMailer do @@ -6,12 +8,12 @@ contect "original spree specs" do let(:order) do order = stub_model(Spree::Order) - product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) - variant = stub_model(Spree::Variant, :product => product) - price = stub_model(Spree::Price, :variant => variant, :amount => 5.00) - line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 4.99) - variant.stub(:default_price => price) - order.stub(:line_items => [line_item]) + product = stub_model(Spree::Product, name: %{The "BEST" product}) + variant = stub_model(Spree::Variant, product: product) + price = stub_model(Spree::Price, variant: variant, amount: 5.00) + line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 4.99) + variant.stub(default_price: price) + order.stub(line_items: [line_item]) order end @@ -44,15 +46,15 @@ context "only shows eligible adjustments in emails" do before do order.adjustments.create( - :label => "Eligible Adjustment", - :amount => 10, - :eligible => true + label: "Eligible Adjustment", + amount: 10, + eligible: true ) order.adjustments.create!( - :label => "Ineligible Adjustment", - :amount => -10, - :eligible => false + label: "Ineligible Adjustment", + amount: -10, + eligible: false ) end @@ -85,8 +87,8 @@ context "emails must be translatable" do context "pt-BR locale" do before do - pt_br_confirm_mail = { :spree => { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } } } - pt_br_cancel_mail = { :spree => { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } } } + pt_br_confirm_mail = { spree: { order_mailer: { confirm_email: { dear_customer: 'Caro Cliente,' } } } } + pt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } } I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail I18n.locale = :'pt-BR' diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb index c7a0da61728..994ec0b871e 100644 --- a/spec/mailers/shipment_mailer_spec.rb +++ b/spec/mailers/shipment_mailer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'email_spec' @@ -7,12 +9,12 @@ let(:shipment) do order = stub_model(Spree::Order) - product = stub_model(Spree::Product, :name => %Q{The "BEST" product}) - variant = stub_model(Spree::Variant, :product => product) - line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 5) + product = stub_model(Spree::Product, name: %{The "BEST" product}) + variant = stub_model(Spree::Variant, product: product) + line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 5) shipment = stub_model(Spree::Shipment) - shipment.stub(:line_items => [line_item], :order => order) - shipment.stub(:tracking_url => "TRACK_ME") + shipment.stub(line_items: [line_item], order: order) + shipment.stub(tracking_url: "TRACK_ME") shipment end @@ -26,7 +28,7 @@ # Regression test for #2196 it "doesn't include out of stock in the email body" do shipment_email = Spree::ShipmentMailer.shipped_email(shipment) - shipment_email.body.should_not include(%Q{Out of Stock}) + shipment_email.body.should_not include(%{Out of Stock}) end it "shipment_email accepts an shipment id as an alternative to an Shipment object" do @@ -40,7 +42,9 @@ context "shipped_email" do context "pt-BR locale" do before do - pt_br_shipped_email = { :spree => { :shipment_mailer => { :shipped_email => { :dear_customer => 'Caro Cliente,' } } } } + pt_br_shipped_email = { + spree: { shipment_mailer: { shipped_email: { dear_customer: 'Caro Cliente,' } } } + } I18n.backend.store_translations :'pt-BR', pt_br_shipped_email I18n.locale = :'pt-BR' end diff --git a/spec/mailers/test_mailer_spec.rb b/spec/mailers/test_mailer_spec.rb index 6ed147ad10a..b7580405475 100644 --- a/spec/mailers/test_mailer_spec.rb +++ b/spec/mailers/test_mailer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'email_spec' @@ -20,4 +22,4 @@ test_email = Spree::TestMailer.test_email(user.id) }.should_not raise_error end -end \ No newline at end of file +end From e96d9c1f45498b922e695b5ef11be63e7de9a660 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 14:19:19 +0100 Subject: [PATCH 04/10] Fix mailer specs brought from spree_core --- spec/mailers/order_mailer_spec.rb | 118 +++++++++------------------ spec/mailers/shipment_mailer_spec.rb | 45 ++-------- spec/mailers/test_mailer_spec.rb | 10 +-- 3 files changed, 52 insertions(+), 121 deletions(-) diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 2261edc8024..ffa6f9433b0 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -5,113 +5,75 @@ describe Spree::OrderMailer do include OpenFoodNetwork::EmailHelper - contect "original spree specs" do - let(:order) do - order = stub_model(Spree::Order) - product = stub_model(Spree::Product, name: %{The "BEST" product}) - variant = stub_model(Spree::Variant, product: product) - price = stub_model(Spree::Price, variant: variant, amount: 5.00) - line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 4.99) - variant.stub(default_price: price) - order.stub(line_items: [line_item]) - order - end + context "basic behaviour" do + let(:order) { build(:order_with_totals_and_distribution) } context ":from not set explicitly" do it "falls back to spree config" do message = Spree::OrderMailer.confirm_email_for_customer(order) - message.from.should == [Spree::Config[:mails_from]] + expect(message.from).to eq [Spree::Config[:mails_from]] end end it "doesn't aggressively escape double quotes in confirmation body" do confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) - confirmation_email.body.should_not include(""") + expect(confirmation_email.body).to_not include(""") end it "confirm_email_for_customer accepts an order id as an alternative to an Order object" do Spree::Order.should_receive(:find).with(order.id).and_return(order) - lambda { + expect { confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order.id) - }.should_not raise_error + }.to_not raise_error end it "cancel_email accepts an order id as an alternative to an Order object" do Spree::Order.should_receive(:find).with(order.id).and_return(order) - lambda { + expect { cancel_email = Spree::OrderMailer.cancel_email(order.id) - }.should_not raise_error + }.to_not raise_error end + end - context "only shows eligible adjustments in emails" do - before do - order.adjustments.create( - label: "Eligible Adjustment", - amount: 10, - eligible: true - ) - - order.adjustments.create!( - label: "Ineligible Adjustment", - amount: -10, - eligible: false - ) - end + context "only shows eligible adjustments in emails" do + let(:order) { create(:order_with_totals_and_distribution) } - let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) } - let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } + before do + order.adjustments.create( + label: "Eligible Adjustment", + amount: 10, + eligible: true + ) + + order.adjustments.create!( + label: "Ineligible Adjustment", + amount: 0, + ) + end - specify do - confirmation_email.body.should_not include("Ineligible Adjustment") - end + let!(:confirmation_email) { Spree::OrderMailer.confirm_email_for_customer(order) } + let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) } - specify do - cancel_email.body.should_not include("Ineligible Adjustment") - end + specify do + expect(confirmation_email.body).to_not include("Ineligible Adjustment") end - context "displays unit costs from line item" do - specify do - confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) - confirmation_email.body.should include("4.99") - confirmation_email.body.should_not include("5.00") - end + specify do + expect(cancel_email.body).to_not include("Ineligible Adjustment") + end + end - specify do - cancel_email = Spree::OrderMailer.cancel_email(order) - cancel_email.body.should include("4.99") - cancel_email.body.should_not include("5.00") - end + context "displays line item price" do + let(:order) { create(:order_with_totals_and_distribution) } + + specify do + confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) + expect(confirmation_email.body).to include("3.00") end - context "emails must be translatable" do - context "pt-BR locale" do - before do - pt_br_confirm_mail = { spree: { order_mailer: { confirm_email: { dear_customer: 'Caro Cliente,' } } } } - pt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } } - I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail - I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail - I18n.locale = :'pt-BR' - end - - after do - I18n.locale = I18n.default_locale - end - - context "confirm_email" do - specify do - confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order) - confirmation_email.body.should include("Caro Cliente,") - end - end - - context "cancel_email" do - specify do - cancel_email = Spree::OrderMailer.cancel_email(order) - cancel_email.body.should include("Resumo da Pedido [CANCELADA]") - end - end - end + specify do + cancel_email = Spree::OrderMailer.cancel_email(order) + expect(cancel_email.body).to include("3.00") end end diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb index 994ec0b871e..8a3fadb0f64 100644 --- a/spec/mailers/shipment_mailer_spec.rb +++ b/spec/mailers/shipment_mailer_spec.rb @@ -1,18 +1,14 @@ # frozen_string_literal: true require 'spec_helper' -require 'email_spec' describe Spree::ShipmentMailer do - include EmailSpec::Helpers - include EmailSpec::Matchers - let(:shipment) do - order = stub_model(Spree::Order) - product = stub_model(Spree::Product, name: %{The "BEST" product}) - variant = stub_model(Spree::Variant, product: product) - line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 5) - shipment = stub_model(Spree::Shipment) + order = build(:order) + product = build(:product, name: %{The "BEST" product}) + variant = build(:variant, product: product) + line_item = build(:line_item, variant: variant, order: order, quantity: 1, price: 5) + shipment = build(:shipment) shipment.stub(line_items: [line_item], order: order) shipment.stub(tracking_url: "TRACK_ME") shipment @@ -21,43 +17,20 @@ context ":from not set explicitly" do it "falls back to spree config" do message = Spree::ShipmentMailer.shipped_email(shipment) - message.from.should == [Spree::Config[:mails_from]] + expect(message.from).to eq [Spree::Config[:mails_from]] end end # Regression test for #2196 it "doesn't include out of stock in the email body" do shipment_email = Spree::ShipmentMailer.shipped_email(shipment) - shipment_email.body.should_not include(%{Out of Stock}) + expect(shipment_email.body).to_not include(%{Out of Stock}) end it "shipment_email accepts an shipment id as an alternative to an Shipment object" do Spree::Shipment.should_receive(:find).with(shipment.id).and_return(shipment) - lambda { + expect { shipped_email = Spree::ShipmentMailer.shipped_email(shipment.id) - }.should_not raise_error - end - - context "emails must be translatable" do - context "shipped_email" do - context "pt-BR locale" do - before do - pt_br_shipped_email = { - spree: { shipment_mailer: { shipped_email: { dear_customer: 'Caro Cliente,' } } } - } - I18n.backend.store_translations :'pt-BR', pt_br_shipped_email - I18n.locale = :'pt-BR' - end - - after do - I18n.locale = I18n.default_locale - end - - specify do - shipped_email = Spree::ShipmentMailer.shipped_email(shipment) - shipped_email.body.should include("Caro Cliente,") - end - end - end + }.to_not raise_error end end diff --git a/spec/mailers/test_mailer_spec.rb b/spec/mailers/test_mailer_spec.rb index b7580405475..a7c58937c42 100644 --- a/spec/mailers/test_mailer_spec.rb +++ b/spec/mailers/test_mailer_spec.rb @@ -1,25 +1,21 @@ # frozen_string_literal: true require 'spec_helper' -require 'email_spec' describe Spree::TestMailer do - include EmailSpec::Helpers - include EmailSpec::Matchers - let(:user) { create(:user) } context ":from not set explicitly" do it "falls back to spree config" do message = Spree::TestMailer.test_email(user) - message.from.should == [Spree::Config[:mails_from]] + expect(message.from).to eq [Spree::Config[:mails_from]] end end it "confirm_email accepts a user id as an alternative to a User object" do Spree.user_class.should_receive(:find).with(user.id).and_return(user) - lambda { + expect { test_email = Spree::TestMailer.test_email(user.id) - }.should_not raise_error + }.to_not raise_error end end From 5835a0ee3abede108fe64af7cbbced947c84699e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 14:20:30 +0100 Subject: [PATCH 05/10] Transpec mailer specs --- spec/mailers/order_mailer_spec.rb | 4 ++-- spec/mailers/shipment_mailer_spec.rb | 6 +++--- spec/mailers/test_mailer_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index ffa6f9433b0..516c7f1d12d 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -21,14 +21,14 @@ end it "confirm_email_for_customer accepts an order id as an alternative to an Order object" do - Spree::Order.should_receive(:find).with(order.id).and_return(order) + expect(Spree::Order).to receive(:find).with(order.id).and_return(order) expect { confirmation_email = Spree::OrderMailer.confirm_email_for_customer(order.id) }.to_not raise_error end it "cancel_email accepts an order id as an alternative to an Order object" do - Spree::Order.should_receive(:find).with(order.id).and_return(order) + expect(Spree::Order).to receive(:find).with(order.id).and_return(order) expect { cancel_email = Spree::OrderMailer.cancel_email(order.id) }.to_not raise_error diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb index 8a3fadb0f64..e9525361305 100644 --- a/spec/mailers/shipment_mailer_spec.rb +++ b/spec/mailers/shipment_mailer_spec.rb @@ -9,8 +9,8 @@ variant = build(:variant, product: product) line_item = build(:line_item, variant: variant, order: order, quantity: 1, price: 5) shipment = build(:shipment) - shipment.stub(line_items: [line_item], order: order) - shipment.stub(tracking_url: "TRACK_ME") + allow(shipment).to receive_messages(line_items: [line_item], order: order) + allow(shipment).to receive_messages(tracking_url: "TRACK_ME") shipment end @@ -28,7 +28,7 @@ end it "shipment_email accepts an shipment id as an alternative to an Shipment object" do - Spree::Shipment.should_receive(:find).with(shipment.id).and_return(shipment) + expect(Spree::Shipment).to receive(:find).with(shipment.id).and_return(shipment) expect { shipped_email = Spree::ShipmentMailer.shipped_email(shipment.id) }.to_not raise_error diff --git a/spec/mailers/test_mailer_spec.rb b/spec/mailers/test_mailer_spec.rb index a7c58937c42..71087a9f367 100644 --- a/spec/mailers/test_mailer_spec.rb +++ b/spec/mailers/test_mailer_spec.rb @@ -13,7 +13,7 @@ end it "confirm_email accepts a user id as an alternative to a User object" do - Spree.user_class.should_receive(:find).with(user.id).and_return(user) + expect(Spree.user_class).to receive(:find).with(user.id).and_return(user) expect { test_email = Spree::TestMailer.test_email(user.id) }.to_not raise_error From 55f160c309ca9518abaf7857d1c27514600e5f83 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 14:23:09 +0100 Subject: [PATCH 06/10] Bring test and shipment email templates from spree_core --- .../spree/shipment_mailer/shipped_email.text.erb | 16 ++++++++++++++++ app/views/spree/test_mailer/test_email.text.erb | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 app/views/spree/shipment_mailer/shipped_email.text.erb create mode 100644 app/views/spree/test_mailer/test_email.text.erb diff --git a/app/views/spree/shipment_mailer/shipped_email.text.erb b/app/views/spree/shipment_mailer/shipped_email.text.erb new file mode 100644 index 00000000000..425df7aef2e --- /dev/null +++ b/app/views/spree/shipment_mailer/shipped_email.text.erb @@ -0,0 +1,16 @@ +<%= Spree.t('shipment_mailer.shipped_email.dear_customer') %> + +<%= Spree.t('shipment_mailer.shipped_email.instructions') %> + +============================================================ +<%= Spree.t('shipment_mailer.shipped_email.shipment_summary') %> +============================================================ +<% @shipment.manifest.each do |item| %> + <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text %> +<% end %> +============================================================ + +<%= Spree.t('shipment_mailer.shipped_email.track_information', :tracking => @shipment.tracking) if @shipment.tracking %> +<%= Spree.t('shipment_mailer.shipped_email.track_link', :url => @shipment.tracking_url) if @shipment.tracking_url %> + +<%= Spree.t('shipment_mailer.shipped_email.thanks') %> diff --git a/app/views/spree/test_mailer/test_email.text.erb b/app/views/spree/test_mailer/test_email.text.erb new file mode 100644 index 00000000000..9944b6faef4 --- /dev/null +++ b/app/views/spree/test_mailer/test_email.text.erb @@ -0,0 +1,4 @@ +<%= t('test_mailer.test_email.greeting') %> +================ + +<%= t('test_mailer.test_email.message') %> From f66538d2cb584d176aa009cadcfd36cf408bcbc9 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 14:26:05 +0100 Subject: [PATCH 07/10] Convert test and shipment email templates to haml --- .../shipment_mailer/shipped_email.html.haml | 19 +++++++++++++++++++ .../shipment_mailer/shipped_email.text.erb | 16 ---------------- .../spree/test_mailer/test_email.html.haml | 4 ++++ .../spree/test_mailer/test_email.text.erb | 4 ---- 4 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 app/views/spree/shipment_mailer/shipped_email.html.haml delete mode 100644 app/views/spree/shipment_mailer/shipped_email.text.erb create mode 100644 app/views/spree/test_mailer/test_email.html.haml delete mode 100644 app/views/spree/test_mailer/test_email.text.erb diff --git a/app/views/spree/shipment_mailer/shipped_email.html.haml b/app/views/spree/shipment_mailer/shipped_email.html.haml new file mode 100644 index 00000000000..96aa8403db5 --- /dev/null +++ b/app/views/spree/shipment_mailer/shipped_email.html.haml @@ -0,0 +1,19 @@ += Spree.t('shipment_mailer.shipped_email.dear_customer') + += Spree.t('shipment_mailer.shipped_email.instructions') + += "============================================================" += Spree.t('shipment_mailer.shipped_email.shipment_summary') += "============================================================" +- @shipment.manifest.each do |item| + = item.variant.sku + = item.variant.product.name + = item.variant.options_text += "============================================================" + +- if @shipment.tracking + = Spree.t('shipment_mailer.shipped_email.track_information', tracking: @shipment.tracking) +- if @shipment.tracking_url + = Spree.t('shipment_mailer.shipped_email.track_link', url: @shipment.tracking_url) + += Spree.t('shipment_mailer.shipped_email.thanks') diff --git a/app/views/spree/shipment_mailer/shipped_email.text.erb b/app/views/spree/shipment_mailer/shipped_email.text.erb deleted file mode 100644 index 425df7aef2e..00000000000 --- a/app/views/spree/shipment_mailer/shipped_email.text.erb +++ /dev/null @@ -1,16 +0,0 @@ -<%= Spree.t('shipment_mailer.shipped_email.dear_customer') %> - -<%= Spree.t('shipment_mailer.shipped_email.instructions') %> - -============================================================ -<%= Spree.t('shipment_mailer.shipped_email.shipment_summary') %> -============================================================ -<% @shipment.manifest.each do |item| %> - <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text %> -<% end %> -============================================================ - -<%= Spree.t('shipment_mailer.shipped_email.track_information', :tracking => @shipment.tracking) if @shipment.tracking %> -<%= Spree.t('shipment_mailer.shipped_email.track_link', :url => @shipment.tracking_url) if @shipment.tracking_url %> - -<%= Spree.t('shipment_mailer.shipped_email.thanks') %> diff --git a/app/views/spree/test_mailer/test_email.html.haml b/app/views/spree/test_mailer/test_email.html.haml new file mode 100644 index 00000000000..024e6cab4cb --- /dev/null +++ b/app/views/spree/test_mailer/test_email.html.haml @@ -0,0 +1,4 @@ += t('test_mailer.test_email.greeting') += "================" + += t('test_mailer.test_email.message') diff --git a/app/views/spree/test_mailer/test_email.text.erb b/app/views/spree/test_mailer/test_email.text.erb deleted file mode 100644 index 9944b6faef4..00000000000 --- a/app/views/spree/test_mailer/test_email.text.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= t('test_mailer.test_email.greeting') %> -================ - -<%= t('test_mailer.test_email.message') %> From 646f48f0afa32aa58b8e9bc32716e5c504a0fcc5 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Jul 2020 14:32:47 +0100 Subject: [PATCH 08/10] Add translation keys for test and shipment emails and make them lazy lookups --- app/mailers/spree/base_mailer.rb | 1 - app/mailers/spree/shipment_mailer.rb | 2 +- app/mailers/spree/test_mailer.rb | 2 +- .../shipment_mailer/shipped_email.html.haml | 12 +++--- .../spree/test_mailer/test_email.html.haml | 4 +- config/locales/en.yml | 38 +++++++++++++------ 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/app/mailers/spree/base_mailer.rb b/app/mailers/spree/base_mailer.rb index d0f86d8aceb..fb46bf54bc9 100644 --- a/app/mailers/spree/base_mailer.rb +++ b/app/mailers/spree/base_mailer.rb @@ -5,7 +5,6 @@ class BaseMailer < ActionMailer::Base # Inline stylesheets include Roadie::Rails::Automatic - # Define layout layout 'mailer' def from_address diff --git a/app/mailers/spree/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb index ccbac24efe9..3b25885f81e 100644 --- a/app/mailers/spree/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -5,7 +5,7 @@ class ShipmentMailer < BaseMailer def shipped_email(shipment, resend = false) @shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment) subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '') - base_subject = Spree.t('shipment_mailer.shipped_email.subject') + base_subject = t('spree.shipment_mailer.shipped_email.subject') subject += "#{Spree::Config[:site_name]} #{base_subject} ##{@shipment.order.number}" mail(to: @shipment.order.email, from: from_address, subject: subject) end diff --git a/app/mailers/spree/test_mailer.rb b/app/mailers/spree/test_mailer.rb index 1f41f55a52f..316de403411 100644 --- a/app/mailers/spree/test_mailer.rb +++ b/app/mailers/spree/test_mailer.rb @@ -4,7 +4,7 @@ module Spree class TestMailer < BaseMailer def test_email(user) recipient = user.respond_to?(:id) ? user : Spree.user_class.find(user) - subject = "#{Spree::Config[:site_name]} #{Spree.t('test_mailer.test_email.subject')}" + subject = "#{Spree::Config[:site_name]} #{t('spree.test_mailer.test_email.subject')}" mail(to: recipient.email, from: from_address, subject: subject) end end diff --git a/app/views/spree/shipment_mailer/shipped_email.html.haml b/app/views/spree/shipment_mailer/shipped_email.html.haml index 96aa8403db5..04c8368787f 100644 --- a/app/views/spree/shipment_mailer/shipped_email.html.haml +++ b/app/views/spree/shipment_mailer/shipped_email.html.haml @@ -1,9 +1,9 @@ -= Spree.t('shipment_mailer.shipped_email.dear_customer') += t('.dear_customer') -= Spree.t('shipment_mailer.shipped_email.instructions') += t('.instructions') = "============================================================" -= Spree.t('shipment_mailer.shipped_email.shipment_summary') += t('.shipment_summary') = "============================================================" - @shipment.manifest.each do |item| = item.variant.sku @@ -12,8 +12,8 @@ = "============================================================" - if @shipment.tracking - = Spree.t('shipment_mailer.shipped_email.track_information', tracking: @shipment.tracking) + = t('.track_information', tracking: @shipment.tracking) - if @shipment.tracking_url - = Spree.t('shipment_mailer.shipped_email.track_link', url: @shipment.tracking_url) + = t('.track_link', url: @shipment.tracking_url) -= Spree.t('shipment_mailer.shipped_email.thanks') += t('.thanks') diff --git a/app/views/spree/test_mailer/test_email.html.haml b/app/views/spree/test_mailer/test_email.html.haml index 024e6cab4cb..6f9e2e771c8 100644 --- a/app/views/spree/test_mailer/test_email.html.haml +++ b/app/views/spree/test_mailer/test_email.html.haml @@ -1,4 +1,4 @@ -= t('test_mailer.test_email.greeting') += t('.greeting') = "================" -= t('test_mailer.test_email.message') += t('.message') diff --git a/config/locales/en.yml b/config/locales/en.yml index 3726167337b..7cd051f0fb1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3508,6 +3508,32 @@ See the %{link} to find out more about %{sitename}'s features and to start using invoice_email: hi: "Hi %{name}" invoice_attached_text: Please find attached an invoice for your recent order from + user_mailer: + reset_password_instructions: + request_sent_text: | + A request to reset your password has been made. + If you did not make this request, simply ignore this email. + link_text: > + If you did make this request just click the link below: + issue_text: | + If the above URL does not work try copying and pasting it into your browser. + If you continue to have problems please feel free to contact us. + confirmation_instructions: + subject: "Please confirm your OFN account" + shipment_mailer: + shipped_email: + dear_customer: "Dear Customer," + instructions: "Your order has been shipped" + shipment_summary: "Shipment Summary" + subject: "Shipment Notification" + thanks: "Thank you for your business." + track_information: ! "Tracking Information: %{tracking}" + track_link: ! "Tracking Link: %{url}" + test_mailer: + test_email: + greeting: "Congratulations!" + message: "If you have received this email, then your email settings are correct." + subject: "Test Mail" order_state: address: address adjustments: adjustments @@ -3529,18 +3555,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using ended: ended paused: paused canceled: cancelled - user_mailer: - reset_password_instructions: - request_sent_text: | - A request to reset your password has been made. - If you did not make this request, simply ignore this email. - link_text: > - If you did make this request just click the link below: - issue_text: | - If the above URL does not work try copying and pasting it into your browser. - If you continue to have problems please feel free to contact us. - confirmation_instructions: - subject: Please confirm your OFN account users: form: account_settings: Account Settings From 6e57e1ad564b93b3193e2c070861074241db8958 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 3 Aug 2020 16:09:37 +0100 Subject: [PATCH 09/10] Fix conflict between unused Spree::CheckoutHelper in spree_core and the required ::CheckoutHelper in OFN The OFN checkoutHelper was not being included and instead the Spree::CheckoutHelper, that doesnt have the necessary helpers, was used --- app/mailers/spree/order_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index 4cd6676c59d..ce9b79874e7 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -3,7 +3,7 @@ module Spree class OrderMailer < BaseMailer helper HtmlHelper - helper CheckoutHelper + helper ::CheckoutHelper helper SpreeCurrencyHelper helper OrderHelper include I18nHelper From 425901fa7ac7409955ebacac167fa4c8f7d799d6 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 3 Aug 2020 16:43:11 +0100 Subject: [PATCH 10/10] Add some paragraphs and breaklines to the tempalte that used to be text and is now html This template needs to be revisited, this is just a quick fix --- .../shipment_mailer/shipped_email.html.haml | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/app/views/spree/shipment_mailer/shipped_email.html.haml b/app/views/spree/shipment_mailer/shipped_email.html.haml index 04c8368787f..c5675a69750 100644 --- a/app/views/spree/shipment_mailer/shipped_email.html.haml +++ b/app/views/spree/shipment_mailer/shipped_email.html.haml @@ -1,19 +1,30 @@ -= t('.dear_customer') +%p + = t('.dear_customer') +%p + = t('.instructions') -= t('.instructions') +%p + = "============================================================" + %br + = t('.shipment_summary') + %br + = "============================================================" -= "============================================================" -= t('.shipment_summary') -= "============================================================" -- @shipment.manifest.each do |item| - = item.variant.sku - = item.variant.product.name - = item.variant.options_text -= "============================================================" +%p + - @shipment.manifest.each do |item| + = item.variant.sku + = item.variant.product.name + = item.variant.options_text + %br + = "============================================================" - if @shipment.tracking - = t('.track_information', tracking: @shipment.tracking) + %p + = t('.track_information', tracking: @shipment.tracking) + - if @shipment.tracking_url - = t('.track_link', url: @shipment.tracking_url) + %p + = t('.track_link', url: @shipment.tracking_url) -= t('.thanks') +%p + = t('.thanks')