-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
order_mailer_spec.rb
122 lines (103 loc) · 4.09 KB
/
order_mailer_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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)
line_item = stub_model(Spree::LineItem, :variant => variant, :order => order, :quantity => 1, :price => 5)
variant.stub(:default_price => price)
order.stub(:line_items => [line_item])
order
end
before do
Spree::MailMethod.create!(
:environment => Rails.env,
:preferred_mails_from => "spree@example.com"
)
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}, :without_protection => true)
order.adjustments.create!({:label => "Ineligible Adjustment",
:amount => -10,
:eligible => false}, :without_protection => true)
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 "emails must be translatable" do
context "en locale" do
before do
en_confirm_mail = { :order_mailer => { :confirm_email => { :dear_customer => 'Dear Customer,' } } }
en_cancel_mail = { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Order Summary [CANCELED]' } } }
I18n.backend.store_translations :en, en_confirm_mail
I18n.backend.store_translations :en, en_cancel_mail
I18n.locale = :en
end
context "confirm_email" do
specify do
confirmation_email = Spree::OrderMailer.confirm_email(order)
confirmation_email.body.should include("Dear Customer,")
end
end
context "cancel_email" do
specify do
cancel_email = Spree::OrderMailer.cancel_email(order)
cancel_email.body.should include("Order Summary [CANCELED]")
end
end
end
context "pt-BR locale" do
before do
pt_br_confirm_mail = { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } }
pt_br_cancel_mail = { :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