mail_manager 3.2.5 → 3.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/app/controllers/mail_manager/bounces_controller.rb +13 -1
  4. data/app/controllers/mail_manager/contacts_controller.rb +1 -2
  5. data/app/controllers/mail_manager/mailings_controller.rb +2 -4
  6. data/app/controllers/mail_manager/subscriptions_controller.rb +0 -2
  7. data/app/models/mail_manager/bounce.rb +9 -7
  8. data/app/models/mail_manager/contactable_registry.rb +2 -1
  9. data/app/models/mail_manager/mailable.rb +11 -9
  10. data/app/models/mail_manager/mailer.rb +13 -5
  11. data/app/models/mail_manager/mailing.rb +13 -25
  12. data/app/models/mail_manager/mailing_list.rb +17 -0
  13. data/app/models/mail_manager/message.rb +12 -1
  14. data/app/models/mail_manager/subscription.rb +12 -0
  15. data/app/views/mail_manager/bounces/_email_parts.html.erb +3 -1
  16. data/app/views/mail_manager/bounces/index.html.erb +1 -1
  17. data/app/views/mail_manager/bounces/show.html.erb +2 -2
  18. data/app/views/mail_manager/contacts/_form.html.erb +1 -1
  19. data/app/views/mail_manager/mailings/index.html.erb +3 -3
  20. data/app/views/mail_manager/messages/index.html.erb +1 -1
  21. data/app/views/mail_manager/subscriptions/_subscriptions.html.erb +6 -3
  22. data/config/routes.rb +2 -2
  23. data/lib/delayed/status.rb +5 -2
  24. data/lib/delayed/status_job.rb +5 -21
  25. data/lib/delayed_overrides/job.rb +6 -0
  26. data/lib/mail_manager/engine.rb +23 -1
  27. data/lib/mail_manager/version.rb +1 -1
  28. data/mail_manager.gemspec +10 -3
  29. data/spec/test_app/Procfile +5 -3
  30. data/spec/test_app/config/mail_manager.yml +3 -0
  31. data/spec/test_app/features/contact_management.feature +7 -0
  32. data/spec/test_app/features/message_management.feature +8 -1
  33. data/spec/test_app/features/step_definitions/webrat_steps.rb +6 -2
  34. data/spec/test_app/lib/debugging.rb +2 -2
  35. data/spec/test_app/script/full_suite +7 -5
  36. data/spec/test_app/spec/controllers/mail_manager/bounces_controller_spec.rb +39 -0
  37. data/spec/test_app/spec/controllers/mail_manager/mailings_controller_spec.rb +12 -0
  38. data/spec/test_app/spec/models/mail_manager/bounce_spec.rb +31 -0
  39. data/spec/test_app/spec/models/mail_manager/engine_spec.rb +25 -0
  40. data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +39 -0
  41. data/spec/test_app/spec/models/mail_manager/mailing_spec.rb +43 -1
  42. data/spec/test_app/spec/models/mail_manager/message_spec.rb +19 -0
  43. data/spec/test_app/spec/models/mail_manager/subscription_spec.rb +17 -0
  44. data/spec/test_app/spec/support/files/bounce-400.txt +73 -0
  45. data/spec/test_app/spec/support/files/bounce-500.txt +75 -0
  46. data/spec/test_app/spec/support/files/bounce-invalid-address.txt +73 -0
  47. data/spec/test_app/spec/support/files/bounce-invalid.txt +113 -0
  48. data/spec/test_app/spec/support/files/bounce-invalid2.txt +29 -0
  49. data/spec/test_app/spec/support/files/bounce-invalid3.txt +29 -0
  50. data/spec/test_app/spec/support/files/bounce-mail-box-full.txt +1178 -0
  51. data/spec/test_app/spec/support/files/bounce-over-quota.txt +1173 -0
  52. data/spec/test_app/spec/support/files/bounce-smtp-timeout.txt +73 -0
  53. data/spec/test_app/spec/support/files/bounce-unknown_domain.txt +73 -0
  54. data/spec/test_app/spec/support/files/mail_manager_empty_table_prefix.yml +85 -0
  55. data/spec/test_app/spec/support/files/mail_manager_use_generic_mailables.yml +86 -0
  56. metadata +36 -3
@@ -1,23 +1,7 @@
1
- # module Delayed
2
- # class StatusJob < RepeatingJob
3
- # def perform
4
- # true
5
- # end
6
-
7
- # def repeats_every
8
- # 1.minutes
9
- # end
10
-
11
- # # This is a good hook if you need to report job processing errors in additional or different ways
12
- # def log_exception(error)
13
- # #don't send mail for this currently.. we'll do something smart laters
14
- # #Delayed::Mailer.deliver_exception_notification(self,error,notify_email) unless notify_email.blank?
15
- # logger.error "* [JOB] #{name}(#{id}) failed with #{error.class.name}: #{error.message} - #{attempts} failed attempts"
16
- # end
17
- # end
18
- # end
19
- class ::Delayed::StatusJob < ::Delayed::Job
20
- def perform
21
- ::Delayed::StatusJob.enqueue ::Delayed::StatusJob.new, run_at: 1.minute.from_now
1
+ module Delayed
2
+ class StatusJob < Struct.new(:next_run)
3
+ def perform
4
+ Job.enqueue StatusJob.new, run_at: (next_run || 1.minute.from_now)
5
+ end
22
6
  end
23
7
  end
@@ -0,0 +1,6 @@
1
+ require 'delayed_job'
2
+ if defined?(Delayed::Job)
3
+ class Delayed::Job
4
+ scope :failed, where("failed_at is not null")
5
+ end
6
+ end
@@ -48,6 +48,8 @@ module MailManager
48
48
  mattr_accessor :authorized_roles
49
49
  # roles_method: the method that your "current_user" object defines its role names(returns a list of strings)
50
50
  mattr_accessor :roles_method
51
+ # sets whether the generic mailable is registered as available
52
+ mattr_accessor :register_generic_mailable
51
53
 
52
54
  # The following 2 might be deprecated soon
53
55
  # show_title: can be used in templates/layouts to see whether you should show a title
@@ -116,7 +118,12 @@ module MailManager
116
118
  MailManager::Bounce,
117
119
  MailManager::Message
118
120
  ]
121
+ can [:send_test, :test, :schedule, :cancel], MailManager::Mailing
122
+ can [:dismiss, :fail_address], MailManager::Bounce
123
+ can [:delete, :undelete], MailManager::Contact
119
124
  end
125
+ can [:subscribe, :double_opt_in, :thank_you], MailManager::Contact
126
+ can [:unsubscribe, :unsubscribe_by_email_address], MailManager::Subscription
120
127
  EOT
121
128
  end
122
129
 
@@ -131,6 +138,15 @@ module MailManager
131
138
  File.join(PLUGIN_ROOT,'assets')
132
139
  end
133
140
 
141
+ def self.public_path?(path)
142
+ [
143
+ MailManager.subscribe_path,
144
+ MailManager.unsubscribe_path,
145
+ MailManager.double_opt_in_path,
146
+ MailManager.subscribe_thank_you_path
147
+ ].detect{|public_path| public_path =~ /#{path}/i}.present?
148
+ end
149
+
134
150
  # sets up your MailManager.blah configuration options from
135
151
  # config/mail_manager.yml and can override those with
136
152
  # config/mail_manager.local.yml for development environments
@@ -141,7 +157,11 @@ module MailManager
141
157
  MailManager.site_url ||= conf.site_url || default_site_url rescue default_site_url
142
158
  MailManager.dont_include_images_domains ||= conf.dont_include_images_domains || [] rescue []
143
159
  MailManager.sleep_time_between_messages ||= conf.sleep_time_between_messages || 0.3 rescue 0.3
144
- MailManager.table_prefix ||= conf.table_prefix || 'mail_manager_' rescue 'mail_manager_'
160
+ if conf.params.has_key?('table_prefix')
161
+ MailManager.table_prefix ||= conf.table_prefix.to_s # allow empty
162
+ else
163
+ MailManager.table_prefix ||= 'mail_manager_'
164
+ end
145
165
  MailManager.default_from_email_address ||= conf.default_from_email_address rescue nil
146
166
  MailManager.signup_email_address ||= conf.signup_email_address rescue nil
147
167
  MailManager.bounce ||= conf.bounce || {} rescue {}
@@ -158,6 +178,7 @@ module MailManager
158
178
  MailManager.requires_authentication ||= conf.requires_authentication || false rescue false
159
179
  MailManager.authorized_roles ||= conf.authorized_roles || [] rescue []
160
180
  MailManager.roles_method ||= conf.roles_method || nil rescue nil
181
+ MailManager.register_generic_mailable ||= conf.register_generic_mailable || false rescue false
161
182
  MailManager.exception_notification = {}
162
183
  MailManager.exception_notification[:to_addresses] ||= conf.exception_notification['to_addresses'] || [] rescue []
163
184
  MailManager.exception_notification[:from_address] ||= conf.exception_notification['from_address'] || nil rescue nil
@@ -178,6 +199,7 @@ MailManager::Engine.config.to_prepare do
178
199
  rescue LoadError => le
179
200
  end
180
201
  load File.join(MailManager::PLUGIN_ROOT,'lib','delayed_overrides','worker.rb')
202
+ load File.join(MailManager::PLUGIN_ROOT,'lib','delayed_overrides','job.rb')
181
203
  end
182
204
 
183
205
  require 'will_paginate'
@@ -1,3 +1,3 @@
1
1
  module MailManager
2
- VERSION = "3.2.5"
2
+ VERSION = "3.2.6"
3
3
  end
@@ -6,12 +6,19 @@ require 'mail_manager/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "mail_manager"
8
8
  gem.version = MailManager::VERSION
9
- gem.authors = ["Lone Star Internet"]
9
+ gem.authors = ["Lone Star Internet", "Christopher Hauboldt"]
10
10
  gem.email = ["biz@lone-star.net", 'chauboldt@lone-star.net']
11
11
  gem.licenses = ["MIT"]
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
15
22
 
16
23
  gem.add_dependency "rails", "~>3.2"
17
24
  gem.add_dependency 'jquery-rails', "~>3.1"
@@ -22,8 +29,8 @@ Gem::Specification.new do |gem|
22
29
  gem.add_dependency "mini_magick", "~>4.1"
23
30
  gem.add_dependency "will_paginate", "~>3.0"
24
31
  gem.add_dependency 'unix_utils', "~>0.0"
25
- gem.add_dependency "delayed_job", "~>4"
26
- gem.add_dependency 'delayed_job_active_record', "~>4"
32
+ gem.add_dependency "delayed_job", '~>4'
33
+ gem.add_dependency 'delayed_job_active_record', '~>4'
27
34
  gem.add_dependency "dynamic_form", "~>1.1"
28
35
  gem.add_dependency 'cancancan', "~>1.9"
29
36
 
@@ -1,3 +1,5 @@
1
- post_office: bundle exec script/post_office run
2
- delayed_job: bundle exec script/delayed_job run
3
- web: spring rails s WEBrick
1
+ post_office: bundle exec script/post_office run
2
+ post_office_test: RAILS_ENV=test bundle exec script/post_office run
3
+ with_lock: script/with_lock run
4
+ delayed_job: bundle exec script/delayed_job run
5
+ web: spring rails s WEBrick
@@ -64,6 +64,7 @@ common:
64
64
  sleep_time_between_messages: 0.3
65
65
  path_prefix: /admin
66
66
  table_prefix: mail_manager_
67
+ register_generic_mailable: false
67
68
  default_from_email_address: chrisboy <chrisboy@lvh.me>
68
69
  secret: 7a3906324erwr6254e85e4bdb80592001a
69
70
  bounce:
@@ -79,7 +80,9 @@ development:
79
80
  site_url: http://example.dev
80
81
  secret: !binary |-
81
82
  ZDgxNDViNzJhOWExMDI1NmU1OTkwZDEzYTgyODcy
83
+ register_generic_mailable: true
82
84
  test:
83
85
  site_url: http://mail-manager.lvh.me:4460
84
86
  secret: !binary |-
85
87
  ZjU0MDU2YWU4M2Q0MjU4MTM2ZWIwYzM2ZTNjMDRj
88
+ register_generic_mailable: true
@@ -74,6 +74,13 @@ Feature: Manage Contacts
74
74
  And I press "Submit"
75
75
  Then contact "Bobo Clown" should exist with email_address "bobo@example.com"
76
76
  And contact "Bobo Clown" should be subscribed to "Peeps" with the "active" status
77
+ When I follow "Edit"
78
+ And I check "Others"
79
+ And I uncheck "Peeps"
80
+ And I press "Submit"
81
+ Then contact "Bobo Clown" should exist with email_address "bobo@example.com"
82
+ And contact "Bobo Clown" should be subscribed to "Others" with the "active" status
83
+ And contact "Bobo Clown" should be subscribed to "Peeps" with the "admin_unsubscribed" status
77
84
 
78
85
  Scenario: Many contacts existing will show pagination
79
86
  Given 50 contacts exist
@@ -17,6 +17,13 @@ Feature: view messages for mailings
17
17
  Scenario:
18
18
  When I go to the mailings page
19
19
  And I follow "Messages"
20
- And I select "Any Status" from "Status"
20
+ Then I should see "bobo@example.com"
21
+ When I select "Pending" from "Status"
22
+ Then I should not see "bobo@example.com"
23
+ When I select "Sent" from "Status"
24
+ Then I should see "bobo@example.com"
25
+ When I select "Failed" from "Status"
26
+ Then I should not see "bobo@example.com"
27
+ When I select "Any Status" from "Status"
21
28
  Then I should see "bobo@example.com"
22
29
 
@@ -95,11 +95,15 @@ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
95
95
  end
96
96
 
97
97
  Then /^I should see "([^\"]*)"$/ do |text|
98
- expect(page.body).to have_content(text)
98
+ Debugging::wait_until_success(5) do
99
+ expect(page.body).to have_content(text)
100
+ end
99
101
  end
100
102
 
101
103
  Then /^I should not see "([^\"]*)"$/ do |text|
102
- expect(page.body).not_to have_content(text)
104
+ Debugging::wait_until_success(5) do
105
+ expect(page.body).not_to have_content(text)
106
+ end
103
107
  end
104
108
 
105
109
  Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
@@ -11,7 +11,7 @@ module ::Debugging
11
11
  end
12
12
  rescue Exception, StandardError, RuntimeError => te
13
13
  Rails.logger.warn "Uncaught/Unpried exception: #{te.message} #{te.backtrace.join("\n")}"
14
- raise e
14
+ raise te
15
15
  end
16
16
  end
17
17
  end
@@ -52,7 +52,7 @@ module ::Debugging
52
52
  Rails.logger.warn "Waiting for something.. trying: #{Kernel.caller[0..5].join("\n")}" if log
53
53
  yield
54
54
  true
55
- rescue => e
55
+ rescue Exception, StandardError, RuntimeError => e
56
56
  Rails.logger.warn "Waiting for something.. failure: #{e.message} #{e.backtrace.join}"
57
57
  false
58
58
  end
@@ -13,14 +13,14 @@ export CUC_SQLITE_SUCCESS=0
13
13
  DBADAPTER=sqlite bundle exec rspec spec && export SQLITE_SUCCESS=1
14
14
  DBADAPTER=sqlite bundle exec cucumber features && export CUC_SQLITE_SUCCESS=1
15
15
 
16
- if [ $POSTGRES -eq 1 ]; then
16
+ if [ "$POSTGRES" = "1" ]; then
17
17
  #RUN FOR Postgresql
18
18
  cp config/database.postgres.local.yml config/database.yml
19
19
 
20
20
  bundle exec rake db:schema:load
21
21
 
22
22
  export PGSQL_SUCCESS=0
23
- export CUCPGSQL_SUCCESS=0
23
+ export CUC_PGSQL_SUCCESS=0
24
24
 
25
25
  DBADAPTER=pg bundle exec rspec spec && export PGSQL_SUCCESS=1
26
26
  DBADAPTER=pg bundle exec cucumber features && export CUC_PGSQL_SUCCESS=1
@@ -32,7 +32,7 @@ cp config/database.mysql.local.yml config/database.yml
32
32
  bundle exec rake db:schema:load
33
33
 
34
34
  export MYSQL_SUCCESS=0
35
- export CUCMYSQL_SUCCESS=0
35
+ export CUC_MYSQL_SUCCESS=0
36
36
 
37
37
  DBADAPTER=mysql bundle exec rspec spec && export MYSQL_SUCCESS=1
38
38
  DBADAPTER=mysql bundle exec cucumber features && export CUC_MYSQL_SUCCESS=1
@@ -43,8 +43,10 @@ DBADAPTER=mysql bundle exec cucumber features && export CUC_MYSQL_SUCCESS=1
43
43
  unset RAILS_ENV
44
44
 
45
45
  if [ $MYSQL_SUCCESS -eq 0 ] ; then echo "Rspec Mysql Failed" && exit 1; fi
46
- if [ $PGSQL_SUCCESS -eq 0 ] ; then echo "Rspec Pgsql Failed" && exit 1; fi
47
46
  if [ $SQLITE_SUCCESS -eq 0 ] ; then echo "Rspec SQLite Failed" && exit 1; fi
48
47
  if [ $CUC_MYSQL_SUCCESS -eq 0 ] ; then echo "Cucumber Mysql Failed" && exit 1; fi
49
- if [ $CUC_PGSQL_SUCCESS -eq 0 ] ; then echo "Cucumber Pgsql Failed" && exit 1; fi
50
48
  if [ $CUC_SQLITE_SUCCESS -eq 0 ] ; then echo "Cucumber SQLite Failed" && exit 1; fi
49
+ if [ "$POSTGRES" = "1" ] ; then
50
+ if [ $PGSQL_SUCCESS -eq 0 ] ; then echo "Rspec Pgsql Failed" && exit 1; fi
51
+ if [ $CUC_PGSQL_SUCCESS -eq 0 ] ; then echo "Cucumber Pgsql Failed" && exit 1; fi
52
+ fi
@@ -45,6 +45,15 @@ RSpec.describe MailManager::BouncesController, :type => :controller do
45
45
  expect(assigns(:bounces)).to eq([bounce])
46
46
  expect(response.body).to match /Listing Bounces/
47
47
  end
48
+ it "orders bounces create date desc" do
49
+ Timecop.travel 2.hours.ago
50
+ bounce = MailManager::Bounce.create! valid_attributes
51
+ Timecop.return
52
+ bounce_new = MailManager::Bounce.create! valid_attributes
53
+ get :index, {}, valid_session
54
+ expect(assigns(:bounces)).to eq([bounce_new,bounce])
55
+ expect(response.body).to match /Listing Bounces/
56
+ end
48
57
  end
49
58
 
50
59
  describe "GET #show" do
@@ -56,4 +65,34 @@ RSpec.describe MailManager::BouncesController, :type => :controller do
56
65
  end
57
66
  end
58
67
 
68
+ describe "PUT #dismiss" do
69
+ it "dismisses a bounce from needing attention" do
70
+ bounce = FactoryGirl.create(:bounce, status: 'needs_manual_intervention')
71
+ put :dismiss, {id: bounce.id}, valid_session
72
+ expect(assigns(:bounce)).to eq(bounce)
73
+ bounce.reload
74
+ expect(bounce.status).to eq 'dismissed'
75
+ end
76
+ end
77
+
78
+ describe "PUT #dismiss" do
79
+ it "fails a bounce setting it to 'removed' and failing its email addresses from active subscriptions" do
80
+ contact = FactoryGirl.create(:contact)
81
+ list1 = FactoryGirl.create(:mailing_list)
82
+ list2 = FactoryGirl.create(:mailing_list)
83
+ sub1 = contact.subscribe(list1)
84
+ message = FactoryGirl.create(:message, contact_id: contact.id)
85
+ bounce = FactoryGirl.create(:bounce, status: 'needs_manual_intervention',
86
+ message_id: message.id
87
+ )
88
+ put :fail_address, {id: bounce.id}, valid_session
89
+ expect(assigns(:bounce)).to eq(bounce)
90
+ bounce.reload
91
+ sub1.reload
92
+ expect(bounce.message.status).to eq('failed')
93
+ expect(sub1.status).to eq('failed_address')
94
+ expect(MailManager::Subscription.count).to eq 1
95
+ expect(bounce.status).to eq 'removed'
96
+ end
97
+ end
59
98
  end
@@ -81,6 +81,18 @@ RSpec.describe MailManager::MailingsController, :type => :controller do
81
81
  expect(assigns(:mailing)).to be_a_new(MailManager::Mailing)
82
82
  expect(response.body).to have_content("New Mailing")
83
83
  end
84
+ it "assigns mailables in created_at desc order" do
85
+ Timecop.travel 2.hours.ago
86
+ mailable = FactoryGirl.create(:mailable)
87
+ Timecop.return
88
+ mailable_new = FactoryGirl.create(:mailable)
89
+ get :new, {}, valid_session
90
+ expect(assigns(:mailing)).to be_a_new(MailManager::Mailing)
91
+ expect(assigns(:mailables_for_select)).to eq([mailable_new,mailable].map{|m|
92
+ [m.name, "#{m.class.name}_#{m.id}"]
93
+ })
94
+ expect(response.body).to have_content("New Mailing")
95
+ end
84
96
  end
85
97
 
86
98
  describe "GET #edit" do
@@ -30,6 +30,37 @@ RSpec.describe MailManager::Bounce do
30
30
  )
31
31
  Delayed::Worker.delay_jobs = false
32
32
  end
33
+
34
+ it "deferred's 400's" do
35
+ bounce = MailManager::Bounce.create(
36
+ bounce_message: File.read('spec/support/files/bounce-400.txt')
37
+ )
38
+ bounce.process
39
+ expect(bounce.status).to eq 'deferred'
40
+ end
41
+
42
+ it "removed's 500's and 'failed_address's associated active subscriptions" do
43
+ contact = FactoryGirl.create(:contact)
44
+ mailing_list = FactoryGirl.create(:mailing_list)
45
+ mailing_list2 = FactoryGirl.create(:mailing_list)
46
+ sub1=contact.subscribe(mailing_list)
47
+ mailing = FactoryGirl.create(:mailing)
48
+ message = FactoryGirl.create(:message,
49
+ mailing_id: mailing.id,
50
+ contact_id: contact.id
51
+ )
52
+ bounce_guid = '30-28-11376-fa351cf35e4012d37d8c13df8735fd13edfed563'
53
+
54
+ bounce = MailManager::Bounce.create(
55
+ bounce_message: File.read('spec/support/files/bounce-500.txt').gsub(
56
+ /#{bounce_guid}/,message.guid)
57
+ )
58
+ bounce.process
59
+ sub1.reload
60
+ expect(bounce.status).to eq 'removed'
61
+ expect(sub1.status).to eq 'failed_address'
62
+ expect(MailManager::Subscription.count).to eq 1
63
+ end
33
64
  end
34
65
  def send_bounce(filename)
35
66
  mail = Mail.new(File.read(File.join(Rails.root,'spec','support','files',filename)))
@@ -76,4 +76,29 @@ RSpec.describe MailManager::Engine do
76
76
  end
77
77
  end
78
78
  end
79
+ it "can set table prefix to empty" do
80
+ prefix = MailManager.table_prefix
81
+ MailManager.table_prefix = nil
82
+ conf = MailManager::Config.new(
83
+ 'spec/support/files/mail_manager_empty_table_prefix.yml')
84
+ MailManager.initialize_with_config(conf)
85
+ expect(MailManager.table_prefix).to eq ''
86
+ MailManager.table_prefix = prefix
87
+ end
88
+ context "with respect to the mailables object" do
89
+ it "can turn on its registration" do
90
+ MailManager.register_generic_mailable = nil
91
+ conf = MailManager::Config.new(
92
+ 'spec/support/files/mail_manager_use_generic_mailables.yml')
93
+ MailManager.initialize_with_config(conf)
94
+ expect(MailManager.register_generic_mailable).to be true
95
+ end
96
+ it "can turn off its registration(default behaviour in mail_manager.yml)" do
97
+ MailManager.register_generic_mailable = nil
98
+ conf = MailManager::Config.new('config/mail_manager.yml')
99
+ MailManager.initialize_with_config(conf)
100
+ expect(MailManager.register_generic_mailable).to be false
101
+ MailManager.register_generic_mailable = true
102
+ end
103
+ end
79
104
  end
@@ -12,4 +12,43 @@ RSpec.describe MailManager::MailingList do
12
12
  expect(@mailing_list.valid?).to eq false
13
13
  end
14
14
  end
15
+ describe "self::active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids" do
16
+ it "returns all active email addresses, contact_ids, subscription_ids for given mailing list ids" do
17
+ contact1 = FactoryGirl.create(:contact)
18
+ contact2 = FactoryGirl.create(:contact)
19
+ contact3 = FactoryGirl.create(:contact)
20
+ contact4 = FactoryGirl.create(:contact)
21
+ list1 = FactoryGirl.create(:mailing_list)
22
+ sub1 = contact1.subscribe(list1)
23
+ sub2 = contact2.subscribe(list1)
24
+ list2 = FactoryGirl.create(:mailing_list)
25
+ sub3 = contact2.subscribe(list2)
26
+ sub4 = contact3.subscribe(list2)
27
+ list3 = FactoryGirl.create(:mailing_list)
28
+ sub5 = contact3.subscribe(list3)
29
+ sub6 = contact4.subscribe(list3)
30
+ expect(MailManager::MailingList.
31
+ active_email_addresses_contact_ids_subscription_ids_for_mailing_list_ids(
32
+ [list1.id, list2.id]).sort).to eq (
33
+ {
34
+ contact1.email_address => {
35
+ contact_id: contact1.id,
36
+ subscription_id: sub1.id
37
+ },
38
+ contact2.email_address => {
39
+ contact_id: contact2.id,
40
+ subscription_id: sub2.id
41
+ },
42
+ contact2.email_address => {
43
+ contact_id: contact2.id,
44
+ subscription_id: sub3.id
45
+ },
46
+ contact3.email_address => {
47
+ contact_id: contact3.id,
48
+ subscription_id: sub4.id
49
+ }
50
+ }.sort
51
+ )
52
+ end
53
+ end
15
54
  end