mail_manager 3.2.6 → 3.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -4
- data/app/assets/stylesheets/mail_manager/admin.css +18 -3
- data/app/models/mail_manager/mailable_registry.rb +5 -0
- data/app/models/mail_manager/mailer.rb +3 -2
- data/app/models/mail_manager/mailing.rb +15 -9
- data/app/models/mail_manager/mailing_list.rb +5 -2
- data/app/models/mail_manager/message.rb +7 -2
- data/app/views/mail_manager/bounces/index.html.erb +1 -1
- data/lib/mail_manager/engine.rb +3 -0
- data/lib/mail_manager/version.rb +1 -1
- data/lib/tasks/mail_manager.rake +1 -0
- data/mail_manager.gemspec +0 -7
- data/spec/test_app/.env.test +2 -2
- data/spec/test_app/script/post_office +1 -1
- data/spec/test_app/spec/features/mail_manager/bounce_spec.rb +32 -4
- data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +17 -0
- data/spec/test_app/spec/models/mail_manager/mailing_spec.rb +67 -5
- metadata +3 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7086dba0cddea0712c21f6c60b68081d53aa2d5d
|
4
|
+
data.tar.gz: ff73fe7f60296ab4368baa6ac7b91268be0528ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0119d6ab3f1bc2f1f64680a1178eaf84ee25b61f809c452276178e471f9b0799fffb4442a1b35c2b4fa03f211ed90b3b622dcd6d1ee592a7d396d7e0473e8a1
|
7
|
+
data.tar.gz: 8d41ad9933f4f6b610ded97d39e31c76006d427e82da9f7ac38f0c6c78860b0b0e592572c4458d8725fe61c930a2f1784e95a0d2c32def26402c7155bc5d76dd
|
data/Gemfile
CHANGED
@@ -25,12 +25,13 @@ group :test, :development do
|
|
25
25
|
gem 'quiet_assets'
|
26
26
|
gem "factory_girl_rails", "~>4.3"
|
27
27
|
gem "faker"
|
28
|
+
gem 'post_office'
|
28
29
|
end
|
29
30
|
|
30
|
-
group :test, :development, :post_office do
|
31
|
-
gem 'dotenv'
|
32
|
-
gem 'post_office', "~>0.3"
|
33
|
-
end
|
31
|
+
#group :test, :development, :post_office do
|
32
|
+
# gem 'dotenv'
|
33
|
+
# gem 'post_office', "~>0.3"
|
34
|
+
#end
|
34
35
|
|
35
36
|
|
36
37
|
# Testing Gems
|
@@ -12,6 +12,15 @@ body {
|
|
12
12
|
height: 85px;
|
13
13
|
min-width: 766px;
|
14
14
|
}
|
15
|
+
|
16
|
+
.menu_expand {
|
17
|
+
cursor: pointer;
|
18
|
+
}
|
19
|
+
|
20
|
+
span.menu_expand:hover {
|
21
|
+
color: #fc6;
|
22
|
+
}
|
23
|
+
|
15
24
|
/*
|
16
25
|
img {
|
17
26
|
display: block;
|
@@ -129,7 +138,9 @@ table.list tr.even {
|
|
129
138
|
background: #e2e8d9;
|
130
139
|
}
|
131
140
|
|
132
|
-
|
141
|
+
.mailing_buttons {
|
142
|
+
width: 310px;
|
143
|
+
}
|
133
144
|
/* form labels have different alignment*/
|
134
145
|
label {font-size: 11pt;
|
135
146
|
font-family: helvetica, arial, sans-serif;
|
@@ -143,6 +154,10 @@ label {font-size: 11pt;
|
|
143
154
|
padding: 7px 7px 0 0;
|
144
155
|
}
|
145
156
|
|
157
|
+
.field {
|
158
|
+
clear: both;
|
159
|
+
}
|
160
|
+
|
146
161
|
input, select, textarea {
|
147
162
|
margin: 6px 0;
|
148
163
|
padding: 2px;
|
@@ -173,7 +188,7 @@ input.button {
|
|
173
188
|
font-size: 11pt;
|
174
189
|
font-weight: bold;
|
175
190
|
color: #555;
|
176
|
-
margin-right:
|
191
|
+
margin-right: 5px;
|
177
192
|
cursor: pointer;
|
178
193
|
}
|
179
194
|
|
@@ -210,7 +225,7 @@ a.button:link, a.button:visited {
|
|
210
225
|
font-size: 11pt;
|
211
226
|
font-weight: bold;
|
212
227
|
color: #555;
|
213
|
-
margin-right:
|
228
|
+
margin-right: 5px;
|
214
229
|
/* do I need this? */
|
215
230
|
cursor: pointer;
|
216
231
|
}
|
@@ -75,6 +75,11 @@ module MailManager
|
|
75
75
|
@@mailable_things.merge!({klass => methods})
|
76
76
|
end
|
77
77
|
|
78
|
+
# unregister a mailable
|
79
|
+
def self.unregister(klass)
|
80
|
+
@@mailable_things.delete(klass)
|
81
|
+
end
|
82
|
+
|
78
83
|
=begin rdoc
|
79
84
|
Finds available mailable items by searching through all registered mailables, calling their finders and sorting by name.
|
80
85
|
=end
|
@@ -50,9 +50,10 @@ module MailManager
|
|
50
50
|
|
51
51
|
class << self
|
52
52
|
# send a mailing related to the message's data
|
53
|
-
def deliver_message(message)
|
53
|
+
def deliver_message(message, cached_parts=nil)
|
54
|
+
cached_parts ||= message.parts
|
54
55
|
self.send_mail(message.subject,message.email_address_with_name,message.from_email_address,
|
55
|
-
|
56
|
+
cached_parts,message.guid,message.mailing.include_images?)
|
56
57
|
end
|
57
58
|
|
58
59
|
# create mailing; parsing html sources for images to attach/include
|
@@ -16,7 +16,7 @@ completed - Mailing has been sent
|
|
16
16
|
module MailManager
|
17
17
|
class Mailing < ActiveRecord::Base
|
18
18
|
self.table_name = "#{MailManager.table_prefix}mailings"
|
19
|
-
has_many :messages, :class_name => 'MailManager::Message'
|
19
|
+
has_many :messages, :class_name => 'MailManager::Message', inverse_of: :mailing
|
20
20
|
has_many :test_messages, :class_name => 'MailManager::TestMessage'
|
21
21
|
has_many :bounces, :class_name => 'MailManager::Bounce'
|
22
22
|
has_and_belongs_to_many :mailing_lists, :class_name => 'MailManager::MailingList',
|
@@ -63,15 +63,14 @@ module MailManager
|
|
63
63
|
end
|
64
64
|
change_status(:processing)
|
65
65
|
initialize_messages
|
66
|
-
messages.pending.each do |message|
|
66
|
+
messages.pending.limit(MailManager.deliveries_per_run).each do |message|
|
67
67
|
if reload.status.to_s != 'processing'
|
68
68
|
Rails.logger.warn "Mailing #{id} is no longer in processing status it was changed to #{status} while running"
|
69
69
|
return false
|
70
70
|
end
|
71
71
|
begin
|
72
|
-
# use the cached mailing parts
|
73
|
-
message.
|
74
|
-
message.deliver
|
72
|
+
# should use the cached mailing parts as mailing object for message should be the same as its caller
|
73
|
+
message.deliver(raw_parts)
|
75
74
|
rescue => e
|
76
75
|
message.result = "Error: #{e.message} - #{e.backtrace.join("\n")}"
|
77
76
|
message.change_status(:failed)
|
@@ -79,13 +78,17 @@ module MailManager
|
|
79
78
|
Rails.logger.debug "Sleeping #{MailManager.sleep_time_between_messages} before next message"
|
80
79
|
sleep MailManager.sleep_time_between_messages
|
81
80
|
end
|
82
|
-
|
81
|
+
if messages.pending.count == 0
|
82
|
+
change_status(:completed)
|
83
|
+
else
|
84
|
+
self.delay(run_at: [scheduled_at,Time.now.utc].max).deliver
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
89
|
def mailable
|
87
90
|
return @mailable if @mailable
|
88
|
-
return
|
91
|
+
return (@mailable=nil) if mailable_type.nil? or mailable_id.nil?
|
89
92
|
@mailable = mailable_type.constantize.find(mailable_id)
|
90
93
|
end
|
91
94
|
|
@@ -121,9 +124,10 @@ module MailManager
|
|
121
124
|
@raw_parts ||= mailable.mailable_parts
|
122
125
|
end
|
123
126
|
|
124
|
-
def parts(substitutions={})
|
127
|
+
def parts(substitutions={}, cached_parts=nil)
|
128
|
+
cached_parts ||= raw_parts
|
125
129
|
parts = []
|
126
|
-
|
130
|
+
cached_parts.each do |type,source|
|
127
131
|
parts << [type, Mailing.substitute_values(source.dup,substitutions)]
|
128
132
|
end
|
129
133
|
parts
|
@@ -133,6 +137,7 @@ module MailManager
|
|
133
137
|
return if value.nil?
|
134
138
|
self[:mailable_type] = value.class.name
|
135
139
|
self[:mailable_id] = value.id
|
140
|
+
@mailable = value
|
136
141
|
end
|
137
142
|
|
138
143
|
def mailable_class_and_id=(value)
|
@@ -200,6 +205,7 @@ module MailManager
|
|
200
205
|
end
|
201
206
|
|
202
207
|
def can_run?
|
208
|
+
# processing is allowed for failed job reset and is OK since we lock around whole job
|
203
209
|
['scheduled','processing'].include?(status.to_s)
|
204
210
|
end
|
205
211
|
|
@@ -24,12 +24,14 @@ module MailManager
|
|
24
24
|
|
25
25
|
attr_protected :id
|
26
26
|
|
27
|
+
# custom query to efficiently retrieve the active email addresses and contact ids and subscription ids for a
|
28
|
+
# given list of mailing lists
|
27
29
|
def self.active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids(mailing_list_ids)
|
28
30
|
results = MailManager::MailingList.connection.execute(
|
29
31
|
%Q|select c.email_address as email_address, c.id as contact_id,
|
30
32
|
s.id as subscription_id from #{MailManager.table_prefix}contacts c
|
31
33
|
inner join #{MailManager.table_prefix}subscriptions s on c.id=s.contact_id
|
32
|
-
where s.status in ('active') and mailing_list_id in (#{
|
34
|
+
where s.status in ('active') and c.deleted_at is NULL and mailing_list_id in (#{
|
33
35
|
mailing_list_ids.join(',')})|
|
34
36
|
)
|
35
37
|
results = results.map(&:values) if results.first.is_a?(Hash)
|
@@ -40,11 +42,12 @@ module MailManager
|
|
40
42
|
}
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
# whether or not the mailing list has been soft deleted
|
44
46
|
def active?
|
45
47
|
deleted_at.nil?
|
46
48
|
end
|
47
49
|
|
50
|
+
# whether or not the mailing list has been soft deleted
|
48
51
|
def inactive?
|
49
52
|
!active?
|
50
53
|
end
|
@@ -80,7 +80,7 @@ module MailManager
|
|
80
80
|
end
|
81
81
|
|
82
82
|
# sends the message through Mailer
|
83
|
-
def deliver
|
83
|
+
def deliver(cached_parts=nil)
|
84
84
|
# lock only needed until status is updated
|
85
85
|
Lock.with_lock("deliver_message_#{self.id}") do
|
86
86
|
reload
|
@@ -90,7 +90,12 @@ module MailManager
|
|
90
90
|
Rails.logger.warn "Message(#{self.id})'s is no longer suitable to deliver.. staus: #{status}"
|
91
91
|
end
|
92
92
|
end
|
93
|
-
|
93
|
+
cached_parts = if cached_parts.present?
|
94
|
+
mailing.parts(substitutions, cached_parts.dup)
|
95
|
+
else
|
96
|
+
parts
|
97
|
+
end
|
98
|
+
MailManager::Mailer.deliver_message(self,cached_parts)
|
94
99
|
change_status(:sent)
|
95
100
|
# allow other errors to bubble up
|
96
101
|
rescue MailManager::LockException => e
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
<%= form_tag mail_manager.bounces_path, :id => 'search_form', :method => 'GET' do %>
|
5
5
|
<label for="mailing_id">Mailing:</label><%= select_tag "mailing_id", options_for_select(@mailings.collect{|mailing| ["#{mailing.subject} (#{l mailing.status_changed_at if mailing.status_changed_at.present?}) (#{mailing.bounces.size})",mailing.id.to_s]},params[:mailing_id].to_i), :include_blank => true, :onChange => "$('#search_form').submit()" %><br />
|
6
|
-
<label for="bounce_status">Status:</label><%= select_tag "bounce[status]", options_for_select([['Needs Attention','needs_manual_intervention'],['Resolved','resolved']],params[:bounce][:status]), :include_blank => true, :onChange => "$('#search_form').submit()" %><br />
|
6
|
+
<label for="bounce_status">Status:</label><%= select_tag "bounce[status]", options_for_select([['Needs Attention','needs_manual_intervention'],['Dismissed','dismissed'],['Removed','removed'],['Unprocessed','unprocessed'],['Invalid','invalid'],['Resolved','resolved']],params[:bounce][:status]), :include_blank => true, :onChange => "$('#search_form').submit()" %><br />
|
7
7
|
<% end %>
|
8
8
|
<% if @bounces.length == 0 %>
|
9
9
|
<h3>No bounces found for the Mailing with given status.</h3>
|
data/lib/mail_manager/engine.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module MailManager
|
2
2
|
# set up accessors for configuration options from config/mail_manager.yml
|
3
|
+
# deliveries_per_run: how many emails to send per 'run' of a mailing job (it kicks off a new job after this number if more exist.. used to keep run time down)
|
4
|
+
mattr_accessor :deliveries_per_run
|
3
5
|
# table_prefix: prefix for database table names to avoid collisions within another app
|
4
6
|
mattr_accessor :table_prefix
|
5
7
|
# secret: a secret for encrypting tokens and guids
|
@@ -163,6 +165,7 @@ module MailManager
|
|
163
165
|
MailManager.table_prefix ||= 'mail_manager_'
|
164
166
|
end
|
165
167
|
MailManager.default_from_email_address ||= conf.default_from_email_address rescue nil
|
168
|
+
MailManager.deliveries_per_run ||= (conf.deliveries_per_run || 50) rescue 50
|
166
169
|
MailManager.signup_email_address ||= conf.signup_email_address rescue nil
|
167
170
|
MailManager.bounce ||= conf.bounce || {} rescue {}
|
168
171
|
MailManager.unsubscribe_path ||= conf.unsubscribe_path || "/listmgr" rescue "/listmgr"
|
data/lib/mail_manager/version.rb
CHANGED
data/lib/tasks/mail_manager.rake
CHANGED
@@ -51,6 +51,7 @@ namespace :mail_manager do
|
|
51
51
|
# roles_method: the method that your "current_user" object defines its role names(returns a list of strings)
|
52
52
|
# unsubscribe_path: public url for unsubscribing ... this is a prefix and is followed by a message 'guid', defaults to '/listmgr' and routes as '/listmgr/:guid'
|
53
53
|
# dont_include_images_domains: a list of domains that won't include images in the email, whether or not the mailing is set to include them
|
54
|
+
# deliveries_per_run: how many messages do deliver for a mailing job 'per run' this keeps the job limited to a short run allowing other jobs to run as well for larger lists and for the job to possibly be more graceful on a delayed job stoppage.
|
54
55
|
# sleep_time_between_messages: a timeout between messages to slow the output of emails to your email server; you should probably limit with your mail server itself if possible
|
55
56
|
# path_prefix: a prefix to the mail manager routes(defaults to /admin)
|
56
57
|
# table_prefix: prefixes all mail manager tables with a string to avoid collisions with your app - should be set BEFORE running migrations
|
data/mail_manager.gemspec
CHANGED
@@ -12,13 +12,6 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.description = %q{Manages the delivery of mailable items. Handles contacts, mailing lists, bounces, unsubscribe, opt-in, etc. Also available with a newsletter manager (including newsletter designs and elements management, wysiwyg newsletter editor, and newsletter archive) as well as user access control as part of the iReach gem.}
|
13
13
|
gem.summary = %q{Mailing list management tool}
|
14
14
|
gem.homepage = "http://ireachnews.com"
|
15
|
-
gem.post_install_message = <<-EOT
|
16
|
-
#** Mail Manager 3.2.6 messages **********************
|
17
|
-
#** Required Actions for every upgrade **
|
18
|
-
rake mail_manager:upgrade # this adds any new migrations and migrates your DB ...
|
19
|
-
#** NOTE! you should try this in development before pushing to your production site
|
20
|
-
#*END Mail Manager messages ********************
|
21
|
-
EOT
|
22
15
|
|
23
16
|
gem.add_dependency "rails", "~>3.2"
|
24
17
|
gem.add_dependency 'jquery-rails', "~>3.1"
|
data/spec/test_app/.env.test
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export POST_OFFICE_SMTP_PORT=
|
2
|
-
export POST_OFFICE_POP_PORT=
|
1
|
+
export POST_OFFICE_SMTP_PORT=25005
|
2
|
+
export POST_OFFICE_POP_PORT=11005
|
@@ -20,6 +20,9 @@ RSpec.feature MailManager::Bounce do
|
|
20
20
|
@bounce1 = FactoryGirl.create(:bounce, mailing_id: @mailing1.id, status: 'needs_manual_intervention')
|
21
21
|
@bounce2 = FactoryGirl.create(:bounce, mailing_id: @mailing2.id, status: 'resolved')
|
22
22
|
@bounce3 = FactoryGirl.create(:bounce, status: 'invalid')
|
23
|
+
@bounce6 = FactoryGirl.create(:bounce, status: 'unprocessed')
|
24
|
+
@bounce4 = FactoryGirl.create(:bounce, mailing_id: @mailing1.id, status: 'removed')
|
25
|
+
@bounce5 = FactoryGirl.create(:bounce, mailing_id: @mailing1.id, status: 'dismissed')
|
23
26
|
@mailing1.reload
|
24
27
|
@mailing2.reload
|
25
28
|
end
|
@@ -27,14 +30,19 @@ RSpec.feature MailManager::Bounce do
|
|
27
30
|
visit "/mail_manager/bounces"
|
28
31
|
select "#{@mailing1.subject} (#{I18n.l @mailing1.status_changed_at}) (#{@mailing1.bounces.size})", from: "Mailing:"
|
29
32
|
expect(page).to have_css("#view_bounce_#{@bounce1.id}", count: 1)
|
30
|
-
expect(page).to
|
33
|
+
expect(page).to have_css("#view_bounce_#{@bounce4.id}", count: 1)
|
34
|
+
expect(page).to have_css("#view_bounce_#{@bounce5.id}", count: 1)
|
35
|
+
expect(page).to have_content("View",count: 3)
|
31
36
|
end
|
32
37
|
it "shows them all", js: true do
|
33
38
|
visit "/mail_manager/bounces"
|
34
39
|
expect(page).to have_css("#view_bounce_#{@bounce1.id}", count: 1)
|
35
40
|
expect(page).to have_css("#view_bounce_#{@bounce2.id}", count: 1)
|
36
41
|
expect(page).to have_css("#view_bounce_#{@bounce3.id}", count: 1)
|
37
|
-
expect(page).to
|
42
|
+
expect(page).to have_css("#view_bounce_#{@bounce4.id}", count: 1)
|
43
|
+
expect(page).to have_css("#view_bounce_#{@bounce5.id}", count: 1)
|
44
|
+
expect(page).to have_css("#view_bounce_#{@bounce6.id}", count: 1)
|
45
|
+
expect(page).to have_content("View",count: 6)
|
38
46
|
end
|
39
47
|
it "filters by 'Needs Attention' status" do
|
40
48
|
visit "/mail_manager/bounces"
|
@@ -48,9 +56,29 @@ RSpec.feature MailManager::Bounce do
|
|
48
56
|
expect(page).to have_css("#view_bounce_#{@bounce2.id}", count: 1)
|
49
57
|
expect(page).to have_content("View",count: 1)
|
50
58
|
end
|
51
|
-
it "
|
59
|
+
it "filters by 'Removed' status" do
|
60
|
+
visit "/mail_manager/bounces"
|
61
|
+
select "Removed", from: "Status:"
|
62
|
+
expect(page).to have_css("#view_bounce_#{@bounce4.id}", count: 1)
|
63
|
+
expect(page).to have_content("View",count: 1)
|
64
|
+
end
|
65
|
+
it "filters by 'Dismissed' status" do
|
66
|
+
visit "/mail_manager/bounces"
|
67
|
+
select "Dismissed", from: "Status:"
|
68
|
+
expect(page).to have_css("#view_bounce_#{@bounce5.id}", count: 1)
|
69
|
+
expect(page).to have_content("View",count: 1)
|
70
|
+
end
|
71
|
+
it "filters by 'Invalid' status" do
|
52
72
|
visit "/mail_manager/bounces"
|
53
|
-
|
73
|
+
select "Invalid", from: "Status:"
|
74
|
+
expect(page).to have_css("#view_bounce_#{@bounce3.id}", count: 1)
|
75
|
+
expect(page).to have_content("View",count: 1)
|
76
|
+
end
|
77
|
+
it "filters by 'Unprocessed' status" do
|
78
|
+
visit "/mail_manager/bounces"
|
79
|
+
select "Unprocessed", from: "Status:"
|
80
|
+
expect(page).to have_css("#view_bounce_#{@bounce6.id}", count: 1)
|
81
|
+
expect(page).to have_content("View",count: 1)
|
54
82
|
end
|
55
83
|
it "filters by 'Resolved' status and mailing" do
|
56
84
|
visit "/mail_manager/bounces"
|
@@ -49,6 +49,23 @@ RSpec.describe MailManager::MailingList do
|
|
49
49
|
}
|
50
50
|
}.sort
|
51
51
|
)
|
52
|
+
and_it "doesn't include soft deleted contacts" do
|
53
|
+
contact2.delete
|
54
|
+
expect(MailManager::MailingList.
|
55
|
+
active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids(
|
56
|
+
[list1.id, list2.id]).sort).to eq (
|
57
|
+
{
|
58
|
+
contact1.email_address => {
|
59
|
+
contact_id: contact1.id,
|
60
|
+
subscription_id: sub1.id
|
61
|
+
},
|
62
|
+
contact3.email_address => {
|
63
|
+
contact_id: contact3.id,
|
64
|
+
subscription_id: sub4.id
|
65
|
+
}
|
66
|
+
}.sort
|
67
|
+
)
|
68
|
+
end
|
52
69
|
end
|
53
70
|
end
|
54
71
|
end
|
@@ -1,5 +1,17 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
+
class MyMailable < MailManager::Mailable
|
4
|
+
cattr_accessor :mailable_parts_call_count
|
5
|
+
def initialize(*args)
|
6
|
+
@@mailable_parts_call_count = 0
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def mailable_parts
|
11
|
+
@@mailable_parts_call_count += 1
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
3
15
|
RSpec.describe MailManager::Mailing do
|
4
16
|
let(:valid_attributes) {FactoryGirl.attributes_for(:mailing)}
|
5
17
|
let(:invalid_attributes) {FactoryGirl.attributes_for(:mailing).delete(
|
@@ -15,11 +27,6 @@ RSpec.describe MailManager::Mailing do
|
|
15
27
|
mailing.change_status(:processing)
|
16
28
|
expect(mailing.can_run?).to be true
|
17
29
|
end
|
18
|
-
it "allows a processing mailing to run(for resetting a failed job)" do
|
19
|
-
mailing = MailManager::Mailing.create(valid_attributes)
|
20
|
-
mailing.change_status(:processing)
|
21
|
-
expect(mailing.can_run?).to be true
|
22
|
-
end
|
23
30
|
it "sets its initial status properly" do
|
24
31
|
attributes = valid_attributes
|
25
32
|
attributes.delete('status')
|
@@ -107,4 +114,59 @@ RSpec.describe MailManager::Mailing do
|
|
107
114
|
[contact1,contact2].map(&:email_address).sort
|
108
115
|
)
|
109
116
|
end
|
117
|
+
|
118
|
+
context "when sending a mailing" do
|
119
|
+
before(:each) do
|
120
|
+
if MailManager.register_generic_mailable
|
121
|
+
MailManager::MailableRegistry.register('MyMailable',{
|
122
|
+
:find_mailables => :all,
|
123
|
+
:name => :name,
|
124
|
+
:parts => [
|
125
|
+
['text/plain', :email_text],
|
126
|
+
['text/html', :email_html]
|
127
|
+
]
|
128
|
+
})
|
129
|
+
end
|
130
|
+
Delayed::Worker.delay_jobs = true
|
131
|
+
@list = FactoryGirl.create(:mailing_list)
|
132
|
+
@contacts = FactoryGirl.create_list(:contact,random_int(4,10))
|
133
|
+
@contacts.each{|c| c.subscribe(@list)}
|
134
|
+
@mailable = MyMailable.create(FactoryGirl.attributes_for(:mailable))
|
135
|
+
@mailing = FactoryGirl.create(:mailing, mailable: @mailable)
|
136
|
+
@mailing.mailable = @mailable
|
137
|
+
@mailing.mailing_lists << @list
|
138
|
+
@mailing.schedule
|
139
|
+
end
|
140
|
+
after(:each) do
|
141
|
+
Delayed::Worker.delay_jobs = false
|
142
|
+
MailManager::MailableRegistry.unregister('MyMailable')
|
143
|
+
end
|
144
|
+
it "caches its mailable for use between messages" do
|
145
|
+
MyMailable.mailable_parts_call_count = 0
|
146
|
+
@mailing.deliver
|
147
|
+
expect(MyMailable.mailable_parts_call_count).to eq 1
|
148
|
+
end
|
149
|
+
|
150
|
+
it "sends a specified number of messages per job" do
|
151
|
+
expect(Delayed::Job.count).to eq 1
|
152
|
+
expect(MailManager.deliveries_per_run).to be > 0
|
153
|
+
MailManager.deliveries_per_run = 2
|
154
|
+
ActionMailer::Base.deliveries.clear
|
155
|
+
@mailing.deliver
|
156
|
+
expect(@mailing.status.to_s).to eq 'processing'
|
157
|
+
expect(Delayed::Job.count).to eq 2
|
158
|
+
expect(ActionMailer::Base.deliveries.count).to eq 2
|
159
|
+
expect(@mailing.messages.pending.count).to eq (@contacts.count - 2)
|
160
|
+
end
|
161
|
+
it 'finishes the mailing' do
|
162
|
+
MailManager.deliveries_per_run = 2
|
163
|
+
ActionMailer::Base.deliveries.clear
|
164
|
+
while ['scheduled','processing'].include?(@mailing.status) do
|
165
|
+
@mailing.deliver
|
166
|
+
end
|
167
|
+
expect(Delayed::Job.count).to eq (@contacts.count/2.0).ceil
|
168
|
+
expect(@mailing.status.to_s).to eq 'completed'
|
169
|
+
expect(ActionMailer::Base.deliveries.count).to eq @contacts.count
|
170
|
+
end
|
171
|
+
end
|
110
172
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lone Star Internet
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -506,12 +506,7 @@ homepage: http://ireachnews.com
|
|
506
506
|
licenses:
|
507
507
|
- MIT
|
508
508
|
metadata: {}
|
509
|
-
post_install_message:
|
510
|
-
#** Mail Manager 3.2.6 messages **********************
|
511
|
-
#** Required Actions for every upgrade **
|
512
|
-
rake mail_manager:upgrade # this adds any new migrations and migrates your DB ...
|
513
|
-
#** NOTE! you should try this in development before pushing to your production site
|
514
|
-
#*END Mail Manager messages ********************
|
509
|
+
post_install_message:
|
515
510
|
rdoc_options: []
|
516
511
|
require_paths:
|
517
512
|
- lib
|