2012-11-12 12:28:44 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
2013-06-24 21:31:40 +00:00
|
|
|
###########################################################
|
|
|
|
|
# We test just the mailer templating here. #
|
|
|
|
|
# In other words, make sure there are no glaring oopsies, #
|
|
|
|
|
# such as broken templates, or sending to wrong address #
|
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
|
|
|
2012-11-12 12:28:44 +00:00
|
|
|
describe UserMailer do
|
|
|
|
|
|
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
2015-04-12 06:18:31 +00:00
|
|
|
stub_const("APP_CONFIG", app_config)
|
2012-11-12 12:28:44 +00:00
|
|
|
UserMailer.deliveries.clear
|
|
|
|
|
end
|
|
|
|
|
|
2013-09-26 13:43:02 +00:00
|
|
|
describe "should send confirm email" do
|
2013-06-24 21:31:40 +00:00
|
|
|
|
|
|
|
|
let (:mail) { UserMailer.deliveries[0] }
|
2021-02-01 17:58:25 +00:00
|
|
|
let (:signup_confirmation_url) { "/confirm" }
|
2013-06-24 21:31:40 +00:00
|
|
|
let (:signup_confirmation_url_with_token ) { "#{signup_confirmation_url}/#{user.signup_token}" }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.confirm_email(user, signup_confirmation_url_with_token).deliver_now
|
2013-09-26 13:43:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
2021-02-01 17:58:25 +00:00
|
|
|
it { mail.html_part.body.include?("delighted").should be_true }
|
2013-09-26 13:43:02 +00:00
|
|
|
it { mail.html_part.body.include?(signup_confirmation_url_with_token).should be_true }
|
2021-02-01 17:58:25 +00:00
|
|
|
it { mail.text_part.body.include?("delighted").should be_true }
|
2013-09-26 13:43:02 +00:00
|
|
|
it { mail.text_part.body.include?(signup_confirmation_url_with_token).should be_true }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "should send welcome email" do
|
|
|
|
|
|
|
|
|
|
let (:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.welcome_message(user).deliver_now
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
2013-09-26 17:33:28 +00:00
|
|
|
it { mail.html_part.body.include?("delighted").should be_true }
|
|
|
|
|
it { mail.text_part.body.include?("delighted").should be_true }
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "should send reset password" do
|
|
|
|
|
|
|
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.password_reset(user, '/reset_password').deliver_now
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
|
|
|
|
it { mail.html_part.body.include?("Reset").should be_true }
|
2014-10-08 03:48:05 +00:00
|
|
|
it { mail.text_part.body.include?("change your JamKazam password").should be_true }
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "should send change password confirmation" do
|
|
|
|
|
|
|
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.password_changed(user).deliver_now
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
2012-11-12 12:28:44 +00:00
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
2013-06-24 21:31:40 +00:00
|
|
|
it { mail.html_part.body.include?("changed your password").should be_true }
|
|
|
|
|
it { mail.text_part.body.include?("changed your password").should be_true }
|
2012-11-12 12:28:44 +00:00
|
|
|
end
|
|
|
|
|
|
2013-06-24 21:31:40 +00:00
|
|
|
describe "should send update email confirmation" do
|
2012-11-12 12:28:44 +00:00
|
|
|
|
2013-06-24 21:31:40 +00:00
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
2012-11-12 12:28:44 +00:00
|
|
|
|
2013-06-24 21:31:40 +00:00
|
|
|
before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.updated_email(user).deliver_now
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
2012-11-12 12:28:44 +00:00
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
2013-06-24 21:31:40 +00:00
|
|
|
it { mail.html_part.body.include?("<b>#{user.email}</b> has been confirmed as your new email address.").should be_true }
|
|
|
|
|
it { mail.text_part.body.include?("#{user.email} has been confirmed as your new email address.").should be_true }
|
2012-11-12 12:28:44 +00:00
|
|
|
end
|
2013-06-24 21:31:40 +00:00
|
|
|
|
|
|
|
|
describe "should send updating email" do
|
|
|
|
|
|
|
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
|
user.update_email = "my_new_email@jamkazam.com"
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.updating_email(user).deliver_now
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { UserMailer.deliveries.length.should == 1 }
|
|
|
|
|
|
|
|
|
|
it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
it { mail['to'].to_s.should == user.update_email }
|
|
|
|
|
it { mail.multipart?.should == true } # because we send plain + html
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
|
|
|
|
it { mail.html_part.body.include?("to confirm your change in email").should be_true }
|
|
|
|
|
it { mail.text_part.body.include?("to confirm your change in email").should be_true }
|
2016-08-03 01:46:15 +00:00
|
|
|
|
|
|
|
|
# verify can unsubscribe from bulk emails
|
|
|
|
|
|
|
|
|
|
it {mail.html_part.body.include?('here to unsubscribe').should be_true}
|
|
|
|
|
it {mail.html_part.body.include?("https://www.jamkazam.com/unsubscribe/#{user.unsubscribe_token}")}
|
2013-06-24 21:31:40 +00:00
|
|
|
end
|
|
|
|
|
|
2015-07-10 15:51:12 +00:00
|
|
|
describe "notifications" do
|
|
|
|
|
|
|
|
|
|
let(:mail) { UserMailer.deliveries[0] }
|
|
|
|
|
let(:music_session) { FactoryGirl.create(:music_session) }
|
|
|
|
|
|
|
|
|
|
it "should send upcoming email" do
|
|
|
|
|
user.update_email = "my_new_email@jamkazam.com"
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.scheduled_session_reminder_upcoming(music_session.creator, music_session).deliver_now
|
2015-07-10 15:51:12 +00:00
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
|
|
|
|
|
mail['from'].to_s.should == UserMailer::DEFAULT_SENDER
|
|
|
|
|
mail['to'].to_s.should == music_session.creator.email# rsvp_requests.first.user.email
|
|
|
|
|
mail.multipart?.should == true # because we send plain + htm
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
|
|
|
|
mail.html_part.body.include?("This is a reminder that your JamKazam session").should be_true
|
|
|
|
|
mail.text_part.body.include?("This is a reminder that your JamKazam session").should be_true
|
|
|
|
|
mail.html_part.body.include?("starts in 1 hour").should be_true
|
|
|
|
|
mail.text_part.body.include?("starts in 1 hour").should be_true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should send 1-day reminder" do
|
|
|
|
|
user.update_email = "my_new_email@jamkazam.com"
|
2016-07-17 15:16:27 +00:00
|
|
|
UserMailer.scheduled_session_reminder_day(music_session.creator, music_session).deliver_now
|
2015-07-10 15:51:12 +00:00
|
|
|
UserMailer.deliveries.length.should == 1
|
|
|
|
|
|
|
|
|
|
mail['from'].to_s.should == UserMailer::DEFAULT_SENDER
|
|
|
|
|
mail['to'].to_s.should == music_session.creator.email# rsvp_requests.first.user.email
|
|
|
|
|
mail.multipart?.should == true # because we send plain + htm
|
|
|
|
|
|
|
|
|
|
# verify that the messages are correctly configured
|
|
|
|
|
mail.html_part.body.include?("This is a reminder that your JamKazam session").should be_true
|
|
|
|
|
mail.text_part.body.include?("This is a reminder that your JamKazam session").should be_true
|
|
|
|
|
mail.html_part.body.include?("is scheduled for tomorrow").should be_true
|
|
|
|
|
mail.text_part.body.include?("is scheduled for tomorrow").should be_true
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2013-06-24 21:31:40 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# describe "sends new musicians email" do
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# let(:mail) { UserMailer.deliveries[0] }
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# before(:each) do
|
2016-07-17 15:16:27 +00:00
|
|
|
# UserMailer.new_musicians(user, User.musicians).deliver_now
|
2014-05-31 21:52:28 +00:00
|
|
|
# end
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# it { UserMailer.deliveries.length.should == 1 }
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# it { mail['from'].to_s.should == UserMailer::DEFAULT_SENDER }
|
|
|
|
|
# it { mail['to'].to_s.should == user.email }
|
|
|
|
|
# it { mail.multipart?.should == true } # because we send plain + html
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2014-05-31 21:52:28 +00:00
|
|
|
# # verify that the messages are correctly configured
|
|
|
|
|
# it { mail.html_part.body.include?("New JamKazam Musicians in your Area").should be_true }
|
|
|
|
|
# it { mail.text_part.body.include?("New JamKazam Musicians in your Area").should be_true }
|
|
|
|
|
# end
|
2013-11-26 06:03:42 +00:00
|
|
|
|
2012-11-12 12:28:44 +00:00
|
|
|
end
|