|
80 | 80 | expect(mail.subject).to eq "Confirm your email address"
|
81 | 81 | end
|
82 | 82 |
|
| 83 | + it "notifies admin for new user" do |
| 84 | + email = FactoryBot.generate(:email) |
| 85 | + admin = FactoryBot.create(:admin_user) |
| 86 | + |
| 87 | + post users_newsletter_subscriptions_path, |
| 88 | + params: {user: {email: email, password: "password", password_confirmation: "password"}} |
| 89 | + |
| 90 | + perform_enqueued_jobs_and_subsequently_enqueued_jobs |
| 91 | + |
| 92 | + mail = find_mail_to(admin.email) |
| 93 | + |
| 94 | + expect(mail.subject).to eq "New Joy of Rails User" |
| 95 | + end |
| 96 | + |
83 | 97 | it "disallows for a subscribing with an already subscribed email" do
|
84 | 98 | user = FactoryBot.create(:user, :subscribed)
|
85 | 99 |
|
|
94 | 108 | # assert "already subscribed" email sent
|
95 | 109 | end
|
96 | 110 |
|
97 |
| - it "succeeds for a user with existing accout who is not currently subscribed email" do |
| 111 | + it "succeeds for a user with existing account who is not currently subscribed email" do |
98 | 112 | user = FactoryBot.create(:user, :unsubscribed)
|
99 | 113 |
|
100 | 114 | expect {
|
|
107 | 121 | expect(user.reload.newsletter_subscription).to be_present
|
108 | 122 | end
|
109 | 123 |
|
| 124 | + it "sends confirmation for an unconfirmed user with existing account who is not currently subscribed email" do |
| 125 | + user = FactoryBot.create(:user, :unsubscribed, :unconfirmed) |
| 126 | + admin = FactoryBot.create(:admin_user) |
| 127 | + |
| 128 | + expect { |
| 129 | + post users_newsletter_subscriptions_path, |
| 130 | + params: {user: {email: user.email}} |
| 131 | + }.to change(NewsletterSubscription, :count).by(1) |
| 132 | + |
| 133 | + expect(response).to redirect_to(users_newsletter_subscription_path(User.last.newsletter_subscription)) |
| 134 | + |
| 135 | + expect(user.reload.newsletter_subscription).to be_present |
| 136 | + |
| 137 | + perform_enqueued_jobs_and_subsequently_enqueued_jobs |
| 138 | + |
| 139 | + mail = find_mail_to(user.email) |
| 140 | + |
| 141 | + expect(mail.subject).to eq "Confirm your email address" |
| 142 | + |
| 143 | + expect(find_mail_to(admin.email)).to be_nil |
| 144 | + end |
| 145 | + |
110 | 146 | it "disallows a user to subscribe with an invalid email" do
|
111 | 147 | expect {
|
112 | 148 | post users_newsletter_subscriptions_path,
|
|
0 commit comments