forked from palkan/active_delivery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer_spec.rb
75 lines (56 loc) · 1.75 KB
/
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
# frozen_string_literal: true
require "spec_helper"
describe "ActionMailer line", skip: !defined?(ActionMailer) do
before do
module ::DeliveryTesting
class TestMailer < ActionMailer::Base
def do_something(*)
end
private
def do_nothing
end
end
class TestDelivery < ActiveDelivery::Base
end
end
end
after do
Object.send(:remove_const, :DeliveryTesting)
end
let(:delivery_class) { ::DeliveryTesting::TestDelivery }
let(:mailer_class) { ::DeliveryTesting::TestMailer }
describe ".mailer_class" do
it "infers mailer from delivery name" do
expect(delivery_class.mailer_class).to be_eql(mailer_class)
end
end
describe ".notify" do
let(:mailer_instance) { double("mailer") }
before { allow(mailer_class).to receive(:do_something).and_return(mailer_instance) }
describe ".notify" do
it "calls deliver_later on mailer instance" do
expect(mailer_instance).to receive(:deliver_later)
delivery_class.notify(:do_something)
end
it "do nothing when mailer doesn't have provided public method" do
delivery_class.notify(:do_nothing)
end
context "with arguments" do
it "process integer" do
expect(mailer_instance).to receive(:deliver_later)
delivery_class.notify(:do_something, 1)
end
it "process hash" do
expect(mailer_instance).to receive(:deliver_later)
delivery_class.notify(:do_something, { key: :value })
end
end
end
describe ".notify!" do
it "calls deliver_now on mailer instance" do
expect(mailer_instance).to receive(:deliver_now)
delivery_class.notify!(:do_something)
end
end
end
end