mail_manager 3.0.0 → 3.2.0
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 +5 -13
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +27 -10
- data/LICENSE.txt +2 -2
- data/MIT-LICENSE +1 -1
- data/README.md +97 -15
- data/{features/bounce_management.feature → app/assets/images/mail_manager/.gitkeep} +0 -0
- data/app/assets/images/mail_manager/BottomRight.gif +0 -0
- data/app/assets/images/mail_manager/MidRight.gif +0 -0
- data/app/assets/images/mail_manager/TopCenter.gif +0 -0
- data/app/assets/images/mail_manager/TopRight.gif +0 -0
- data/app/assets/images/mail_manager/calendar_date_select/calendar.gif +0 -0
- data/app/assets/images/mail_manager/iReach_logo.gif +0 -0
- data/app/assets/images/mail_manager/spacer.gif +0 -0
- data/app/assets/images/mail_manager/topMid.gif +0 -0
- data/app/assets/javascripts/mail_manager/application.js +19 -1
- data/app/assets/javascripts/mail_manager/jquery-ui-timepicker-addon.js +2134 -0
- data/app/assets/stylesheets/mail_manager/admin.css +261 -0
- data/app/assets/stylesheets/mail_manager/application.css +3 -1
- data/app/assets/stylesheets/mail_manager/nav.css +68 -0
- data/app/assets/stylesheets/mail_manager/timepicker.css +11 -0
- data/app/controllers/mail_manager/application_controller.rb +7 -2
- data/app/controllers/mail_manager/bounces_controller.rb +5 -10
- data/app/controllers/mail_manager/contacts_controller.rb +42 -20
- data/app/controllers/mail_manager/mailing_lists_controller.rb +5 -12
- data/app/controllers/mail_manager/mailings_controller.rb +18 -18
- data/app/controllers/mail_manager/messages_controller.rb +3 -10
- data/app/controllers/mail_manager/subscriptions_controller.rb +16 -75
- data/app/helpers/mail_manager/layout_helper.rb +43 -0
- data/app/models/mail_manager/bounce.rb +16 -5
- data/app/models/mail_manager/contact.rb +64 -1
- data/app/models/mail_manager/mailable.rb +14 -0
- data/app/models/mail_manager/mailer.rb +48 -81
- data/app/models/mail_manager/mailing.rb +23 -42
- data/app/models/mail_manager/message.rb +52 -8
- data/app/models/mail_manager/subscription.rb +9 -3
- data/app/models/status_history.rb +3 -2
- data/app/views/layouts/mail_manager/application.html.erb +33 -5
- data/app/views/layouts/mail_manager/layout.html.erb +15 -0
- data/app/views/mail_manager/bounces/index.html.erb +6 -4
- data/app/views/mail_manager/bounces/show.html.erb +3 -3
- data/app/views/mail_manager/contacts/_form.html.erb +7 -23
- data/app/views/mail_manager/contacts/edit.html.erb +3 -3
- data/app/views/mail_manager/contacts/index.html.erb +14 -28
- data/app/views/mail_manager/contacts/new.html.erb +2 -2
- data/app/views/mail_manager/contacts/show.html.erb +5 -5
- data/app/views/mail_manager/contacts/subscribe.html.erb +1 -1
- data/app/views/mail_manager/mailer/double_opt_in.erb +1 -1
- data/app/views/mail_manager/mailer/double_opt_in.html.erb +6 -0
- data/app/views/mail_manager/mailer/unsubscribed.erb +1 -1
- data/app/views/mail_manager/mailer/unsubscribed.html.erb +1 -1
- data/app/views/mail_manager/mailing_lists/_form.html.erb +8 -17
- data/app/views/mail_manager/mailing_lists/edit.html.erb +4 -4
- data/app/views/mail_manager/mailing_lists/index.html.erb +6 -5
- data/app/views/mail_manager/mailing_lists/new.html.erb +3 -3
- data/app/views/mail_manager/mailings/_form.html.erb +22 -44
- data/app/views/mail_manager/mailings/edit.html.erb +3 -3
- data/app/views/mail_manager/mailings/index.html.erb +23 -27
- data/app/views/mail_manager/mailings/new.html.erb +2 -2
- data/app/views/mail_manager/mailings/test.html.erb +3 -3
- data/app/views/mail_manager/messages/index.html.erb +2 -2
- data/app/views/mail_manager/subscriptions/_form.html.erb +1 -1
- data/app/views/mail_manager/subscriptions/_subscriptions.html.erb +2 -2
- data/app/views/mail_manager/subscriptions/edit.html.erb +2 -2
- data/app/views/mail_manager/subscriptions/index.html.erb +3 -3
- data/app/views/mail_manager/subscriptions/new.html.erb +1 -1
- data/app/views/mail_manager/subscriptions/unsubscribe.html.erb +1 -1
- data/app/views/mail_manager/subscriptions/unsubscribe_by_email_address.html.erb +3 -3
- data/config/locales/en.yml +13 -0
- data/config/locales/mailings.en.yml +52 -0
- data/config/routes.rb +21 -19
- data/db/migrate/008_add_bounces_count_to_mailings.rb +14 -0
- data/db/migrate/009_add_messages_count_to_mailings.rb +14 -0
- data/db/migrate/010_add_login_token_to_contact.rb +11 -0
- data/db/migrate/011_add_deleted_at_to_mailing.rb +11 -0
- data/lib/delayed/mailer.rb +9 -5
- data/lib/delayed/status.rb +6 -2
- data/lib/delayed_overrides/worker.rb +21 -0
- data/lib/deleteable.rb +13 -14
- data/lib/mail_manager/config.rb +3 -3
- data/lib/mail_manager/engine.rb +136 -7
- data/lib/mail_manager/lock.rb +1 -0
- data/lib/mail_manager/version.rb +1 -1
- data/lib/tasks/mail_manager.rake +92 -56
- data/mail_manager.gemspec +4 -0
- data/spec/rails_helper.rb +50 -0
- data/spec/spec_helper.rb +87 -48
- data/spec/test_app/.env.development +3 -0
- data/spec/test_app/.env.test +2 -0
- data/spec/test_app/.rspec +1 -0
- data/spec/test_app/Procfile +3 -0
- data/spec/test_app/app/controllers/application_controller.rb +4 -0
- data/spec/test_app/app/models/ability.rb +7 -0
- data/spec/test_app/app/models/user.rb +8 -2
- data/spec/test_app/app/models/user_with_role.rb +22 -0
- data/spec/test_app/config/database.postgres.yml +21 -0
- data/spec/test_app/config/database.sqlite.yml +2 -2
- data/spec/test_app/config/environment.rb +2 -2
- data/spec/test_app/config/environments/test.rb +13 -0
- data/spec/test_app/config/mail_manager.yml +66 -2
- data/spec/test_app/config/routes.rb +0 -1
- data/spec/test_app/db/migrate/20150420163235_add_bounces_count_to_mailings.rb +14 -0
- data/spec/test_app/db/migrate/20150420163804_add_messages_count_to_mailings.rb +14 -0
- data/spec/test_app/db/migrate/20150421151457_add_login_token_to_contact.rb +11 -0
- data/spec/test_app/db/migrate/20150423143754_add_deleted_at_to_mailing.rb +11 -0
- data/spec/test_app/db/schema.rb +10 -5
- data/spec/test_app/db/structure.sql +150 -15
- data/spec/test_app/features/bounce_management.feature +11 -0
- data/spec/test_app/features/contact_management.feature +91 -0
- data/{features → spec/test_app/features}/mailable.feature +3 -1
- data/spec/test_app/features/mailing_list_management.feature +39 -0
- data/spec/test_app/features/mailing_management.feature +60 -0
- data/{features → spec/test_app/features}/message.feature +4 -4
- data/spec/test_app/features/message_management.feature +22 -0
- data/spec/test_app/features/step_definitions/bounce_steps.rb +4 -0
- data/spec/test_app/features/step_definitions/contact_steps.rb +63 -0
- data/spec/test_app/features/step_definitions/debugging_steps.rb +3 -0
- data/spec/test_app/features/step_definitions/email_steps.rb +6 -0
- data/spec/test_app/features/step_definitions/job_steps.rb +25 -0
- data/spec/test_app/features/step_definitions/login_steps.rb +4 -0
- data/spec/test_app/features/step_definitions/mailing_list.rb +17 -0
- data/spec/test_app/features/step_definitions/mailing_steps.rb +51 -0
- data/spec/test_app/features/step_definitions/subscription_steps.rb +26 -0
- data/{features → spec/test_app/features}/step_definitions/webrat_steps.rb +10 -6
- data/spec/test_app/features/subscription_management.feature +62 -0
- data/spec/test_app/features/support/env.rb +37 -0
- data/spec/test_app/features/support/paths.rb +36 -0
- data/spec/test_app/lib/debugging.rb +61 -0
- data/spec/test_app/lib/post_office_manager.rb +71 -0
- data/spec/test_app/public/subscribe.html +40 -0
- data/spec/test_app/script/full_suite +50 -0
- data/spec/test_app/script/post_office +25 -0
- data/spec/test_app/script/rails +20 -0
- data/spec/test_app/script/rspec_multi_db +34 -0
- data/spec/test_app/spec/controllers/mail_manager/bounces_controller_spec.rb +59 -0
- data/spec/test_app/spec/controllers/mail_manager/contacts_controller_spec.rb +178 -0
- data/spec/test_app/spec/controllers/mail_manager/mailing_lists_controller_spec.rb +164 -0
- data/spec/test_app/spec/controllers/mail_manager/mailings_controller_spec.rb +184 -0
- data/spec/test_app/spec/controllers/users_controller_spec.rb +47 -46
- data/spec/test_app/spec/factories/_functions.rb +27 -0
- data/spec/test_app/spec/factories/contacts.rb +7 -0
- data/spec/test_app/spec/factories/mail_manager_bounces.rb +13 -0
- data/spec/test_app/spec/factories/mailable.rb +8 -0
- data/spec/test_app/spec/factories/mailings.rb +7 -1
- data/spec/test_app/spec/factories/message.rb +7 -0
- data/spec/test_app/spec/factories/users.rb +19 -7
- data/spec/test_app/spec/features/mail_manager/bounce_spec.rb +73 -0
- data/spec/test_app/spec/features/mail_manager/double_opt_in_spec.rb +62 -0
- data/spec/test_app/spec/features/mail_manager/mailing_spec.rb +46 -0
- data/spec/test_app/spec/features/navigation_spec.rb +9 -0
- data/spec/test_app/spec/helpers/mail_manager/layout_helper_spec.rb +41 -0
- data/spec/test_app/spec/helpers/mail_manager/subscriptions_helper_spec.rb +14 -0
- data/spec/test_app/spec/models/delayed/mailer_spec.rb +27 -0
- data/spec/test_app/spec/models/delayed/status_job_spec.rb +13 -0
- data/spec/test_app/spec/models/delayed/status_spec.rb +37 -0
- data/spec/test_app/spec/models/mail_manager/bounce_spec.rb +23 -3
- data/spec/test_app/spec/models/mail_manager/engine_spec.rb +79 -0
- data/spec/test_app/spec/models/mail_manager/mailable_spec.rb +10 -0
- data/spec/test_app/spec/models/mail_manager/mailer_spec.rb +35 -3
- data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +5 -5
- data/spec/test_app/spec/models/mail_manager/mailing_spec.rb +58 -0
- data/spec/test_app/spec/models/mail_manager/message_spec.rb +112 -0
- data/spec/test_app/spec/models/user_spec.rb +10 -8
- data/spec/test_app/spec/rails_helper.rb +86 -0
- data/spec/test_app/spec/requests/users_spec.rb +3 -3
- data/spec/test_app/spec/routing/mail_manager/bounces_routing_spec.rb +27 -0
- data/spec/test_app/spec/routing/mail_manager/contacts_routing_spec.rb +36 -0
- data/spec/test_app/spec/routing/mail_manager/mailing_lists_routing_spec.rb +36 -0
- data/spec/test_app/spec/routing/mail_manager/mailings_routing_spec.rb +36 -0
- data/spec/test_app/spec/spec_helper.rb +82 -32
- data/spec/test_app/spec/support/continuance.rb +18 -0
- data/spec/test_app/spec/support/custom_matchers.rb +17 -0
- data/spec/test_app/spec/support/database_cleaner.rb +10 -1
- data/spec/test_app/spec/views/mail_manager/bounces/index.html.erb_spec.rb +32 -0
- data/spec/test_app/spec/views/mail_manager/bounces/show.html.erb_spec.rb +12 -0
- data/spec/test_app/spec/views/users/edit.html.erb_spec.rb +8 -5
- data/spec/test_app/spec/views/users/index.html.erb_spec.rb +10 -19
- data/spec/test_app/spec/views/users/new.html.erb_spec.rb +9 -6
- data/spec/test_app/spec/views/users/show.html.erb_spec.rb +8 -9
- metadata +231 -75
- data/.DS_Store +0 -0
- data/README.rdoc +0 -3
- data/app/.DS_Store +0 -0
- data/app/controllers/mail_manager/base_controller.rb +0 -22
- data/app/models/.DS_Store +0 -0
- data/features/contact_management.feature +0 -24
- data/features/mailing_management.feature +0 -78
- data/features/step_definitions/email_steps.rb +0 -50
- data/features/step_definitions/mlm_steps.rb +0 -11
- data/features/step_definitions/pickle_steps.rb +0 -41
- data/features/subscription_management.feature +0 -17
- data/features/support/env.rb +0 -11
- data/features/support/paths.rb +0 -44
- data/lib/tasks/mail_manager_tasks.rake +0 -4
- data/lib/tasks/rspec.rake +0 -165
- data/spec/test_app/bin/cucumber +0 -7
- data/spec/test_app/bin/rails +0 -10
- data/spec/test_app/bin/rake +0 -7
- data/spec/test_app/bin/rspec +0 -7
- data/spec/test_app/bin/spring +0 -18
- data/spec/test_app/spec/routing/users_routing_spec.rb +0 -35
- data/spec/test_app/spec/support/post_office.rb +0 -13
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::LayoutHelper, :type => :helper do
|
|
4
|
+
describe "#title" do
|
|
5
|
+
it "translates what you give it and returns when translation exists" do
|
|
6
|
+
expect(helper.title("mail_manager/mailing.edit.title", subject: "Bonkers",
|
|
7
|
+
default: "Edit my 'Bonkers'")
|
|
8
|
+
).to eq("<h1>Edit Bonkers</h1>")
|
|
9
|
+
and_it "then returns the same thing ... without the h1 tags on the subsequent call" do
|
|
10
|
+
expect(helper.title).to eq "Edit Bonkers"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
it "translates to your default when your translation name doesn't exist" do
|
|
14
|
+
expect(helper.title("my.nonsense.title", subject: "Bonkers",
|
|
15
|
+
default: "Edit my 'Bonkers'")
|
|
16
|
+
).to eq("<h1>Edit my 'Bonkers'</h1>")
|
|
17
|
+
and_it "then returns the same thing ... without the h1 tags on the subsequent call" do
|
|
18
|
+
expect(helper.title).to eq "Edit my 'Bonkers'"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
describe "#site_url" do
|
|
23
|
+
it "returns the mail manager's site_url setting as a helper" do
|
|
24
|
+
expect{helper.site_url}.not_to raise_error
|
|
25
|
+
expect(helper.site_url).to eq(MailManager.site_url)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
describe "#show_title?" do
|
|
29
|
+
it "returns the mail manager's show_title setting as a helper" do
|
|
30
|
+
expect{helper.show_title?}.not_to raise_error
|
|
31
|
+
expect(helper.show_title?).to eq(MailManager.show_title)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
describe "#use_show_for_resources?" do
|
|
35
|
+
it "returns the mail manager's use_show_for_resources setting as a helper" do
|
|
36
|
+
expect{helper.use_show_for_resources?}.not_to raise_error
|
|
37
|
+
expect(helper.use_show_for_resources?).to eq(MailManager.use_show_for_resources)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::SubscriptionsHelper, :type => :helper do
|
|
4
|
+
describe "#contactable_subscriptions_selector" do
|
|
5
|
+
it "creates a subform for a contact's mailing list subscriptions" do
|
|
6
|
+
FactoryGirl.create(:mailing_list, name: "Peeps", defaults_to_active: true)
|
|
7
|
+
FactoryGirl.create(:mailing_list, name: "Others", defaults_to_active: false)
|
|
8
|
+
form_for MailManager::Contact.new, url: '/mail_manager/contacts', method: :post do |f|
|
|
9
|
+
expect(contactable_subscriptions_selector(f)).to match /Peeps/
|
|
10
|
+
expect(contactable_subscriptions_selector(f)).to match /Others/
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
class BreakMe < Struct.new(:bob)
|
|
4
|
+
def perform
|
|
5
|
+
raise "I don't work!#{bob}"
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
RSpec.describe Delayed::Mailer do
|
|
10
|
+
it "sends an email when a job fails" do
|
|
11
|
+
Delayed::Worker.delay_jobs = true
|
|
12
|
+
Delayed::Worker.max_attempts = 0
|
|
13
|
+
Delayed::Job.delete_all
|
|
14
|
+
ActionMailer::Base.deliveries.clear
|
|
15
|
+
previous_method = ActionMailer::Base.delivery_method
|
|
16
|
+
ActionMailer::Base.delivery_method = :test
|
|
17
|
+
Delayed::Job.enqueue BreakMe.new("Funk")
|
|
18
|
+
Delayed::Worker.new(name: 'Bunk').work_off
|
|
19
|
+
Debugging::wait_until_success do
|
|
20
|
+
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
|
21
|
+
expect(ActionMailer::Base.deliveries.first.body).to match /I don't work!Funk/
|
|
22
|
+
end
|
|
23
|
+
Delayed::Worker.delay_jobs = false
|
|
24
|
+
ActionMailer::Base.delivery_method = previous_method
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Delayed::StatusJob do
|
|
4
|
+
it "recreates itself on success" do
|
|
5
|
+
Delayed::Worker.delay_jobs = true
|
|
6
|
+
Delayed::StatusJob.new.perform
|
|
7
|
+
expect(Delayed::Job.count).to eq(1)
|
|
8
|
+
expect(Delayed::Job.first.handler).to match /Delayed::StatusJob/
|
|
9
|
+
expect(Delayed::Job.first.run_at.utc.to_i).to be_within(5).of(
|
|
10
|
+
1.minute.from_now.utc.to_i
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe Delayed::Status do
|
|
4
|
+
before(:each) do
|
|
5
|
+
Delayed::Worker.delay_jobs = true
|
|
6
|
+
end
|
|
7
|
+
after(:each) do
|
|
8
|
+
Timecop.return
|
|
9
|
+
Delayed::Worker.delay_jobs = false
|
|
10
|
+
end
|
|
11
|
+
it "Creates a status job when invoked and it doesn't yet exist" do
|
|
12
|
+
expect(Delayed::Status.ok?).to be true
|
|
13
|
+
expect(Delayed::Job.count).to eq(1)
|
|
14
|
+
expect(Delayed::Job.first.handler).to match /Delayed::StatusJob/
|
|
15
|
+
Timecop.travel 20.minutes.from_now
|
|
16
|
+
and_it "gripes when the status job is overdue for a run by the specified time" do
|
|
17
|
+
expect{Delayed::Status.ok?(15.minutes)}.to raise_error(
|
|
18
|
+
Delayed::StatusException, /Status job hasn't run for \d+ seconds/
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
and_it "gripes when the status job is overdue for a run for 15 minutes" do
|
|
22
|
+
expect{Delayed::Status.ok?}.to raise_error(
|
|
23
|
+
Delayed::StatusException, /Status job hasn't run for \d+ seconds/
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
and_it "is OK when the status job is overdue for only 20 minutes and you ask about 25" do
|
|
27
|
+
expect{Delayed::Status.ok?(25.minutes)}.not_to raise_error
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
it "gripes when you have failed jobs" do
|
|
31
|
+
Delayed::Status.ok?
|
|
32
|
+
Delayed::Job.first.update_attribute(:failed_at, Time.now.utc)
|
|
33
|
+
expect{Delayed::Status.ok?}.to raise_error(
|
|
34
|
+
Delayed::StatusException, "There are 1 failed jobs!"
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
-
require '
|
|
2
|
+
require 'rails_helper'
|
|
3
3
|
|
|
4
|
-
describe MailManager::Bounce do
|
|
4
|
+
RSpec.describe MailManager::Bounce do
|
|
5
5
|
context "when checking pop account" do
|
|
6
6
|
it "should not blow up when mail contains a bad extended char" do
|
|
7
7
|
Delayed::Worker.delay_jobs = true
|
|
@@ -9,9 +9,29 @@ describe MailManager::Bounce do
|
|
|
9
9
|
MailManager::BounceJob.new.perform
|
|
10
10
|
Delayed::Worker.delay_jobs = false
|
|
11
11
|
end
|
|
12
|
+
it "should run every 10 minutes when there is mail on the current run" do
|
|
13
|
+
Delayed::Worker.delay_jobs = true
|
|
14
|
+
send_bounce('bad_utf8_chars.eml')
|
|
15
|
+
MailManager::BounceJob.new.perform
|
|
16
|
+
expect(Delayed::Job.count).to eq(1)
|
|
17
|
+
expect(Delayed::Job.first.run_at.utc.to_i).to be_within(5).of(
|
|
18
|
+
10.minutes.from_now.utc.to_i
|
|
19
|
+
)
|
|
20
|
+
Delayed::Worker.delay_jobs = false
|
|
21
|
+
end
|
|
22
|
+
it "should run every 120 minutes when there is no mail on the current check" do
|
|
23
|
+
Delayed::Worker.delay_jobs = true
|
|
24
|
+
MailManager::BounceJob.new.perform
|
|
25
|
+
Delayed::Job.delete_all
|
|
26
|
+
MailManager::BounceJob.new.perform
|
|
27
|
+
expect(Delayed::Job.count).to eq(1)
|
|
28
|
+
expect(Delayed::Job.first.run_at.utc.to_i).to be_within(5).of(
|
|
29
|
+
120.minutes.from_now.utc.to_i
|
|
30
|
+
)
|
|
31
|
+
Delayed::Worker.delay_jobs = false
|
|
32
|
+
end
|
|
12
33
|
end
|
|
13
34
|
def send_bounce(filename)
|
|
14
|
-
PostOffice.start_post_office
|
|
15
35
|
mail = Mail.new(File.read(File.join(Rails.root,'spec','support','files',filename)))
|
|
16
36
|
mail.delivery_method :smtp
|
|
17
37
|
mail.delivery_method.settings.merge!(ActionMailer::Base.smtp_settings)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::Engine do
|
|
4
|
+
it "knows its asset path" do
|
|
5
|
+
expect(MailManager.assets_path).to eq(File.join(MailManager::PLUGIN_ROOT, 'assets'))
|
|
6
|
+
end
|
|
7
|
+
context "when authentication is not needed" do
|
|
8
|
+
before(:each) do
|
|
9
|
+
MailManager.requires_authentication = false
|
|
10
|
+
MailManager.authorized_roles = []
|
|
11
|
+
end
|
|
12
|
+
it "authorizes a nil user" do
|
|
13
|
+
expect(MailManager.authorized?(nil)).to be true
|
|
14
|
+
end
|
|
15
|
+
it "authorizes an actual User" do
|
|
16
|
+
expect(MailManager.authorized?(FactoryGirl.create(:user))).to be true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
context "when only authentication is needed" do
|
|
20
|
+
before(:each) do
|
|
21
|
+
MailManager.requires_authentication = true
|
|
22
|
+
MailManager.authorized_roles = []
|
|
23
|
+
end
|
|
24
|
+
after(:each) do
|
|
25
|
+
MailManager.requires_authentication = false
|
|
26
|
+
end
|
|
27
|
+
it "won't authorize a nil user" do
|
|
28
|
+
expect(MailManager.authorized?(nil)).to be false
|
|
29
|
+
end
|
|
30
|
+
it "authorizes an actual User" do
|
|
31
|
+
expect(MailManager.authorized?(FactoryGirl.create(:user))).to be true
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
context "when authentication is needed with role 'admin'" do
|
|
35
|
+
before(:each) do
|
|
36
|
+
MailManager.requires_authentication = true
|
|
37
|
+
MailManager.authorized_roles = ['admin']
|
|
38
|
+
end
|
|
39
|
+
after(:each) do
|
|
40
|
+
MailManager.requires_authentication = false
|
|
41
|
+
MailManager.authorized_roles = []
|
|
42
|
+
end
|
|
43
|
+
it "won't authorizes a nil user" do
|
|
44
|
+
expect(MailManager.authorized?(nil)).to be false
|
|
45
|
+
end
|
|
46
|
+
it "won't authorizes an object that doesn't respond to 'role' or 'roles'" do
|
|
47
|
+
expect(MailManager.authorized?(MailManager::Contact.new)).to be false
|
|
48
|
+
end
|
|
49
|
+
it "authorizes an actual User with roles ['admin']" do
|
|
50
|
+
expect(MailManager.authorized?(FactoryGirl.create(:admin_user))).to be true
|
|
51
|
+
end
|
|
52
|
+
it "authorizes an actual User with role 'admin'" do
|
|
53
|
+
expect(MailManager.authorized?(FactoryGirl.create(:admin_user_with_role))).to be true
|
|
54
|
+
end
|
|
55
|
+
it "won't authorize the user if they aren't an admin(admin role)" do
|
|
56
|
+
expect(MailManager.authorized?(FactoryGirl.create(:user))).to be false
|
|
57
|
+
end
|
|
58
|
+
context "and a roles_method is given" do
|
|
59
|
+
before(:each) do
|
|
60
|
+
MailManager.roles_method = "roles"
|
|
61
|
+
end
|
|
62
|
+
after(:each) do
|
|
63
|
+
MailManager.roles_method = nil
|
|
64
|
+
end
|
|
65
|
+
it "won't authorize if the user doesn't have that method" do
|
|
66
|
+
expect(MailManager.authorized?(FactoryGirl.create(:admin_user_with_role))).to be false
|
|
67
|
+
end
|
|
68
|
+
it "won't authorize a nil user" do
|
|
69
|
+
expect(MailManager.authorized?(nil)).to be false
|
|
70
|
+
end
|
|
71
|
+
it "won't authorize a users without the mentioned roles" do
|
|
72
|
+
expect(MailManager.authorized?(FactoryGirl.create(:user))).to be false
|
|
73
|
+
end
|
|
74
|
+
it "authorizes a user with the mentioned roles and method" do
|
|
75
|
+
expect(MailManager.authorized?(FactoryGirl.create(:user))).to be false
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::Mailable do
|
|
4
|
+
let(:mailable) {FactoryGirl.build(:mailable)}
|
|
5
|
+
it "responds to mailable attributes for creating a mailing's content" do
|
|
6
|
+
expect(mailable).to respond_to (:email_html)
|
|
7
|
+
expect(mailable).to respond_to (:email_text)
|
|
8
|
+
expect(mailable).to respond_to (:name)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'rails_helper'
|
|
2
2
|
|
|
3
|
-
describe MailManager::Mailer do
|
|
3
|
+
RSpec.describe MailManager::Mailer do
|
|
4
4
|
it "Can fetch images from https servers" do
|
|
5
5
|
image_url = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRwNmnMYLBp2Sw9vg-snbZ_GKONKo_WY0f3S1ETL2era2DZKKqD'
|
|
6
6
|
data = MailManager::Mailer.fetch(image_url)
|
|
7
7
|
expect(data.to_s[0..100]).to include('JFIF')
|
|
8
|
+
and_it "knows a jpeg when getting extension from its data" do
|
|
9
|
+
expect(MailManager::Mailer.get_extension_from_data(data)).to eq "JPEG"
|
|
10
|
+
end
|
|
8
11
|
end
|
|
9
|
-
|
|
12
|
+
context "can get an image's extension from its data" do
|
|
13
|
+
it "for gifs" do
|
|
14
|
+
image = MailManager::Mailer.fetch("file://" + File.join(MailManager::PLUGIN_ROOT, 'app','assets','images','mail_manager','BottomRight.gif'))
|
|
15
|
+
expect(MailManager::Mailer.get_extension_from_data(image).upcase).to eq 'GIF'
|
|
16
|
+
end
|
|
17
|
+
it "for garbage data" do
|
|
18
|
+
image = "THIS IS NOT AN IMAGE BLAH BHAL"
|
|
19
|
+
expect(MailManager::Mailer.get_extension_from_data(image).upcase).to eq ''
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
it "sets its delivery methods correctly" do
|
|
23
|
+
mail = Mail.new
|
|
24
|
+
ActionMailer::Base.delivery_method = :smtp
|
|
25
|
+
previous_settings = ActionMailer::Base.smtp_settings
|
|
26
|
+
ActionMailer::Base.smtp_settings = smtp_settings = {
|
|
27
|
+
domain: 'example.com',
|
|
28
|
+
address: 'mail.lvh.me',
|
|
29
|
+
port: 587,
|
|
30
|
+
password: 'Secret1!',
|
|
31
|
+
user_name: 'bobo',
|
|
32
|
+
enable_starttls_auto: true,
|
|
33
|
+
authentication: :plain,
|
|
34
|
+
}
|
|
35
|
+
MailManager::Mailer.set_mail_settings(mail)
|
|
36
|
+
expect(mail.delivery_method.settings.values.map(&:to_s).select(&:present?).sort).to eq(
|
|
37
|
+
smtp_settings.values.select(&:present?).map(&:to_s).sort
|
|
38
|
+
)
|
|
39
|
+
ActionMailer::Base.smtp_settings = previous_settings
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'rails_helper'
|
|
2
2
|
|
|
3
|
-
describe MailManager::MailingList do
|
|
3
|
+
RSpec.describe MailManager::MailingList do
|
|
4
4
|
context "a valid mailing list" do
|
|
5
5
|
before(:each) do
|
|
6
6
|
@mailing_list = FactoryGirl.build(:mailing_list)
|
|
7
7
|
end
|
|
8
8
|
it "must have a name" do
|
|
9
|
-
@mailing_list.name.present
|
|
10
|
-
@mailing_list.valid
|
|
9
|
+
expect(@mailing_list.name.present?).to eq true
|
|
10
|
+
expect(@mailing_list.valid?).to eq true
|
|
11
11
|
@mailing_list.name = nil
|
|
12
|
-
@mailing_list.valid
|
|
12
|
+
expect(@mailing_list.valid?).to eq false
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::Mailing do
|
|
4
|
+
let(:valid_attributes) {FactoryGirl.attributes_for(:mailing)}
|
|
5
|
+
let(:invalid_attributes) {FactoryGirl.attributes_for(:mailing).delete(
|
|
6
|
+
'from_email_address')
|
|
7
|
+
}
|
|
8
|
+
before(:each) do
|
|
9
|
+
ActionMailer::Base.delivery_method = :test
|
|
10
|
+
Delayed::Worker.delay_jobs = false
|
|
11
|
+
ActionMailer::Base.deliveries.clear
|
|
12
|
+
end
|
|
13
|
+
it "sets its initial status properly" do
|
|
14
|
+
attributes = valid_attributes
|
|
15
|
+
attributes.delete('status')
|
|
16
|
+
attributes.delete('status_updated_at')
|
|
17
|
+
mailing = MailManager::Mailing.new(attributes)
|
|
18
|
+
mailing.save
|
|
19
|
+
expect(mailing.status.to_s).to eq('pending')
|
|
20
|
+
expect(mailing.status_changed_at).not_to be nil
|
|
21
|
+
end
|
|
22
|
+
it "will soft delete a mailing" do
|
|
23
|
+
mailing = MailManager::Mailing.create(valid_attributes)
|
|
24
|
+
mailing.delete
|
|
25
|
+
expect(MailManager::Mailing.count).to eq 0
|
|
26
|
+
expect(MailManager::Mailing.deleted.count).to eq 1
|
|
27
|
+
end
|
|
28
|
+
it "doesn't include images when configured to not do so for a domain" do
|
|
29
|
+
# should be in config
|
|
30
|
+
image_url = "http://www.lone-star.net/graphics/lst_header_logo.png"
|
|
31
|
+
expect(MailManager.dont_include_images_domains).to include('yahoo.com')
|
|
32
|
+
mailing = FactoryGirl.create(:mailing, include_images: true)
|
|
33
|
+
mailing.mailable.update_attribute(:email_html, mailing.mailable.email_html.gsub(%r#file://.*/iReach_logo.gif#,image_url))
|
|
34
|
+
mailing.send_test_message('bobo@yahoo.com')
|
|
35
|
+
html_body = ActionMailer::Base.deliveries.last.parts.last.body
|
|
36
|
+
expect(html_body).to match /#{image_url}/
|
|
37
|
+
expect(html_body).not_to match %r#cid:#
|
|
38
|
+
end
|
|
39
|
+
it "doesn't include images when include_images is false" do
|
|
40
|
+
# should be in config
|
|
41
|
+
image_url = "http://www.lone-star.net/graphics/lst_header_logo.png"
|
|
42
|
+
expect(MailManager.dont_include_images_domains).to include('yahoo.com')
|
|
43
|
+
mailing = FactoryGirl.create(:mailing, include_images: false)
|
|
44
|
+
mailing.mailable.update_attribute(:email_html, mailing.mailable.email_html.gsub(%r#file://.*/iReach_logo.gif#,image_url))
|
|
45
|
+
mailing.send_test_message('bobo@example.com')
|
|
46
|
+
html_body = ActionMailer::Base.deliveries.last.parts.last.body
|
|
47
|
+
expect(html_body).to match /#{image_url}/
|
|
48
|
+
expect(html_body).not_to match %r#cid:#
|
|
49
|
+
end
|
|
50
|
+
it "does include images when its configuration doesn't exclude an email domain" do
|
|
51
|
+
image_url = "http://www.lone-star.net/graphics/lst_header_logo.png"
|
|
52
|
+
expect(MailManager.dont_include_images_domains).not_to include('example.com')
|
|
53
|
+
mailing = FactoryGirl.create(:mailing, include_images: true)
|
|
54
|
+
mailing.mailable.update_attribute(:email_html, mailing.mailable.email_html.gsub(%r#file://.*/iReach_logo.gif#,image_url))
|
|
55
|
+
mailing.send_test_message('bobo@example.com')
|
|
56
|
+
html_body = ActionMailer::Base.deliveries.last.to_s =~ /cid:=/
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MailManager::Message do
|
|
4
|
+
def message
|
|
5
|
+
@message
|
|
6
|
+
end
|
|
7
|
+
before(:each) do
|
|
8
|
+
@message = FactoryGirl.create(:message)
|
|
9
|
+
end
|
|
10
|
+
describe "concerning statuses" do
|
|
11
|
+
it "starts in :pending" do
|
|
12
|
+
expect(message.status).to eq('pending')
|
|
13
|
+
end
|
|
14
|
+
it "goes to 'sent' on a deliver" do
|
|
15
|
+
message.save
|
|
16
|
+
message.deliver
|
|
17
|
+
expect(message.status).to eq('sent')
|
|
18
|
+
end
|
|
19
|
+
it "goes to 'failed_address' on a message bounce" do
|
|
20
|
+
pending "need to get a failed worthy bounce!"
|
|
21
|
+
raise "not tested"
|
|
22
|
+
end
|
|
23
|
+
it "stays 'sent' on a temporary message bounce" do
|
|
24
|
+
pending "need to get a temporary bounce!"
|
|
25
|
+
raise "not tested"
|
|
26
|
+
end
|
|
27
|
+
it "goes to 'processing' while it is being sent" do
|
|
28
|
+
pending "figure this out... its in the middle of a deliver"
|
|
29
|
+
raise "not tested"
|
|
30
|
+
end
|
|
31
|
+
describe "and can't be delivered unless it is currently pending or ready" do
|
|
32
|
+
it "when pending can be delivered" do
|
|
33
|
+
expect(message.can_deliver?).to be true
|
|
34
|
+
end
|
|
35
|
+
it "when ready can be delivered" do
|
|
36
|
+
message.change_status('ready')
|
|
37
|
+
expect(message.can_deliver?).to be true
|
|
38
|
+
end
|
|
39
|
+
it "when processing cannot be delivered" do
|
|
40
|
+
message.change_status('processing')
|
|
41
|
+
expect(message.can_deliver?).to be false
|
|
42
|
+
end
|
|
43
|
+
it "when sent cannot be delivered" do
|
|
44
|
+
message.change_status('sent')
|
|
45
|
+
expect(message.can_deliver?).to be false
|
|
46
|
+
end
|
|
47
|
+
it "when failed cannot be delivered" do
|
|
48
|
+
message.change_status('failed')
|
|
49
|
+
expect(message.can_deliver?).to be false
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "has a email_address_with_name when a name is present on the contact" do
|
|
55
|
+
contact = message.contact
|
|
56
|
+
expect(message.email_address_with_name).to eq(%Q|"#{contact.full_name}" <#{contact.email_address}>|)
|
|
57
|
+
and_it "only has email when the contact has no name" do
|
|
58
|
+
message.contact.update_attributes(first_name: nil, last_name: nil)
|
|
59
|
+
expect(message.email_address_with_name).to eq(contact.email_address)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "knows its mailing's subject" do
|
|
64
|
+
expect(message.subject).to eq(message.mailing.subject)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "knows its contact's full name" do
|
|
68
|
+
expect(message.full_name).to eq(message.contact.full_name)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "concerning a deleted contact" do
|
|
72
|
+
before(:each) do
|
|
73
|
+
@contact = MailManager::Contact.find(message.contact_id)
|
|
74
|
+
@contact.delete
|
|
75
|
+
@message = MailManager::Message.find(message.id)
|
|
76
|
+
end
|
|
77
|
+
it "doesn't blow up when asking for full_name" do
|
|
78
|
+
expect(message.full_name).to eq @contact.full_name
|
|
79
|
+
end
|
|
80
|
+
it "doesn't blow up when asking for email_address" do
|
|
81
|
+
expect(message.email_address).to eq @contact.email_address
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "concerning a nil contact" do
|
|
86
|
+
before(:each) do
|
|
87
|
+
MailManager::Contact.where(id: message.contact_id).delete_all
|
|
88
|
+
@message = MailManager::Message.find(message.id)
|
|
89
|
+
end
|
|
90
|
+
it "doesn't blow up when asking for full_name" do
|
|
91
|
+
expect(message.full_name).to eq nil
|
|
92
|
+
end
|
|
93
|
+
it "doesn't blow up when asking for email_address" do
|
|
94
|
+
expect(message.email_address).to eq nil
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "concerning a contact's data" do
|
|
99
|
+
it "will substitute values into messages" do
|
|
100
|
+
pending "not tested"
|
|
101
|
+
raise "not tested"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "concerning a registerd contactable's data" do
|
|
106
|
+
it "will substitute values into messages" do
|
|
107
|
+
pending "not tested"
|
|
108
|
+
raise "not tested"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|