From e6d0851391f722eb068b4b034fd6eacd72ea3d2c Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 15:07:45 +0000 Subject: [PATCH 01/17] VRFS-1483 adding first set of updates for batch emails --- db/manifest | 1 + db/up/emails.sql | 32 +++ ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 241 ++++++++++++++++++ ruby/lib/jam_ruby/models/email_batch.rb | 21 ++ ruby/spec/factories.rb | 7 + ruby/spec/jam_ruby/models/email_batch_spec.rb | 11 + ruby/spec/mailers/batch_mailer_spec.rb | 149 +++++++++++ 8 files changed, 463 insertions(+) create mode 100644 db/up/emails.sql create mode 100644 ruby/lib/jam_ruby/app/mailers/batch_mailer.rb create mode 100644 ruby/lib/jam_ruby/models/email_batch.rb create mode 100644 ruby/spec/jam_ruby/models/email_batch_spec.rb create mode 100644 ruby/spec/mailers/batch_mailer_spec.rb diff --git a/db/manifest b/db/manifest index bad9decf1..2423e0138 100755 --- a/db/manifest +++ b/db/manifest @@ -136,4 +136,5 @@ events.sql cascading_delete_constraints_for_release.sql events_social_description.sql fix_broken_cities.sql +emails.sql diff --git a/db/up/emails.sql b/db/up/emails.sql new file mode 100644 index 000000000..c4290bda1 --- /dev/null +++ b/db/up/emails.sql @@ -0,0 +1,32 @@ +CREATE TABLE email_batches ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + subject VARCHAR(256) NOT NULL, + body TEXT NOT NULL, + aasm_state VARCHAR(32) NOT NULL default 'pending', + + test_emails TEXT NOT NULL, + batch_size INTEGER NOT NULL default 1000, + + started_at TIMESTAMP, + completed_at TIMESTAMP, + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE email_batch_results ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + email_batch_id VARCHAR(64) REFERENCES email_batches(id) ON DELETE CASCADE, + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + + error_type VARCHAR(32), + email_address VARCHAR(256), + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE email_batch_results ADD CONSTRAINT email_batch_uniqkey UNIQUE (email_batch_id); +ALTER TABLE email_batch_results ADD CONSTRAINT email_user_uniqkey UNIQUE (user_id); + +ALTER TABLE users ADD COLUMN opt_out_email_batch boolean DEFAULT false; diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index b6103cd16..572b18c16 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -131,6 +131,7 @@ require "jam_ruby/models/playable_play" require "jam_ruby/models/country" require "jam_ruby/models/region" require "jam_ruby/models/city" +require "jam_ruby/models/email_batch" include Jampb diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb new file mode 100644 index 000000000..2aada35c8 --- /dev/null +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -0,0 +1,241 @@ +module JamRuby + class BatchMailer < ActionMailer::Base + include SendGrid + + layout "batch_mailer" + + DEFAULT_SENDER = "support@jamkazam.com" + + default :from => DEFAULT_SENDER + + sendgrid_category :batch_email + sendgrid_category :use_subject_lines + sendgrid_unique_args :env => Environment.mode + + def send_batch_email(user, signup_confirm_url) + @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| + 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 diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb new file mode 100644 index 000000000..9e1a11566 --- /dev/null +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -0,0 +1,21 @@ +module JamRuby + class EmailBatch < ActiveRecord::Base + self.table_name = "email_batches" + + # has_many :email_batch_results, :class_name => 'JamRuby::EmailBatchResult' + + def self.qualified_users + User.select(:email) + .where(:opt_out_email_batch => false) + .order('created_at DESC') + end + + def deliver + self.class.qualified_users.each + end + + def test_batch + end + + end +end diff --git a/ruby/spec/factories.rb b/ruby/spec/factories.rb index 0db11878c..08d44fd6f 100644 --- a/ruby/spec/factories.rb +++ b/ruby/spec/factories.rb @@ -424,4 +424,11 @@ FactoryGirl.define do factory :event_session, :class => JamRuby::EventSession do end + + factory :email_batch, :class => JamRuby::EmailBatch do + subject Faker::Lorem.sentence + body Faker::Lorem.paragraph(3) + test_emails 4.times.collect { Faker::Internet.safe_email }.join(',') + end + end diff --git a/ruby/spec/jam_ruby/models/email_batch_spec.rb b/ruby/spec/jam_ruby/models/email_batch_spec.rb new file mode 100644 index 000000000..a59e5a377 --- /dev/null +++ b/ruby/spec/jam_ruby/models/email_batch_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe EmailBatch do + let (:email_batch) { FactoryGirl.create(:email_batch) } + + it 'runs test' do + expect(email_batch.test_emails.present?).to be true + # email_batch.test_batch + end + +end diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb new file mode 100644 index 000000000..06c9393d0 --- /dev/null +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -0,0 +1,149 @@ +require "spec_helper" + +describe BatchMailer do + + let(:user) { FactoryGirl.create(:user) } + let(:batch) { FactoryGirl.create(:email_batch) } + + before(:each) do + BatchMailer.deliveries.clear + end + + describe "should create a batch email" 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 + + 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?("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?("#{user.email} 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 } + end + +end From 98a4553f72f8df45fde7586a96b65557a9592e4d Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 18:33:48 +0000 Subject: [PATCH 02/17] VRFS-1483 specs for test users --- ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 222 +----------------- ruby/lib/jam_ruby/models/email_batch.rb | 23 +- ruby/spec/factories.rb | 2 +- ruby/spec/jam_ruby/models/email_batch_spec.rb | 10 +- ruby/spec/mailers/batch_mailer_spec.rb | 153 ++---------- 5 files changed, 51 insertions(+), 359 deletions(-) diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 2aada35c8..8b8042cb8 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 9e1a11566..9909eebd3 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -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 diff --git a/ruby/spec/factories.rb b/ruby/spec/factories.rb index c2cc4b3fa..25c4f4849 100644 --- a/ruby/spec/factories.rb +++ b/ruby/spec/factories.rb @@ -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 diff --git a/ruby/spec/jam_ruby/models/email_batch_spec.rb b/ruby/spec/jam_ruby/models/email_batch_spec.rb index a59e5a377..19d8a125f 100644 --- a/ruby/spec/jam_ruby/models/email_batch_spec.rb +++ b/ruby/spec/jam_ruby/models/email_batch_spec.rb @@ -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 diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index 06c9393d0..df9ea17fd 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -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?("#{user.email} 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 From 72fb245dd7f175ce5137477be8ea753063887171 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 19:56:15 +0000 Subject: [PATCH 03/17] VRFS-1483 added batch_mailer --- ruby/lib/jam_ruby.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 572b18c16..927d1e40f 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -132,6 +132,7 @@ require "jam_ruby/models/country" require "jam_ruby/models/region" require "jam_ruby/models/city" require "jam_ruby/models/email_batch" +require "jam_ruby/app/mailers/batch_mailer" include Jampb From 40a2049bdf423e9ad752a2dae0229aafd0f240fd Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 20:31:23 +0000 Subject: [PATCH 04/17] VRFS-1483 added from_email column to email_batches --- db/up/emails.sql | 2 ++ ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 6 +----- ruby/lib/jam_ruby/models/email_batch.rb | 2 ++ ruby/spec/mailers/batch_mailer_spec.rb | 12 +----------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/db/up/emails.sql b/db/up/emails.sql index c4290bda1..47a33d105 100644 --- a/db/up/emails.sql +++ b/db/up/emails.sql @@ -2,6 +2,8 @@ CREATE TABLE email_batches ( id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), subject VARCHAR(256) NOT NULL, body TEXT NOT NULL, + from_email VARCHAR(64) NOT NULL default 'support@jamkazam.com', + aasm_state VARCHAR(32) NOT NULL default 'pending', test_emails TEXT NOT NULL, diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 8b8042cb8..4c6873efc 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -4,10 +4,6 @@ module JamRuby layout "batch_mailer" - DEFAULT_SENDER = "support@jamkazam.com" - - default :from => DEFAULT_SENDER - sendgrid_category :batch_email sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode @@ -15,7 +11,7 @@ module JamRuby def send_batch_email(batch, user) @user = user @body = batch.merged_body(user) - mail(:to => user.email, :subject => batch.subject) do |format| + mail(:to => user.email, :from => batch.from_email, :subject => batch.subject) do |format| format.text format.html end diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 9909eebd3..792aaf7bc 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -5,6 +5,8 @@ module JamRuby VAR_FIRST_NAME = '@FIRSTNAME' VAR_LAST_NAME = '@LASTNAME' + DEFAULT_SENDER = "support@jamkazam.com" + # has_many :email_batch_results, :class_name => 'JamRuby::EmailBatchResult' def self.qualified_users diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index df9ea17fd..ed578da89 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -2,10 +2,6 @@ require "spec_helper" describe BatchMailer do - # before(:each) do - # BatchMailer.deliveries.clear - # end - describe "should send test emails" do let (:mail) { BatchMailer.deliveries[0] } @@ -13,18 +9,12 @@ describe BatchMailer do batch.send_test_batch it { BatchMailer.deliveries.length.should == 4 } - it { mail['from'].to_s.should == BatchMailer::DEFAULT_SENDER } + it { mail['from'].to_s.should == EmailBatch::DEFAULT_SENDER } it { mail['to'].to_s.should == batch.test_emails.split(',')[0] } it { mail.subject.should == batch.subject } 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]))}/) } - - - # 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 From cdb271bf98dccbb9f912346f98c8271282bf34f2 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 22:50:06 +0000 Subject: [PATCH 05/17] VRFS-1483 added async support --- ruby/Gemfile | 1 + ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 26 ++++++++++++++----- ruby/lib/jam_ruby/models/email_batch.rb | 2 +- ruby/spec/mailers/batch_mailer_spec.rb | 3 ++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ruby/Gemfile b/ruby/Gemfile index 7ba18443c..52c04053e 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -40,6 +40,7 @@ gem 'resque' gem 'resque-retry' gem 'resque-failed-job-mailer' #, :path => "/Users/seth/workspace/resque_failed_job_mailer" gem 'resque-lonely_job', '~> 1.0.0' +gem 'resque_mailer' gem 'oj' gem 'builder' gem 'fog' diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 927d1e40f..afd8c77c7 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -132,6 +132,7 @@ require "jam_ruby/models/country" require "jam_ruby/models/region" require "jam_ruby/models/city" require "jam_ruby/models/email_batch" +require "jam_ruby/app/mailers/async_mailer" require "jam_ruby/app/mailers/batch_mailer" include Jampb diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 4c6873efc..8b16acd08 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -1,17 +1,31 @@ module JamRuby - class BatchMailer < ActionMailer::Base - include SendGrid - + class BatchMailer < JamRuby::AsyncMailer layout "batch_mailer" sendgrid_category :batch_email sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode - def send_batch_email(batch, user) - @user = user + def send_batch_email(batch_id, user_id) + @user = User.where(:id => user_id).limit(1).first + batch = EmailBatch.where(:id => batch_id).limit(1).first @body = batch.merged_body(user) - mail(:to => user.email, :from => batch.from_email, :subject => batch.subject) do |format| + + mail(:to => user.email, + :from => batch.from_email, + :subject => batch.subject) do |format| + format.text + format.html + end + end + + def send_batch_email_test(batch_id, email_addy) + batch = EmailBatch.where(:id => batch_id).limit(1).first + @body = batch.body + + mail(:to => email_addy, + :from => batch.from_email, + :subject => batch.subject) do |format| format.text format.html end diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 792aaf7bc..9df7d3d30 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -32,7 +32,7 @@ module JamRuby def send_test_batch self.test_users.each do |uu| - BatchMailer.send_batch_email(self, uu).deliver + BatchMailer.send_batch_email_test(self.id, uu.email).deliver end end diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index ed578da89..1febc734c 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -7,6 +7,7 @@ describe BatchMailer do batch = FactoryGirl.create(:email_batch) batch.send_test_batch + it { BatchMailer.deliveries.length.should == 4 } it { mail['from'].to_s.should == EmailBatch::DEFAULT_SENDER } @@ -14,7 +15,7 @@ describe BatchMailer do it { mail.subject.should == batch.subject } 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]))}/) } + it { mail.text_part.decode_body.should match(/#{Regexp.escape(batch.body)}/) } end end From 1c39238fe5c224bb885a4bd49c46aeebabe95e2b Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 23:05:40 +0000 Subject: [PATCH 06/17] VRFS-1483 adding send batch layouts and such --- ruby/lib/jam_ruby/app/mailers/async_mailer.rb | 8 +++ .../batch_mailer/send_batch_email.html.erb | 1 + .../batch_mailer/send_batch_email.text.erb | 1 + .../send_batch_email_test.html.erb | 1 + .../send_batch_email_test.text.erb | 1 + .../app/views/layouts/batch_mailer.html.erb | 54 +++++++++++++++++++ .../app/views/layouts/batch_mailer.text.erb | 8 +++ web/Gemfile | 1 + 8 files changed, 75 insertions(+) create mode 100644 ruby/lib/jam_ruby/app/mailers/async_mailer.rb create mode 100644 ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.html.erb create mode 100644 ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.text.erb create mode 120000 ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.html.erb create mode 120000 ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.text.erb create mode 100644 ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb create mode 100644 ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb diff --git a/ruby/lib/jam_ruby/app/mailers/async_mailer.rb b/ruby/lib/jam_ruby/app/mailers/async_mailer.rb new file mode 100644 index 000000000..bde8e11ed --- /dev/null +++ b/ruby/lib/jam_ruby/app/mailers/async_mailer.rb @@ -0,0 +1,8 @@ +require 'resque_mailer' + +module JamRuby + class AsyncMailer < ActionMailer::Base + include SendGrid + # include Resque::Mailer + end +end diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.html.erb new file mode 100644 index 000000000..31bd20e21 --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.html.erb @@ -0,0 +1 @@ +<%= @body %> diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.text.erb new file mode 100644 index 000000000..31bd20e21 --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email.text.erb @@ -0,0 +1 @@ +<%= @body %> diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.html.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.html.erb new file mode 120000 index 000000000..f14e9223c --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.html.erb @@ -0,0 +1 @@ +send_batch_email.html.erb \ No newline at end of file diff --git a/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.text.erb b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.text.erb new file mode 120000 index 000000000..2a1e564e8 --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/jam_ruby/batch_mailer/send_batch_email_test.text.erb @@ -0,0 +1 @@ +send_batch_email.text.erb \ No newline at end of file diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb new file mode 100644 index 000000000..a195a3ff4 --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb @@ -0,0 +1,54 @@ + + + + + JamKazam + + + + + + + + + + +
JamKazam
+ + + + + + + + + +

<%= yield(:title) %>

+

<%= yield %>

+
+
+ + +
+ + +

+

This email was sent to you because you have an account at JamKazam. +

+ +
+ + + + +
Copyright © <%= Time.now.year %> JamKazam, Inc. All rights reserved. +
+ + + diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb new file mode 100644 index 000000000..8bd3c7483 --- /dev/null +++ b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb @@ -0,0 +1,8 @@ +<%= yield %> + + +<% unless @suppress_user_has_account_footer == true %> +This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. +<% end %> + +Copyright <%= Time.now.year %> JamKazam, Inc. All rights reserved. diff --git a/web/Gemfile b/web/Gemfile index 6ea68e5fb..af835a453 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -67,6 +67,7 @@ gem 'resque-retry' gem 'resque-failed-job-mailer' gem 'resque-dynamic-queues' gem 'resque-lonely_job', '~> 1.0.0' +gem 'resque_mailer' gem 'quiet_assets', :group => :development gem 'bugsnag' gem 'multi_json', '1.9.0' From 17fcd42120c3ecde0aa36d6dbcbb60f7c33b0894 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 18 Mar 2014 23:39:23 +0000 Subject: [PATCH 07/17] VRFS-1483 include resque::mailer --- ruby/lib/jam_ruby/app/mailers/async_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/lib/jam_ruby/app/mailers/async_mailer.rb b/ruby/lib/jam_ruby/app/mailers/async_mailer.rb index bde8e11ed..4cbad60e4 100644 --- a/ruby/lib/jam_ruby/app/mailers/async_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/async_mailer.rb @@ -3,6 +3,6 @@ require 'resque_mailer' module JamRuby class AsyncMailer < ActionMailer::Base include SendGrid - # include Resque::Mailer + include Resque::Mailer end end From e8dd5f6ae5dd3b8c2b1bfd5cfdf092c99d0075b2 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 04:24:42 +0000 Subject: [PATCH 08/17] VRFS-1483 state transitions and optimistic locking --- db/up/emails.sql | 8 +- ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 5 +- ruby/lib/jam_ruby/models/email_batch.rb | 76 ++++++++++++++++++- 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/db/up/emails.sql b/db/up/emails.sql index 47a33d105..9c68b643e 100644 --- a/db/up/emails.sql +++ b/db/up/emails.sql @@ -6,8 +6,12 @@ CREATE TABLE email_batches ( aasm_state VARCHAR(32) NOT NULL default 'pending', - test_emails TEXT NOT NULL, - batch_size INTEGER NOT NULL default 1000, + test_emails TEXT NOT NULL default '', + + qualified_count INTEGER NOT NULL default 0, + sent_count INTEGER NOT NULL default 0, + + lock_version INTEGER, started_at TIMESTAMP, completed_at TIMESTAMP, diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 8b16acd08..899e01b16 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -6,7 +6,8 @@ module JamRuby sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode - def send_batch_email(batch_id, user_id) + def send_batch_email(batch_id, user_ids) + @users = User.find_all_by_id(user_ids) @user = User.where(:id => user_id).limit(1).first batch = EmailBatch.where(:id => batch_id).limit(1).first @body = batch.merged_body(user) @@ -17,6 +18,7 @@ module JamRuby format.text format.html end + batch.did_send(user.email) end def send_batch_email_test(batch_id, email_addy) @@ -29,6 +31,7 @@ module JamRuby format.text format.html end + batch.did_send(email_addy) end end diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 9df7d3d30..d3b396c1e 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -2,21 +2,55 @@ module JamRuby class EmailBatch < ActiveRecord::Base self.table_name = "email_batches" + attr_accessible :lock_version + VAR_FIRST_NAME = '@FIRSTNAME' VAR_LAST_NAME = '@LASTNAME' DEFAULT_SENDER = "support@jamkazam.com" + include AASM + aasm do + state :pending, :initial => true + state :testing + state :tested + state :batching + state :batched + state :disabled + + event :enable do + transitions :from => :disabled, :to => :pending + end + event :do_test_run, :after => Proc.new { running_tests } do + transitions :from => [:pending, :tested, :batched], :to => :testing + end + event :did_test_run do + transitions :from => :testing, :to => :tested + end + event :do_batch_run, :after => Proc.new { running_batch } do + transitions :from => [:tested, :pending, :batched], :to => :batching + end + event :did_batch_run do + transitions :from => :batching, :to => :batched + end + event :disable do + transitions :from => [:pending, :tested, :batched], :to => :disabled + end + end + # has_many :email_batch_results, :class_name => 'JamRuby::EmailBatchResult' def self.qualified_users User.select(:email) .where(:opt_out_email_batch => false) - .order('created_at DESC') end def deliver - self.class.qualified_users.each + self.do_batch_run! + + self.class.qualified_users.find_each do |uu| + BatchMailer.send_batch_email_test(self.id, uu.id).deliver + end end def test_users @@ -31,6 +65,8 @@ module JamRuby end def send_test_batch + self.do_test_run! + self.test_users.each do |uu| BatchMailer.send_batch_email_test(self.id, uu.email).deliver end @@ -40,5 +76,41 @@ module JamRuby body.gsub(VAR_FIRST_NAME, user.first_name).gsub(VAR_LAST_NAME, user.last_name) end + def did_send(email) + self.update_with_conflict_validation({ :sent_count => self.sent_count + 1 }) + if self.sent_count >= self.qualified_count + if batching? + self.did_batch_run! + elsif testing? + self.did_test_run! + end + end + end + + protected + + def update_with_conflict_validation(*args) + num_try = 0 + update_attributes(*args) + rescue ActiveRecord::StaleObjectError + num_try += 1 + if 5 > num_try + self.reload + retry + end + end + + def running_batch + self.update_attributes({:qualified_count => self.class.qualified_users.count, + :sent_count => 0 + }) + end + + def running_test + self.update_attributes({:qualified_count => self.class.qualified_users.count, + :sent_count => 0 + }) + end + end end From 4ba18a88ee3b8de8908098e4237c6a5158770596 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 06:20:58 +0000 Subject: [PATCH 09/17] VRFS-1483 integrating sendgrid_smtpapi --- ruby/Gemfile | 1 + ruby/lib/jam_ruby.rb | 2 ++ ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 35 +++++++++++-------- ruby/lib/jam_ruby/models/email_batch.rb | 21 +++++------ ruby/spec/mailers/batch_mailer_spec.rb | 4 +-- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/ruby/Gemfile b/ruby/Gemfile index 52c04053e..ae98be72b 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -41,6 +41,7 @@ gem 'resque-retry' gem 'resque-failed-job-mailer' #, :path => "/Users/seth/workspace/resque_failed_job_mailer" gem 'resque-lonely_job', '~> 1.0.0' gem 'resque_mailer' +gem 'sendgrid_smtpapi' gem 'oj' gem 'builder' gem 'fog' diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index ec893c470..be91ea559 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -16,6 +16,8 @@ require "geokit-rails" require "postgres_ext" require 'builder' require 'cgi' +require 'resque_mailer' +require 'sendgrid_smtpapi' require "jam_ruby/constants/limits" require "jam_ruby/constants/notification_types" diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 899e01b16..d540748dc 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -8,30 +8,35 @@ module JamRuby def send_batch_email(batch_id, user_ids) @users = User.find_all_by_id(user_ids) - @user = User.where(:id => user_id).limit(1).first - batch = EmailBatch.where(:id => batch_id).limit(1).first - @body = batch.merged_body(user) - mail(:to => user.email, - :from => batch.from_email, - :subject => batch.subject) do |format| - format.text - format.html - end - batch.did_send(user.email) - end - - def send_batch_email_test(batch_id, email_addy) batch = EmailBatch.where(:id => batch_id).limit(1).first @body = batch.body - mail(:to => email_addy, + substitute(EmailBatch::VAR_FIRST_NAME, @users.map(&:first_name)) + emails = @users.map(&:email) + mail(:to => emails, :from => batch.from_email, :subject => batch.subject) do |format| format.text format.html end - batch.did_send(email_addy) + batch.did_send(emails) + end + + def send_batch_email_test(batch_id) + batch = EmailBatch.where(:id => batch_id).limit(1).first + @body = batch.body + + @users = batch.test_users + emails = @users.map(&:email) + substitute(EmailBatch::VAR_FIRST_NAME, @users.map(&:first_name)) + mail(:to => emails, + :from => batch.from_email, + :subject => batch.subject) do |format| + format.text + format.html + end + batch.did_send(emails) end end diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index d3b396c1e..104eae30f 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -21,7 +21,7 @@ module JamRuby event :enable do transitions :from => :disabled, :to => :pending end - event :do_test_run, :after => Proc.new { running_tests } do + event :do_test_run, :after => :running_tests do transitions :from => [:pending, :tested, :batched], :to => :testing end event :did_test_run do @@ -47,9 +47,8 @@ module JamRuby def deliver self.do_batch_run! - - self.class.qualified_users.find_each do |uu| - BatchMailer.send_batch_email_test(self.id, uu.id).deliver + self.class.qualified_users.pluck(:id).find_in_batches(batch_size: 100) do |user_ids| + BatchMailer.send_batch_email(self.id, user_ids).deliver end end @@ -66,18 +65,16 @@ module JamRuby def send_test_batch self.do_test_run! - - self.test_users.each do |uu| - BatchMailer.send_batch_email_test(self.id, uu.email).deliver - end + BatchMailer.send_batch_email_test(self.id).deliver end def merged_body(user) body.gsub(VAR_FIRST_NAME, user.first_name).gsub(VAR_LAST_NAME, user.last_name) end - def did_send(email) - self.update_with_conflict_validation({ :sent_count => self.sent_count + 1 }) + def did_send(emails) + self.update_with_conflict_validation({ :sent_count => self.sent_count + emails.size }) + if self.sent_count >= self.qualified_count if batching? self.did_batch_run! @@ -87,8 +84,6 @@ module JamRuby end end - protected - def update_with_conflict_validation(*args) num_try = 0 update_attributes(*args) @@ -106,7 +101,7 @@ module JamRuby }) end - def running_test + def running_tests self.update_attributes({:qualified_count => self.class.qualified_users.count, :sent_count => 0 }) diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index 1febc734c..f7b1349b8 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -8,10 +8,10 @@ describe BatchMailer do batch = FactoryGirl.create(:email_batch) batch.send_test_batch - it { BatchMailer.deliveries.length.should == 4 } + it { BatchMailer.deliveries.length.should == 1 } it { mail['from'].to_s.should == EmailBatch::DEFAULT_SENDER } - it { mail['to'].to_s.should == batch.test_emails.split(',')[0] } + it { mail['to'].to_s.split(',')[0].should == batch.test_emails.split(',')[0] } it { mail.subject.should == batch.subject } it { mail.multipart?.should == true } # because we send plain + html From d15c1dbdfdedaf9a03826f4a59e018051ec70442 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 07:15:38 +0000 Subject: [PATCH 10/17] VRFS-1483 --- ruby/lib/jam_ruby/models/email_batch.rb | 8 ++++++-- ruby/spec/mailers/batch_mailer_spec.rb | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 104eae30f..f7ca64ddc 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -21,13 +21,13 @@ module JamRuby event :enable do transitions :from => :disabled, :to => :pending end - event :do_test_run, :after => :running_tests do + event :do_test_run, :before => :running_tests do transitions :from => [:pending, :tested, :batched], :to => :testing end event :did_test_run do transitions :from => :testing, :to => :tested end - event :do_batch_run, :after => Proc.new { running_batch } do + event :do_batch_run, :before => :running_batch do transitions :from => [:tested, :pending, :batched], :to => :batching end event :did_batch_run do @@ -51,6 +51,10 @@ module JamRuby BatchMailer.send_batch_email(self.id, user_ids).deliver end end + + def test_count + self.test_emails.split(',').count + end def test_users self.test_emails.split(',').collect do |ee| diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index f7b1349b8..fda7ed191 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -16,6 +16,10 @@ describe BatchMailer do it { mail.multipart?.should == true } # because we send plain + html it { mail.text_part.decode_body.should match(/#{Regexp.escape(batch.body)}/) } + + it { batch.testing?.should == true } + binding.pry + it { batch.qualified_count.should == batch.test_count } end end From 21bd8fcf2f2878b984325d1d6ba15078ab5b59dd Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 16:29:19 +0000 Subject: [PATCH 11/17] VRFS-1483 removed debug code --- ruby/spec/mailers/batch_mailer_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index fda7ed191..a2d45dd6c 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -6,6 +6,7 @@ describe BatchMailer do let (:mail) { BatchMailer.deliveries[0] } batch = FactoryGirl.create(:email_batch) + batch.update_attribute(:test_emails, "jonathan@jamkazam.com") batch.send_test_batch it { BatchMailer.deliveries.length.should == 1 } @@ -18,8 +19,6 @@ describe BatchMailer do it { mail.text_part.decode_body.should match(/#{Regexp.escape(batch.body)}/) } it { batch.testing?.should == true } - binding.pry - it { batch.qualified_count.should == batch.test_count } end end From 74a5f3863a974db9b8fb21ed4f68e9aaf543e0f8 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 16:32:53 +0000 Subject: [PATCH 12/17] VRFS-1483 various fixes from testing --- ruby/lib/jam_ruby.rb | 1 - ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 35 ++++------ .../app/views/layouts/batch_mailer.html.erb | 2 +- .../app/views/layouts/batch_mailer.text.erb | 2 +- ruby/lib/jam_ruby/models/email_batch.rb | 68 +++++++++++++++---- 5 files changed, 71 insertions(+), 37 deletions(-) diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index be91ea559..b6f17a3a4 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -17,7 +17,6 @@ require "postgres_ext" require 'builder' require 'cgi' require 'resque_mailer' -require 'sendgrid_smtpapi' require "jam_ruby/constants/limits" require "jam_ruby/constants/notification_types" diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index d540748dc..76af3a456 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -2,41 +2,36 @@ module JamRuby class BatchMailer < JamRuby::AsyncMailer layout "batch_mailer" - sendgrid_category :batch_email sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode - def send_batch_email(batch_id, user_ids) - @users = User.find_all_by_id(user_ids) - - batch = EmailBatch.where(:id => batch_id).limit(1).first + def _send_batch(batch, users) @body = batch.body + emails = users.map(&:email) + + sendgrid_recipients(emails) + sendgrid_substitute(EmailBatch::VAR_FIRST_NAME, users.map(&:first_name)) + + batch.did_send(emails) - substitute(EmailBatch::VAR_FIRST_NAME, @users.map(&:first_name)) - emails = @users.map(&:email) mail(:to => emails, :from => batch.from_email, :subject => batch.subject) do |format| format.text format.html end - batch.did_send(emails) + end + + def send_batch_email(batch_id, user_ids) + users = User.find_all_by_id(user_ids) + batch = EmailBatch.where(:id => batch_id).limit(1).first + self._send_batch(batch, users) end def send_batch_email_test(batch_id) batch = EmailBatch.where(:id => batch_id).limit(1).first - @body = batch.body - - @users = batch.test_users - emails = @users.map(&:email) - substitute(EmailBatch::VAR_FIRST_NAME, @users.map(&:first_name)) - mail(:to => emails, - :from => batch.from_email, - :subject => batch.subject) do |format| - format.text - format.html - end - batch.did_send(emails) + users = batch.test_users + self._send_batch(batch, users) end end diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb index a195a3ff4..9e1d84fb8 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb @@ -24,7 +24,7 @@

<%= yield(:title) %>

-

<%= yield %>

+

<%= @body %>


diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb index 8bd3c7483..37f361950 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb @@ -1,4 +1,4 @@ -<%= yield %> +<%= Nokogiri::HTML(@body).text %> <% unless @suppress_user_has_account_footer == true %> diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index f7ca64ddc..3dc8ef2c7 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -2,7 +2,8 @@ module JamRuby class EmailBatch < ActiveRecord::Base self.table_name = "email_batches" - attr_accessible :lock_version + attr_accessible :from_email, :subject, :test_emails, :body + attr_accessible :lock_version, :qualified_count, :sent_count, :started_at, :completed_at VAR_FIRST_NAME = '@FIRSTNAME' VAR_LAST_NAME = '@LASTNAME' @@ -21,16 +22,19 @@ module JamRuby event :enable do transitions :from => :disabled, :to => :pending end + event :reset do + transitions :from => [:disabled, :testing, :tested, :batching, :batched, :pending], :to => :pending + end event :do_test_run, :before => :running_tests do transitions :from => [:pending, :tested, :batched], :to => :testing end - event :did_test_run do + event :did_test_run, :after => :ran_tests do transitions :from => :testing, :to => :tested end event :do_batch_run, :before => :running_batch do transitions :from => [:tested, :pending, :batched], :to => :batching end - event :did_batch_run do + event :did_batch_run, :after => :ran_batch do transitions :from => :batching, :to => :batched end event :disable do @@ -45,8 +49,23 @@ module JamRuby .where(:opt_out_email_batch => false) end + def self.create_with_params(params) + obj = self.new + obj.update_with_params(params) + obj.save! + obj + end + + def update_with_params(params) + self.from_email = params[:from_email].strip + self.subject = params[:subject].strip + self.test_emails = params[:test_emails].strip + self.body = params[:body].strip + self + end + def deliver - self.do_batch_run! + self.perform_event('do_batch_run!') self.class.qualified_users.pluck(:id).find_in_batches(batch_size: 100) do |user_ids| BatchMailer.send_batch_email(self.id, user_ids).deliver end @@ -68,7 +87,7 @@ module JamRuby end def send_test_batch - self.do_test_run! + self.perform_event('do_test_run!') BatchMailer.send_batch_email_test(self.id).deliver end @@ -81,13 +100,24 @@ module JamRuby if self.sent_count >= self.qualified_count if batching? - self.did_batch_run! + self.perform_event('did_batch_run!') elsif testing? - self.did_test_run! + self.perform_event('did_test_run!') end end end + def perform_event(event_name) + num_try = 0 + self.send(event_name) + rescue ActiveRecord::StaleObjectError + num_try += 1 + if 5 > num_try + self.reload + retry + end + end + def update_with_conflict_validation(*args) num_try = 0 update_attributes(*args) @@ -98,17 +128,27 @@ module JamRuby retry end end - + def running_batch - self.update_attributes({:qualified_count => self.class.qualified_users.count, - :sent_count => 0 - }) + self.update_with_conflict_validation({:qualified_count => self.class.qualified_users.count, + :sent_count => 0, + :started_at => Time.now + }) end def running_tests - self.update_attributes({:qualified_count => self.class.qualified_users.count, - :sent_count => 0 - }) + self.update_with_conflict_validation({:qualified_count => self.test_count, + :sent_count => 0, + :started_at => Time.now + }) + end + + def ran_tests + self.update_with_conflict_validation({ :completed_at => Time.now }) + end + + def ran_batch + self.update_with_conflict_validation({ :completed_at => Time.now }) end end From 0987cf2cf8f6f8b91c10e7d9c9989f9765480674 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 16:37:03 +0000 Subject: [PATCH 13/17] VRFS-1483 editing batch emails --- admin/Gemfile | 4 +- admin/app/admin/email_batch.rb | 53 +++++++++++++++++++ .../views/admin/batch_emails/_form.html.erb | 9 ++++ ruby/Gemfile | 3 +- web/Gemfile | 3 +- web/config/application.rb | 4 +- web/config/environments/development.rb | 4 +- web/config/initializers/resque_mailer.rb | 1 + 8 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 admin/app/admin/email_batch.rb create mode 100644 admin/app/views/admin/batch_emails/_form.html.erb create mode 100644 web/config/initializers/resque_mailer.rb diff --git a/admin/Gemfile b/admin/Gemfile index 5ec8a3411..5fea93d71 100644 --- a/admin/Gemfile +++ b/admin/Gemfile @@ -65,10 +65,11 @@ gem 'logging-rails', :require => 'logging/rails' gem 'pg_migrate' gem 'ruby-protocol-buffers', '1.2.2' -gem 'sendgrid', '1.1.0' +gem 'sendgrid', '1.2.0' gem 'geokit-rails' gem 'postgres_ext', '1.0.0' +gem 'resque_mailer' group :libv8 do gem 'libv8', "~> 3.11.8" @@ -106,6 +107,7 @@ group :development, :test do gem 'factory_girl_rails', '4.1.0' gem 'database_cleaner', '0.7.0' gem 'launchy' + gem 'faker' end group :test do diff --git a/admin/app/admin/email_batch.rb b/admin/app/admin/email_batch.rb new file mode 100644 index 000000000..8aaa0700b --- /dev/null +++ b/admin/app/admin/email_batch.rb @@ -0,0 +1,53 @@ +ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do + + menu :label => 'Emails' + + config.sort_order = 'updated_at DESC' + config.batch_actions = false + # config.clear_action_items! + config.filters = false + + form :partial => 'form' + + index do + column 'Subject' do |pp| pp.subject end + column 'Updated' do |pp| pp.updated_at end + column 'From' do |pp| pp.from_email end + column 'Status' do |pp| pp.aasm_state end + column 'Test Emails' do |pp| pp.test_emails end + column 'Email Count' do |pp| pp.qualified_count end + column 'Send Count' do |pp| pp.sent_count end + column 'Started At' do |pp| pp.started_at end + column 'Completed At' do |pp| pp.completed_at end + + default_actions + end + + # show do + # attributes_table do + # row 'Who?' do |obj| obj.text_short end + # row 'Quote' do |obj| obj.text_long end + # row :image do |obj| + # image_tag(obj.image_url, :size => '50x50') + # end + # row 'State' do |obj| obj.aasm_state end + # row 'Position' do |obj| obj.position end + # row 'Updated' do |obj| obj.updated_at end + # end + # end + + controller do + + def create + EmailBatch.create_with_params(params[:jam_ruby_email_batch]) + redirect_to admin_batch_emails_path + end + + def update + resource.update_with_conflict_validation(params[:jam_ruby_email_batch]) + redirect_to admin_batch_email_path(resource.id) + end + + end + +end diff --git a/admin/app/views/admin/batch_emails/_form.html.erb b/admin/app/views/admin/batch_emails/_form.html.erb new file mode 100644 index 000000000..a9c83f836 --- /dev/null +++ b/admin/app/views/admin/batch_emails/_form.html.erb @@ -0,0 +1,9 @@ +<%= semantic_form_for([:admin, resource], :url => resource.new_record? ? admin_batch_emails_path : "/admin/batch_emails/#{resource.id}") do |f| %> + <%= f.inputs do %> + <%= f.input(:from_email, :label => "From Email", :input_html => {:maxlength => 64}) %> + <%= f.input(:subject, :label => "Subject", :input_html => {:maxlength => 128}) %> + <%= f.input(:test_emails, :label => "Test Emails", :input_html => {:maxlength => 1024, :size => '3x3'}) %> + <%= f.input(:body, :label => "Body", :input_html => {:maxlength => 3096, :size => '10x20'}) %> + <% end %> + <%= f.actions %> +<% end %> diff --git a/ruby/Gemfile b/ruby/Gemfile index ae98be72b..cd4bca5ec 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -27,7 +27,7 @@ gem 'eventmachine', '1.0.3' gem 'amqp', '1.0.2' gem 'will_paginate' gem 'actionmailer', '3.2.13' -gem 'sendgrid' +gem 'sendgrid', '1.2.0' gem 'aws-sdk', '1.29.1' gem 'carrierwave' gem 'aasm', '3.0.16' @@ -41,7 +41,6 @@ gem 'resque-retry' gem 'resque-failed-job-mailer' #, :path => "/Users/seth/workspace/resque_failed_job_mailer" gem 'resque-lonely_job', '~> 1.0.0' gem 'resque_mailer' -gem 'sendgrid_smtpapi' gem 'oj' gem 'builder' gem 'fog' diff --git a/web/Gemfile b/web/Gemfile index af835a453..f2cdab689 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -45,7 +45,7 @@ gem 'omniauth-twitter' gem 'omniauth-google-oauth2', '0.2.1' gem 'twitter' gem 'fb_graph', '2.5.9' -gem 'sendgrid', '1.1.0' +gem 'sendgrid', '1.2.0' gem 'recaptcha', '0.3.4' gem 'filepicker-rails', '0.1.0' gem 'aws-sdk', '1.29.1' @@ -68,6 +68,7 @@ gem 'resque-failed-job-mailer' gem 'resque-dynamic-queues' gem 'resque-lonely_job', '~> 1.0.0' gem 'resque_mailer' + gem 'quiet_assets', :group => :development gem 'bugsnag' gem 'multi_json', '1.9.0' diff --git a/web/config/application.rb b/web/config/application.rb index 5f1e18959..ff213c11a 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -107,8 +107,8 @@ if defined?(Bundler) config.websocket_gateway_connect_time_stale = 2 config.websocket_gateway_connect_time_expire = 5 else - config.websocket_gateway_connect_time_stale = 12 # 12 matches production - config.websocket_gateway_connect_time_expire = 20 # 20 matches production + config.websocket_gateway_connect_time_stale = 60000 # 12 matches production + config.websocket_gateway_connect_time_expire = 100000 # 20 matches production end config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6767 + ENV['JAM_INSTANCE'].to_i diff --git a/web/config/environments/development.rb b/web/config/environments/development.rb index 188a87ed9..91835c64b 100644 --- a/web/config/environments/development.rb +++ b/web/config/environments/development.rb @@ -68,8 +68,8 @@ SampleApp::Application.configure do # it's nice to have even admin accounts (which all the default ones are) generate GA data for testing config.ga_suppress_admin = false - config.websocket_gateway_connect_time_stale = 12 # 12 matches production - config.websocket_gateway_connect_time_expire = 20 # 20 matches production + config.websocket_gateway_connect_time_stale = 60000 + config.websocket_gateway_connect_time_expire = 100000 config.audiomixer_path = ENV['AUDIOMIXER_PATH'] || audiomixer_workspace_path || "/var/lib/audiomixer/audiomixer/audiomixerapp" diff --git a/web/config/initializers/resque_mailer.rb b/web/config/initializers/resque_mailer.rb new file mode 100644 index 000000000..5a9e2bcdb --- /dev/null +++ b/web/config/initializers/resque_mailer.rb @@ -0,0 +1 @@ +Resque::Mailer.excluded_environments = [:test, :cucumber] From 22104e3a977933ecd390a65965d08f78394d8f57 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 16:38:59 +0000 Subject: [PATCH 14/17] VRFS-1483 undoing accidently checkin of wsg connect params --- web/config/application.rb | 4 ++-- web/config/environments/development.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/config/application.rb b/web/config/application.rb index ff213c11a..5f1e18959 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -107,8 +107,8 @@ if defined?(Bundler) config.websocket_gateway_connect_time_stale = 2 config.websocket_gateway_connect_time_expire = 5 else - config.websocket_gateway_connect_time_stale = 60000 # 12 matches production - config.websocket_gateway_connect_time_expire = 100000 # 20 matches production + config.websocket_gateway_connect_time_stale = 12 # 12 matches production + config.websocket_gateway_connect_time_expire = 20 # 20 matches production end config.websocket_gateway_internal_debug = false config.websocket_gateway_port = 6767 + ENV['JAM_INSTANCE'].to_i diff --git a/web/config/environments/development.rb b/web/config/environments/development.rb index 91835c64b..017f717a1 100644 --- a/web/config/environments/development.rb +++ b/web/config/environments/development.rb @@ -68,8 +68,8 @@ SampleApp::Application.configure do # it's nice to have even admin accounts (which all the default ones are) generate GA data for testing config.ga_suppress_admin = false - config.websocket_gateway_connect_time_stale = 60000 - config.websocket_gateway_connect_time_expire = 100000 + config.websocket_gateway_connect_time_stale = 12 + config.websocket_gateway_connect_time_expire = 20 config.audiomixer_path = ENV['AUDIOMIXER_PATH'] || audiomixer_workspace_path || "/var/lib/audiomixer/audiomixer/audiomixerapp" From eecdbebf3de7b340c328e96db87f96c1bea71c94 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 19 Mar 2014 18:42:28 +0000 Subject: [PATCH 15/17] VRFS-1483 integrating admin interface --- admin/app/admin/email_batch.rb | 64 +++++++++++++++---- .../app/views/layouts/batch_mailer.html.erb | 2 +- ruby/lib/jam_ruby/models/email_batch.rb | 11 +--- ruby/lib/jam_ruby/models/user.rb | 1 + 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/admin/app/admin/email_batch.rb b/admin/app/admin/email_batch.rb index 8aaa0700b..bd934f6da 100644 --- a/admin/app/admin/email_batch.rb +++ b/admin/app/admin/email_batch.rb @@ -23,18 +23,46 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do default_actions end - # show do - # attributes_table do - # row 'Who?' do |obj| obj.text_short end - # row 'Quote' do |obj| obj.text_long end - # row :image do |obj| - # image_tag(obj.image_url, :size => '50x50') - # end - # row 'State' do |obj| obj.aasm_state end - # row 'Position' do |obj| obj.position end - # row 'Updated' do |obj| obj.updated_at end - # end - # end + action_item :only => :show do + link_to("Run Test Batch (#{resource.test_count})", + "/admin/batch_emails/#{resource.id}/batch_test", + :confirm => "Run test batch with #{resource.test_count} emails?") + end + + action_item :only => :show do + link_to("Run Live Batch (#{User.email_opt_in.count})", + "/admin/batch_emails/#{resource.id}/batch_send", + :confirm => "Run LIVE batch with #{User.email_opt_in.count} emails?") + end + + show :title => 'Batch Email' do |obj| + panel 'Email Contents' do + attributes_table_for obj do + row 'Subject' do |obj| obj.subject end + row 'From' do |obj| obj.from_email end + row 'Test Emails' do |obj| obj.test_emails end + row 'Body' do |obj| obj.body end + row 'State' do |obj| obj.aasm_state end + end + end + columns do + column do + panel 'Sending Parameters' do + attributes_table_for obj do + row 'Opt-in User Count' do |obj| User.email_opt_in.count end + row 'Sent Count' do |obj| obj.sent_count end + row 'Started At' do |obj| obj.started_at end + row 'Completed At' do |obj| obj.completed_at end + row 'Updated' do |obj| obj.updated_at end + end + end + end + column do + panel 'Send Results' do + end + end + end + end controller do @@ -50,4 +78,16 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do end + member_action :batch_test, :method => :get do + batch = EmailBatch.find(params[:id]) + batch.send_test_batch + redirect_to admin_batch_email_path(batch.id) + end + + member_action :batch_send, :method => :get do + batch = EmailBatch.find(params[:id]) + batch.deliver_batch + redirect_to admin_batch_email_path(batch.id) + end + end diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb index 9e1d84fb8..1cf0d1605 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb @@ -24,7 +24,7 @@

<%= yield(:title) %>

-

<%= @body %>

+

<%= @body.html_safe %>


diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 3dc8ef2c7..1910cd7ff 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -44,11 +44,6 @@ module JamRuby # has_many :email_batch_results, :class_name => 'JamRuby::EmailBatchResult' - def self.qualified_users - User.select(:email) - .where(:opt_out_email_batch => false) - end - def self.create_with_params(params) obj = self.new obj.update_with_params(params) @@ -64,9 +59,9 @@ module JamRuby self end - def deliver + def deliver_batch self.perform_event('do_batch_run!') - self.class.qualified_users.pluck(:id).find_in_batches(batch_size: 100) do |user_ids| + User.email_opt_in.pluck(:id).find_in_batches(batch_size: 1000) do |user_ids| BatchMailer.send_batch_email(self.id, user_ids).deliver end end @@ -130,7 +125,7 @@ module JamRuby end def running_batch - self.update_with_conflict_validation({:qualified_count => self.class.qualified_users.count, + self.update_with_conflict_validation({:qualified_count => User.email_opt_in.count, :sent_count => 0, :started_at => Time.now }) diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 93f73d829..0fa73c0a5 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -132,6 +132,7 @@ module JamRuby scope :fans, where(:musician => false) scope :geocoded_users, where(['lat IS NOT NULL AND lng IS NOT NULL']) scope :musicians_geocoded, musicians.geocoded_users + scope :email_opt_in, where(:opt_out_email_batch => false) def user_progression_fields @user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_recording_at", "first_social_promoted_at" ] From accaa99e38745726d2c6efc49f1de43f7a430a9f Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 1 Apr 2014 14:42:26 +0000 Subject: [PATCH 16/17] VRFS-1483 integrating opt-out; fixing tests --- admin/app/admin/email_batch.rb | 39 ++++++++++++------- db/up/emails.sql | 24 ++++++------ ruby/lib/jam_ruby/app/mailers/batch_mailer.rb | 4 +- .../app/views/layouts/user_mailer.html.erb | 6 +-- .../app/views/layouts/user_mailer.text.erb | 9 +++-- ruby/lib/jam_ruby/models/email_batch.rb | 16 ++------ ruby/lib/jam_ruby/models/user.rb | 2 +- ruby/spec/jam_ruby/models/email_batch_spec.rb | 3 +- ruby/spec/mailers/batch_mailer_spec.rb | 2 + 9 files changed, 57 insertions(+), 48 deletions(-) diff --git a/admin/app/admin/email_batch.rb b/admin/app/admin/email_batch.rb index bd934f6da..3f15aadd3 100644 --- a/admin/app/admin/email_batch.rb +++ b/admin/app/admin/email_batch.rb @@ -17,42 +17,54 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do column 'Test Emails' do |pp| pp.test_emails end column 'Email Count' do |pp| pp.qualified_count end column 'Send Count' do |pp| pp.sent_count end - column 'Started At' do |pp| pp.started_at end - column 'Completed At' do |pp| pp.completed_at end + column 'Started' do |pp| pp.started_at end + column 'Completed' do |pp| pp.completed_at end + column 'Send Test' do |pp| + link_to("Test Batch (#{pp.test_count})", + batch_test_admin_batch_email_path(pp.id), + :confirm => "Run test batch with #{pp.test_count} emails?") + end + column 'Send Live' do |pp| + link_to("Live Batch (#{User.email_opt_in.count})", + batch_send_admin_batch_email_path(pp.id), + :confirm => "Run LIVE batch with #{User.email_opt_in.count} emails?") + end default_actions end action_item :only => :show do - link_to("Run Test Batch (#{resource.test_count})", - "/admin/batch_emails/#{resource.id}/batch_test", + link_to("Send Test Batch (#{resource.test_count})", + batch_test_admin_batch_email_path(resource.id), :confirm => "Run test batch with #{resource.test_count} emails?") end action_item :only => :show do - link_to("Run Live Batch (#{User.email_opt_in.count})", - "/admin/batch_emails/#{resource.id}/batch_send", + link_to("Send Live Batch (#{User.email_opt_in.count})", + batch_send_admin_batch_email_path(resource.id), :confirm => "Run LIVE batch with #{User.email_opt_in.count} emails?") end show :title => 'Batch Email' do |obj| panel 'Email Contents' do attributes_table_for obj do - row 'Subject' do |obj| obj.subject end row 'From' do |obj| obj.from_email end row 'Test Emails' do |obj| obj.test_emails end + row 'Subject' do |obj| obj.subject end row 'Body' do |obj| obj.body end - row 'State' do |obj| obj.aasm_state end end end columns do column do panel 'Sending Parameters' do attributes_table_for obj do - row 'Opt-in User Count' do |obj| User.email_opt_in.count end + row 'State' do |obj| obj.aasm_state end + row 'User Count' do |obj| + obj.qualified_count ? obj.qualified_count : User.email_opt_in.count + end row 'Sent Count' do |obj| obj.sent_count end - row 'Started At' do |obj| obj.started_at end - row 'Completed At' do |obj| obj.completed_at end + row 'Started' do |obj| obj.started_at end + row 'Completed' do |obj| obj.completed_at end row 'Updated' do |obj| obj.updated_at end end end @@ -67,8 +79,9 @@ ActiveAdmin.register JamRuby::EmailBatch, :as => 'Batch Emails' do controller do def create - EmailBatch.create_with_params(params[:jam_ruby_email_batch]) - redirect_to admin_batch_emails_path + batch = EmailBatch.create_with_params(params[:jam_ruby_email_batch]) + redirect_to admin_batch_email_path(batch.id) + # redirect_to admin_batch_emails_path end def update diff --git a/db/up/emails.sql b/db/up/emails.sql index 9c68b643e..86f8b4f6f 100644 --- a/db/up/emails.sql +++ b/db/up/emails.sql @@ -20,19 +20,19 @@ CREATE TABLE email_batches ( updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); -CREATE TABLE email_batch_results ( - id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), - email_batch_id VARCHAR(64) REFERENCES email_batches(id) ON DELETE CASCADE, - user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, +-- CREATE TABLE email_batch_results ( +-- id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), +-- email_batch_id VARCHAR(64) REFERENCES email_batches(id) ON DELETE CASCADE, +-- user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, - error_type VARCHAR(32), - email_address VARCHAR(256), +-- error_type VARCHAR(32), +-- email_address VARCHAR(256), - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); +-- created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +-- updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +-- ); -ALTER TABLE email_batch_results ADD CONSTRAINT email_batch_uniqkey UNIQUE (email_batch_id); -ALTER TABLE email_batch_results ADD CONSTRAINT email_user_uniqkey UNIQUE (user_id); +-- ALTER TABLE email_batch_results ADD CONSTRAINT email_batch_uniqkey UNIQUE (email_batch_id); +-- ALTER TABLE email_batch_results ADD CONSTRAINT email_user_uniqkey UNIQUE (user_id); -ALTER TABLE users ADD COLUMN opt_out_email_batch boolean DEFAULT false; +ALTER TABLE users ALTER COLUMN subscribe_email SET DEFAULT true; diff --git a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb index 76af3a456..11e21efd2 100644 --- a/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/batch_mailer.rb @@ -1,12 +1,12 @@ module JamRuby class BatchMailer < JamRuby::AsyncMailer - layout "batch_mailer" + layout "user_mailer" sendgrid_category :use_subject_lines sendgrid_unique_args :env => Environment.mode def _send_batch(batch, users) - @body = batch.body + @batch_body = batch.body emails = users.map(&:email) sendgrid_recipients(emails) diff --git a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb index 6fcd69d53..1198a26f4 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.html.erb @@ -24,13 +24,11 @@

<%= yield(:title) %>

-

<%= yield %>

+

<%= @batch_body ? @batch_body.html_safe : yield %>


- - <% unless @suppress_user_has_account_footer == true %> @@ -39,8 +37,8 @@ +

This email was sent to you because you have an account at JamKazam.  Click here to unsubscribe and update your profile settings.

-

This email was sent to you because you have an account at JamKazam. diff --git a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.text.erb b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.text.erb index 8bd3c7483..5c8262f63 100644 --- a/ruby/lib/jam_ruby/app/views/layouts/user_mailer.text.erb +++ b/ruby/lib/jam_ruby/app/views/layouts/user_mailer.text.erb @@ -1,8 +1,11 @@ -<%= yield %> - +<% if @batch_body %> + <%= Nokogiri::HTML(@batch_body).text %> +<% else %> + <%= yield %> +<% end %> <% unless @suppress_user_has_account_footer == true %> -This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. +This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. Visit your profile page to unsubscribe: http://www.jamkazam.com/client#/account/profile. <% end %> Copyright <%= Time.now.year %> JamKazam, Inc. All rights reserved. diff --git a/ruby/lib/jam_ruby/models/email_batch.rb b/ruby/lib/jam_ruby/models/email_batch.rb index 1910cd7ff..a2fd36387 100644 --- a/ruby/lib/jam_ruby/models/email_batch.rb +++ b/ruby/lib/jam_ruby/models/email_batch.rb @@ -46,23 +46,15 @@ module JamRuby def self.create_with_params(params) obj = self.new - obj.update_with_params(params) - obj.save! + params.each { |kk,vv| vv.strip! } + obj.update_with_conflict_validation(params) obj end - def update_with_params(params) - self.from_email = params[:from_email].strip - self.subject = params[:subject].strip - self.test_emails = params[:test_emails].strip - self.body = params[:body].strip - self - end - def deliver_batch self.perform_event('do_batch_run!') - User.email_opt_in.pluck(:id).find_in_batches(batch_size: 1000) do |user_ids| - BatchMailer.send_batch_email(self.id, user_ids).deliver + User.email_opt_in.find_in_batches(batch_size: 1000) do |users| + BatchMailer.send_batch_email(self.id, users.map(&:id)).deliver end end diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 7651d14ca..1ff5f9513 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -132,7 +132,7 @@ module JamRuby scope :fans, where(:musician => false) scope :geocoded_users, where(['lat IS NOT NULL AND lng IS NOT NULL']) scope :musicians_geocoded, musicians.geocoded_users - scope :email_opt_in, where(:opt_out_email_batch => false) + scope :email_opt_in, where(:subscribe_email => true) def user_progression_fields @user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_recording_at", "first_social_promoted_at" ] diff --git a/ruby/spec/jam_ruby/models/email_batch_spec.rb b/ruby/spec/jam_ruby/models/email_batch_spec.rb index 19d8a125f..e3b14c32d 100644 --- a/ruby/spec/jam_ruby/models/email_batch_spec.rb +++ b/ruby/spec/jam_ruby/models/email_batch_spec.rb @@ -9,9 +9,10 @@ describe EmailBatch do it 'has test emails setup' do expect(email_batch.test_emails.present?).to be true + expect(email_batch.pending?).to be true users = email_batch.test_users - expect(email_batch.merged_body(users[0])).to match(/#{users[0].first_name} #{email_batch.body}/) + expect(email_batch.test_count).to eq(users.count) end end diff --git a/ruby/spec/mailers/batch_mailer_spec.rb b/ruby/spec/mailers/batch_mailer_spec.rb index a2d45dd6c..a1a216607 100644 --- a/ruby/spec/mailers/batch_mailer_spec.rb +++ b/ruby/spec/mailers/batch_mailer_spec.rb @@ -3,6 +3,8 @@ require "spec_helper" describe BatchMailer do describe "should send test emails" do + BatchMailer.deliveries.clear + let (:mail) { BatchMailer.deliveries[0] } batch = FactoryGirl.create(:email_batch) From 3509a84de5daa8ea33ad1081c26c3614032e7294 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Tue, 1 Apr 2014 14:51:45 +0000 Subject: [PATCH 17/17] VRFS-1483 replaced layout with user_mailer --- .../app/views/layouts/batch_mailer.html.erb | 54 ------------------- .../app/views/layouts/batch_mailer.text.erb | 8 --- 2 files changed, 62 deletions(-) delete mode 100644 ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb delete mode 100644 ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb deleted file mode 100644 index 1cf0d1605..000000000 --- a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.html.erb +++ /dev/null @@ -1,54 +0,0 @@ - - - - - JamKazam - - - - - - - - - - -
JamKazam
- - - - - - - - - -

<%= yield(:title) %>

-

<%= @body.html_safe %>

-
-
- - -
- - -

-

This email was sent to you because you have an account at JamKazam. -

- -
- - - - -
Copyright © <%= Time.now.year %> JamKazam, Inc. All rights reserved. -
- - - diff --git a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb b/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb deleted file mode 100644 index 37f361950..000000000 --- a/ruby/lib/jam_ruby/app/views/layouts/batch_mailer.text.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= Nokogiri::HTML(@body).text %> - - -<% unless @suppress_user_has_account_footer == true %> -This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. -<% end %> - -Copyright <%= Time.now.year %> JamKazam, Inc. All rights reserved.