forked from eliotsykes/rspec-rails-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscription_mailer_spec.rb
57 lines (45 loc) · 1.75 KB
/
subscription_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
require "rails_helper"
RSpec.describe SubscriptionMailer, :type => :mailer do
describe ".send_confirmation_request!(subscription)" do
before do
@subscription = Subscription.create!(
email: "[email protected]",
confirmation_token: "this-is-a-confirmation-token"
)
end
it "calls the error-sensitive deliver_now!" do
delivery = double
expect(delivery).to receive(:deliver_now!).with(no_args)
expect(SubscriptionMailer)
.to receive(:confirmation_request)
.with(@subscription)
.and_return(delivery)
SubscriptionMailer.send_confirmation_request!(@subscription)
end
it "has appropriate subject" do
mail = SubscriptionMailer.send_confirmation_request!(@subscription)
expect(mail).to have_subject("Please confirm")
end
it "sends from the default email" do
mail = SubscriptionMailer.send_confirmation_request!(@subscription)
expect(mail).to be_delivered_from("[email protected]")
end
it "sends to the subscriber" do
mail = SubscriptionMailer.send_confirmation_request!(@subscription)
expect(mail).to be_delivered_to("[email protected]")
end
context "HTML body" do
it "includes the confirm link" do
mail = SubscriptionMailer.send_confirmation_request!(@subscription)
anchor_html = %Q|<a href="#{confirm_subscription_url(@subscription)}">Confirm your subscription</a>|
expect(mail).to have_body_text(anchor_html)
end
end
context "plain text body" do
it "includes the confirm URL" do
mail = SubscriptionMailer.send_confirmation_request!(@subscription)
expect(mail.text_part).to have_body_text(confirm_subscription_url(@subscription))
end
end
end
end