VRFS-1483 integrating opt-out; fixing tests
This commit is contained in:
parent
e29907f09b
commit
accaa99e38
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -24,13 +24,11 @@
|
|||
|
||||
<tr>
|
||||
<td align="left"><h1 style="font-size:22px;font-weight:normal;margin-top:0px"><font color="#F34E1C" face="Arial, Helvetica, sans-serif"><%= yield(:title) %></font></h1>
|
||||
<p><font size="3" color="#AAAAAA" face="Arial, Helvetica, sans-serif"><%= yield %></font></p>
|
||||
<p><font size="3" color="#AAAAAA" face="Arial, Helvetica, sans-serif"><%= @batch_body ? @batch_body.html_safe : yield %></font></p>
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<% unless @suppress_user_has_account_footer == true %>
|
||||
<tr>
|
||||
<td>
|
||||
|
|
@ -39,8 +37,8 @@
|
|||
<td align="left">
|
||||
|
||||
<!-- CALL OUT BOX -->
|
||||
<p style="margin-top:0px"><font size="2" color="#7FACBA" face="Arial, Helvetica, sans-serif">This email was sent to you because you have an account at <a style="color: #588C98;" href="http://www.jamkazam.com">JamKazam</a>. Click <a style="color: #588C98;" href="http://www.jamkazam.com/client#/account/profile">here to unsubscribe</a> and update your profile settings.
|
||||
</font></p>
|
||||
<p style="margin-top:0px"><font size="2" color="#7FACBA" face="Arial, Helvetica, sans-serif">This email was sent to you because you have an account at <a style="color: #588C98;" href="http://www.jamkazam.com">JamKazam</a>.
|
||||
</td></tr></table>
|
||||
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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" ]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue