|
15 | 15 | end |
16 | 16 |
|
17 | 17 | let :sponsor do |
18 | | - FactoryBot.create(:sponsor, :pending, email: 'allyadams@outlook.com', petition: petition) |
| 18 | + FactoryBot.create(:sponsor, :pending, name: "Ally Adams", email: 'allyadams@outlook.com', petition: petition) |
19 | 19 | end |
20 | 20 |
|
21 | 21 | describe "#petition_and_email_confirmation_for_sponsor" do |
|
75 | 75 | end |
76 | 76 | end |
77 | 77 | end |
| 78 | + |
| 79 | + describe "#sponsor_signed_email_on_threshold" do |
| 80 | + subject(:mail) { described_class.sponsor_signed_email_on_threshold(petition, sponsor) } |
| 81 | + |
| 82 | + before do |
| 83 | + allow(petition).to receive_message_chain(:sponsors, :validated, :count).and_return(5) |
| 84 | + end |
| 85 | + |
| 86 | + shared_examples_for "a sponsor signed on threshold email" do |
| 87 | + it "has the correct subject" do |
| 88 | + expect(mail.subject).to eq("We’re checking your petition") |
| 89 | + end |
| 90 | + |
| 91 | + it "sends it only to the creator" do |
| 92 | + expect(mail.to).to eq(%w[bazbutler@gmail.com]) |
| 93 | + expect(mail.cc).to be_blank |
| 94 | + expect(mail.bcc).to be_blank |
| 95 | + end |
| 96 | + |
| 97 | + it "includes the creator's name in the body" do |
| 98 | + expect(mail).to have_body_text(%r[Barry Butler]) |
| 99 | + end |
| 100 | + |
| 101 | + it "includes the sponsor's name in the body" do |
| 102 | + expect(mail).to have_body_text(%r[Ally Adams]) |
| 103 | + end |
| 104 | + |
| 105 | + it "includes the petition action" do |
| 106 | + expect(mail).to have_body_text(%r[Allow organic vegetable vans to use red diesel]) |
| 107 | + end |
| 108 | + |
| 109 | + it "doesn't include the petition background" do |
| 110 | + expect(mail).not_to have_body_text(%r[Add vans to permitted users of red diesel]) |
| 111 | + end |
| 112 | + |
| 113 | + it "doesn't include the petition additional details" do |
| 114 | + expect(mail).not_to have_body_text(%r[To promote organic vegetables]) |
| 115 | + end |
| 116 | + |
| 117 | + it "includes the sponsor count" do |
| 118 | + expect(mail).to have_body_text(%r[5 people have supported your petition so far]) |
| 119 | + end |
| 120 | + |
| 121 | + it "tells the creator that the petition is being checked" do |
| 122 | + expect(mail).to have_body_text(%r[We’re checking your petition to make sure it meets the petition standards]) |
| 123 | + end |
| 124 | + end |
| 125 | + |
| 126 | + context "before the Christmas period" do |
| 127 | + around do |example| |
| 128 | + travel_to("2017-12-21") { example.run } |
| 129 | + end |
| 130 | + |
| 131 | + it_behaves_like "a sponsor signed on threshold email" |
| 132 | + |
| 133 | + it "doesn't include the moderation delay message" do |
| 134 | + expect(mail).not_to have_body_text(%r[over the Christmas period it may take us a little longer than usual]) |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context "during the Christmas period" do |
| 139 | + around do |example| |
| 140 | + travel_to("2017-12-26") { example.run } |
| 141 | + end |
| 142 | + |
| 143 | + it_behaves_like "a sponsor signed on threshold email" |
| 144 | + |
| 145 | + it "includes the moderation delay message" do |
| 146 | + expect(mail).to have_body_text(%r[over the Christmas period it may take us a little longer than usual]) |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + context "after the Christmas period" do |
| 151 | + around do |example| |
| 152 | + travel_to("2018-01-05") { example.run } |
| 153 | + end |
| 154 | + |
| 155 | + it_behaves_like "a sponsor signed on threshold email" |
| 156 | + |
| 157 | + it "doesn't include the moderation delay message" do |
| 158 | + expect(mail).not_to have_body_text(%r[over the Christmas period it may take us a little longer than usual]) |
| 159 | + end |
| 160 | + end |
| 161 | + end |
78 | 162 | end |
0 commit comments