VRFS-1483 specs for test users
This commit is contained in:
parent
3204de01e6
commit
98a4553f72
|
|
@ -12,230 +12,14 @@ module JamRuby
|
|||
sendgrid_category :use_subject_lines
|
||||
sendgrid_unique_args :env => Environment.mode
|
||||
|
||||
def send_batch_email(user, signup_confirm_url)
|
||||
def send_batch_email(batch, user)
|
||||
@user = user
|
||||
@signup_confirm_url = signup_confirm_url
|
||||
sendgrid_category "Confirm Email"
|
||||
sendgrid_unique_args :type => "confirm_email"
|
||||
|
||||
mail(:to => user.email, :subject => "Please confirm your JamKazam email") do |format|
|
||||
@body = batch.merged_body(user)
|
||||
mail(:to => user.email, :subject => batch.subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def welcome_message(user)
|
||||
@user = user
|
||||
sendgrid_category "Welcome"
|
||||
sendgrid_unique_args :type => "welcome_message"
|
||||
|
||||
mail(:to => user.email, :subject => "Welcome to JamKazam") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def password_changed(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "password_changed"
|
||||
mail(:to => user.email, :subject => "JamKazam Password Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def password_reset(user, password_reset_url)
|
||||
@user = user
|
||||
@password_reset_url = password_reset_url
|
||||
sendgrid_unique_args :type => "password_reset"
|
||||
mail(:to => user.email, :subject => "JamKazam Password Reset") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def updating_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updating_email"
|
||||
mail(:to => user.update_email, :subject => "JamKazam Email Change Confirmation") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def updated_email(user)
|
||||
@user = user
|
||||
sendgrid_unique_args :type => "updated_email"
|
||||
mail(:to => user.email, :subject => "JamKazam Email Changed") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_musicians(user, new_nearby, host='www.jamkazam.com')
|
||||
@user, @new_nearby, @host = user, new_nearby, host
|
||||
sendgrid_unique_args :type => "new_musicians"
|
||||
mail(:to => user.email, :subject => "JamKazam New Musicians in Your Area") do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
#################################### NOTIFICATION EMAILS ####################################
|
||||
def friend_request(email, msg)
|
||||
subject = "You have a new friend request on JamKazam"
|
||||
unique_args = {:type => "friend_request"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def friend_request_accepted(email, msg)
|
||||
subject = "You have a new friend on JamKazam"
|
||||
unique_args = {:type => "friend_request_accepted"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_user_follower(email, msg)
|
||||
subject = "You have a new follower on JamKazam"
|
||||
unique_args = {:type => "new_user_follower"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new_band_follower(email, msg)
|
||||
subject = "Your band has a new follower on JamKazam"
|
||||
unique_args = {:type => "new_band_follower"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:bcc => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def session_invitation(email, msg)
|
||||
subject = "You have been invited to a session on JamKazam"
|
||||
unique_args = {:type => "session_invitation"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def musician_session_join(email, msg, session_id)
|
||||
subject = "Someone you know is in a session on JamKazam"
|
||||
unique_args = {:type => "musician_session_join"}
|
||||
@body = msg
|
||||
@session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session_id}"
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:bcc => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_session_join(email, msg, session_id)
|
||||
subject = "A band that you follow has joined a session"
|
||||
unique_args = {:type => "band_session_join"}
|
||||
|
||||
@body = msg
|
||||
@session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session_id}"
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:bcc => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def musician_recording_saved(email, msg)
|
||||
subject = "A musician has saved a new recording on JamKazam"
|
||||
unique_args = {:type => "musician_recording_saved"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:bcc => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_recording_saved(email, msg)
|
||||
subject = "A band has saved a new recording on JamKazam"
|
||||
unique_args = {:type => "band_recording_saved"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:bcc => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_invitation(email, msg)
|
||||
subject = "You have been invited to join a band on JamKazam"
|
||||
unique_args = {:type => "band_invitation"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def band_invitation_accepted(email, msg)
|
||||
subject = "Your band invitation was accepted"
|
||||
unique_args = {:type => "band_invitation_accepted"}
|
||||
|
||||
@body = msg
|
||||
sendgrid_category "Notification"
|
||||
sendgrid_unique_args :type => unique_args[:type]
|
||||
mail(:to => email, :subject => subject) do |format|
|
||||
format.text
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# def send_notification(email, subject, msg, unique_args)
|
||||
# @body = msg
|
||||
# sendgrid_category "Notification"
|
||||
# sendgrid_unique_args :type => unique_args[:type]
|
||||
# mail(:bcc => email, :subject => subject) do |format|
|
||||
# format.text
|
||||
# format.html
|
||||
# end
|
||||
# end
|
||||
#############################################################################################
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ module JamRuby
|
|||
class EmailBatch < ActiveRecord::Base
|
||||
self.table_name = "email_batches"
|
||||
|
||||
VAR_FIRST_NAME = '@FIRSTNAME'
|
||||
VAR_LAST_NAME = '@LASTNAME'
|
||||
|
||||
# has_many :email_batch_results, :class_name => 'JamRuby::EmailBatchResult'
|
||||
|
||||
def self.qualified_users
|
||||
|
|
@ -14,7 +17,25 @@ module JamRuby
|
|||
self.class.qualified_users.each
|
||||
end
|
||||
|
||||
def test_batch
|
||||
def test_users
|
||||
self.test_emails.split(',').collect do |ee|
|
||||
ee.strip!
|
||||
uu = User.new
|
||||
uu.email = ee
|
||||
uu.first_name = ee.match(/^(.*)@/)[1].to_s
|
||||
uu.last_name = 'Test'
|
||||
uu
|
||||
end
|
||||
end
|
||||
|
||||
def send_test_batch
|
||||
self.test_users.each do |uu|
|
||||
BatchMailer.send_batch_email(self, uu).deliver
|
||||
end
|
||||
end
|
||||
|
||||
def merged_body(user)
|
||||
body.gsub(VAR_FIRST_NAME, user.first_name).gsub(VAR_LAST_NAME, user.last_name)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ FactoryGirl.define do
|
|||
|
||||
factory :email_batch, :class => JamRuby::EmailBatch do
|
||||
subject Faker::Lorem.sentence
|
||||
body Faker::Lorem.paragraph(3)
|
||||
body "#{JamRuby::EmailBatch::VAR_FIRST_NAME} " + Faker::Lorem.paragraphs(3).join("\n")
|
||||
test_emails 4.times.collect { Faker::Internet.safe_email }.join(',')
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,15 @@ require 'spec_helper'
|
|||
describe EmailBatch do
|
||||
let (:email_batch) { FactoryGirl.create(:email_batch) }
|
||||
|
||||
it 'runs test' do
|
||||
before(:each) do
|
||||
BatchMailer.deliveries.clear
|
||||
end
|
||||
|
||||
it 'has test emails setup' do
|
||||
expect(email_batch.test_emails.present?).to be true
|
||||
# email_batch.test_batch
|
||||
|
||||
users = email_batch.test_users
|
||||
expect(email_batch.merged_body(users[0])).to match(/#{users[0].first_name} #{email_batch.body}/)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,148 +2,29 @@ require "spec_helper"
|
|||
|
||||
describe BatchMailer do
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:batch) { FactoryGirl.create(:email_batch) }
|
||||
# before(:each) do
|
||||
# BatchMailer.deliveries.clear
|
||||
# end
|
||||
|
||||
before(:each) do
|
||||
BatchMailer.deliveries.clear
|
||||
end
|
||||
|
||||
describe "should create a batch email" do
|
||||
describe "should send test emails" do
|
||||
let (:mail) { BatchMailer.deliveries[0] }
|
||||
let (:signup_confirmation_url) { "http://example.com/confirm" }
|
||||
let (:signup_confirmation_url_with_token ) { "#{signup_confirmation_url}/#{user.signup_token}" }
|
||||
|
||||
before(:each) do
|
||||
BatchMailer.confirm_email(user, signup_confirmation_url_with_token).deliver
|
||||
end
|
||||
batch = FactoryGirl.create(:email_batch)
|
||||
batch.send_test_batch
|
||||
it { BatchMailer.deliveries.length.should == 4 }
|
||||
|
||||
it { mail['from'].to_s.should == BatchMailer::DEFAULT_SENDER }
|
||||
it { mail['to'].to_s.should == batch.test_emails.split(',')[0] }
|
||||
it { mail.subject.should == batch.subject }
|
||||
|
||||
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
|
||||
it { mail.parts[1].decode_body.should match(/#{Regexp.escape(batch.merged_body(batch.test_users[0]))}/) }
|
||||
|
||||
|
||||
# verify that the messages are correctly configured
|
||||
it { mail.html_part.body.include?("Welcome").should be_true }
|
||||
it { mail.html_part.body.include?(signup_confirmation_url_with_token).should be_true }
|
||||
it { mail.text_part.body.include?("Welcome").should be_true }
|
||||
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
|
||||
UserMailer.welcome_message(user).deliver
|
||||
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?("delighted").should be_true }
|
||||
it { mail.text_part.body.include?("delighted").should be_true }
|
||||
end
|
||||
|
||||
describe "should send reset password" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
before(:each) do
|
||||
UserMailer.password_reset(user, '/reset_password').deliver
|
||||
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 }
|
||||
it { mail.text_part.body.include?("Reset").should be_true }
|
||||
end
|
||||
|
||||
describe "should send change password confirmation" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
|
||||
before(:each) do
|
||||
UserMailer.password_changed(user).deliver
|
||||
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?("changed your password").should be_true }
|
||||
it { mail.text_part.body.include?("changed your password").should be_true }
|
||||
end
|
||||
|
||||
describe "should send update email confirmation" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
|
||||
before(:each) do
|
||||
UserMailer.updated_email(user).deliver
|
||||
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?("<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 }
|
||||
end
|
||||
|
||||
describe "should send updating email" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
|
||||
before(:each) do
|
||||
user.update_email = "my_new_email@jamkazam.com"
|
||||
UserMailer.updating_email(user).deliver
|
||||
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 }
|
||||
end
|
||||
|
||||
|
||||
describe "sends new musicians email" do
|
||||
|
||||
let(:mail) { UserMailer.deliveries[0] }
|
||||
|
||||
before(:each) do
|
||||
UserMailer.new_musicians(user, User.musicians).deliver
|
||||
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?("New JamKazam Musicians in your Area").should be_true }
|
||||
it { mail.text_part.body.include?("New JamKazam Musicians in your Area").should be_true }
|
||||
# it { mail.html_part.body.include?("Welcome").should be_true }
|
||||
# it { mail.html_part.body.include?(signup_confirmation_url_with_token).should be_true }
|
||||
# it { mail.text_part.body.include?("Welcome").should be_true }
|
||||
# it { mail.text_part.body.include?(signup_confirmation_url_with_token).should be_true }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue