|
24 | 24 | end |
25 | 25 |
|
26 | 26 | context 'a member receives a welcome email' do |
| 27 | + before do |
| 28 | + ActionMailer::Base.deliveries.clear |
| 29 | + end |
| 30 | + |
27 | 31 | scenario 'Subscribing to a coach mailing list for the first time sends a coach email to the user' do |
28 | 32 | coach_group = Fabricate(:coaches) |
29 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_coach) |
30 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_students) |
31 | 33 |
|
32 | 34 | visit subscriptions_path |
33 | 35 | click_on "#{coach_group.chapter.name}-coaches" |
| 36 | + |
| 37 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 38 | + expect(welcome_emails.count).to eq(1) |
| 39 | + expect(welcome_emails.first.body.encoded).to include('coach') |
34 | 40 | end |
35 | 41 |
|
36 | 42 | scenario 'Subscribing to a student mailing list for the first time sends a student email to the user' do |
37 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_student) |
38 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_coach) |
39 | | - |
40 | 43 | visit subscriptions_path |
41 | 44 | click_on "#{group.chapter.name}-students" |
| 45 | + |
| 46 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 47 | + expect(welcome_emails.count).to eq(1) |
| 48 | + expect(welcome_emails.first.body.encoded).to include('student') |
42 | 49 | end |
43 | 50 |
|
44 | 51 | scenario "Subscribing to a second coach mailing list doesn't send another mail" do |
45 | 52 | coach_groups = Fabricate.times(2, :coaches) |
46 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_coach).once |
47 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_students) |
48 | 53 |
|
49 | 54 | visit subscriptions_path |
50 | 55 | click_on "#{coach_groups[0].chapter.name}-coaches" |
| 56 | + ActionMailer::Base.deliveries.clear |
51 | 57 | click_on "#{coach_groups[1].chapter.name}-coaches" |
| 58 | + |
| 59 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 60 | + expect(welcome_emails.count).to eq(0) |
52 | 61 | end |
53 | 62 |
|
54 | 63 | scenario "Subscribing to a second student mailing list doesn't send another mail" do |
55 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_student).once |
56 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_coach) |
57 | 64 | extra_student_group = Fabricate(:students) |
58 | 65 |
|
59 | 66 | visit subscriptions_path |
60 | 67 | click_on "#{group.chapter.name}-students" |
| 68 | + ActionMailer::Base.deliveries.clear |
61 | 69 | click_on "#{extra_student_group.chapter.name}-students" |
| 70 | + |
| 71 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 72 | + expect(welcome_emails.count).to eq(0) |
62 | 73 | end |
63 | 74 |
|
64 | 75 | scenario "Unsubscribing and re-subscribing doesn't send a second mail to a coach" do |
65 | 76 | coach_group = Fabricate(:coaches) |
66 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_coach).once |
67 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_students) |
68 | 77 |
|
69 | 78 | visit subscriptions_path |
70 | 79 | click_on "#{coach_group.chapter.name}-coaches" |
| 80 | + ActionMailer::Base.deliveries.clear |
71 | 81 | click_on "#{coach_group.chapter.name}-coaches" |
72 | 82 | click_on "#{coach_group.chapter.name}-coaches" |
| 83 | + |
| 84 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 85 | + expect(welcome_emails.count).to eq(0) |
73 | 86 | end |
74 | 87 |
|
75 | 88 | scenario "Unsubscribing and re-subscribing doesn't send a second mail to a student" do |
76 | | - expect_any_instance_of(MemberMailer).to receive(:welcome_student).once |
77 | | - expect_any_instance_of(MemberMailer).not_to receive(:welcome_coach) |
78 | | - |
79 | 89 | visit subscriptions_path |
80 | 90 | click_on "#{group.chapter.name}-students" |
| 91 | + ActionMailer::Base.deliveries.clear |
81 | 92 | click_on "#{group.chapter.name}-students" |
82 | 93 | click_on "#{group.chapter.name}-students" |
| 94 | + |
| 95 | + welcome_emails = ActionMailer::Base.deliveries.select { |e| e.to.include?(member.email) } |
| 96 | + expect(welcome_emails.count).to eq(0) |
83 | 97 | end |
84 | 98 | end |
85 | 99 | end |
0 commit comments