Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send automatic emails to organizers when event gets approved and deadline passed #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def approve
tweet_event_check
inform_applicants_country
inform_applicants_field_of_interest
inform_organizer
redirect_to admin_path, notice: "#{@event.name} has been approved"
else
redirect_to admin_path, notice: "#{@event.name} has been unapproved"
Expand Down Expand Up @@ -126,6 +127,10 @@ def inform_applicants_field_of_interest
end
end

def inform_organizer
OrganizerMailer.approved_event(@event).deliver_later
end

def tweet_event_check
Tweet.create(event_id: @event.id, published: false) if params[:approve][:tweet] == "0"
end
Expand Down
17 changes: 15 additions & 2 deletions app/mailers/organizer_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ def submitted_event(event)

def approved_event(event)
@event = event
mail(to: @event.organizer_email, subject: 'Your event has been approved.')
mail(
to: @event.organizer_email,
subject: "Your event #{event.name} has been approved.",
template_path: 'organizer_mailer/approved_event',
template_name: @event.application_process,
)
end

def ticket_capacity_reached(event)
@event = event
mail(to: @event.organizer_email, subject: 'Your event received more applications than available tickets.')
mail(
to: @event.organizer_email,
subject: "Your event #{@event.name} received more applications than available tickets.",
)
end

def passed_event_deadline(event)
@event = event
mail(to: @event.organizer_email, subject: "#{@event.name}'s deadline passed.")
end
end
4 changes: 4 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def self.application_via_diversitytickets
where.not(application_process: 'application_by_organizer')
end

def self.selection_by_organizer
where(application_process: 'selection_by_organizer')
end

def self.approved
where(approved: true)
end
Expand Down
4 changes: 4 additions & 0 deletions app/services/deadline_passed_mail_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ def self.send_deadline_passed_mail
AdminMailer.passed_event_deadline(event, user.email).deliver_later
end
end

Event.approved.selection_by_organizer.deadline_yesterday.each do |event|
OrganizerMailer.passed_event_deadline(event).deliver_later
end
end
end
11 changes: 0 additions & 11 deletions app/views/organizer_mailer/approved_event.text.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Dear <%= @event.organizer_name %>,

Thank you so much for submitting your conference <%= @event.name %> to diversitytickets.org.
You have selected the option of just listing your event on our site and handling the application and selection process externally, so we've gone ahead and approved the conference.

The event looks like this now: https://diversitytickets.org/events/<%= @event.id %>. An automatic tweet will be shared shortly on https://twitter.com/DiversityTix.

Thank you for offering free diversity tickets to your conference. This helps raise awareness of all the work that still needs to be done to build an inclusive tech community, and offers possibilities to underrepresented people in tech to join your conference.

Please don't hesitate to reach out to [email protected] if you have any questions.

Best,
The Diversity Tickets Team

-
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Dear <%= @event.organizer_name %>,

Thanks so much for reaching out and submitting <%= @event.name %> to diversitytickets.org.
You chose the option to have us handle the application and handle the selection process yourself.
For the application process, we use this form: https://diversitytickets.org/events/<%= @event.id %>/applications/new. After the application deadline has passed, you can download the applications from the event overview here https://diversitytickets.org/users/<%= @event.organizer_id %>.

We've gone ahead and published your event, you can find it here https://diversitytickets.org/events/<%= @event.id %>. An automatic tweet will be shared shortly on https://twitter.com/DiversityTix.

Thank you for offering free diversity tickets to your conference. This helps raise awareness of all the work that still needs to be done to build an inclusive tech community, and offers possibilities to underrepresented people in tech to join your conference.

Please don't hesitate to reach out to [email protected] if you have any questions.

Best,
The Diversity Tickets Team

-
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Dear <%= @event.organizer_name %>,

Thanks so much for reaching out and submitting <%= @event.name %> to diversitytickets.org.
You chose the option to have us handle both the application and the selection process.
For the application process, we use this form: https://diversitytickets.org/events/<%= @event.id %>/applications/new. After the application deadline has passed, we will select the winners and send their contact details to you, so you can give them further instructions on how to receive the diversity ticket and other benefits.

We've gone ahead and published your event, you can find it here https://diversitytickets.org/events/<%= @event.id %>. An automatic tweet will be shared shortly on https://twitter.com/DiversityTix.

Thank you for offering free diversity tickets to your conference. This helps raise awareness of all the work that still needs to be done to build an inclusive tech community, and offers possibilities to underrepresented people in tech to join your conference.

Please don't hesitate to reach out to [email protected] if you have any questions.

Best,
The Diversity Tickets Team

-
12 changes: 12 additions & 0 deletions app/views/organizer_mailer/passed_event_deadline.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Hello <%= @event.organizer_name %>,

The deadline of your event <%= @event.name %> has passed. You can now download the applications from the 'Your events' overview page here https://diversitytickets.org/users/<%= @event.organizer_id %>. If you want some input on what we recommend for a selection process, you can read more about our own process here: http://foundation.travis-ci.org/2016/04/26/diversity-tickets/.

Thank you again for offering free diversity tickets to your conference.

Please don't hesitate to reach out to [email protected] if you have any questions.

Best,
The Diversity Tickets Team

-
4 changes: 2 additions & 2 deletions test/controllers/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class ApplicationsControllerTest < ActionController::TestCase
reminder_email = ActionMailer::Base.deliveries.last
assert_equal(
reminder_email.subject,
"Your event received more applications than available tickets."
"Your event #{event.name} received more applications than available tickets."
)
end

Expand Down Expand Up @@ -275,7 +275,7 @@ class ApplicationsControllerTest < ActionController::TestCase
reminder_emails = []
emails = ActionMailer::Base.deliveries
emails.each do |email|
if email.subject == "Your event received more applications than available tickets."
if email.subject == "Your event #{event.name} received more applications than available tickets."
reminder_emails << email
end
end
Expand Down
60 changes: 50 additions & 10 deletions test/mailers/organizer_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
require 'test_helper'

class OrganizerMailerTest < ActionMailer::TestCase
def setup
@event = make_event
end

test "submitted_event" do
email = OrganizerMailer.submitted_event(@event)
event = make_event
email = OrganizerMailer.submitted_event(event)

assert_emails 1 do
email.deliver_now
end

assert_equal ['[email protected]'], email.from
assert_equal [@event.organizer_email], email.to
assert_equal [event.organizer_email], email.to
assert_equal 'You submitted a new event.', email.subject
end

test "approved_event" do
email = OrganizerMailer.approved_event(@event)
test "approved_event for event with `selection_by_travis`" do
event = make_event(application_process: 'selection_by_travis')
email = OrganizerMailer.approved_event(event)

assert_emails 1 do
email.deliver_now
end

assert_equal ['[email protected]'], email.from
assert_equal [event.organizer_email], email.to
assert_equal "Your event #{event.name} has been approved.", email.subject
assert /You chose the option to have us handle both the application and the selection process/ =~ email.body.raw_source
end

test "approved_event for event with `selection_by_organizer`" do
event = make_event(application_process: 'selection_by_organizer')
email = OrganizerMailer.approved_event(event)

assert_emails 1 do
email.deliver_now
end

assert_equal ['[email protected]'], email.from
assert_equal [event.organizer_email], email.to
assert_equal "Your event #{event.name} has been approved.", email.subject
assert /You chose the option to have us handle the application and handle the selection process yourself/ =~ email.body.raw_source
end

test "approved_event for event with `application_by_organizer`" do
event = make_event(application_process: 'application_by_organizer', application_link: 'https://mylink.com')
email = OrganizerMailer.approved_event(event)

assert_emails 1 do
email.deliver_now
end

assert_equal ['[email protected]'], email.from
assert_equal [event.organizer_email], email.to
assert_equal "Your event #{event.name} has been approved.", email.subject
assert /You have selected the option of just listing your event on our site/ =~ email.body.raw_source
end

test "passed_event_deadline" do
event = make_event
email = OrganizerMailer.passed_event_deadline(event)

assert_emails 1 do
email.deliver_now
end

assert_equal ['[email protected]'], email.from
assert_equal [@event.organizer_email], email.to
assert_equal 'Your event has been approved.', email.subject
assert_equal [event.organizer_email], email.to
assert_equal "#{event.name}'s deadline passed.", email.subject
end
end
81 changes: 56 additions & 25 deletions test/services/deadline_passed_mail_service_test.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
require 'test_helper'

class DeadlinePassedMailServiceTest < ActiveSupport::TestCase
describe 'sending emails about events with passed deadlines to admins' do
it 'send emails about right events to the right people' do
make_event(deadline: 1.days.ago, approved: true, name: 'Valid Event')
make_event(deadline: 1.week.ago)
make_user(email: '[email protected]')
make_admin(email: '[email protected]')
describe 'sending emails about events with passed deadlines to admins and organizer' do
it 'sends emails to organizer & admin when application process is `selection_by_organizer`' do
organizer = make_user(email: '[email protected]')
make_event(
deadline: 1.days.ago, approved: true, name: 'Valid Event', organizer_id: organizer.id,
organizer_email: organizer.email, organizer_email_confirmation: organizer.email,
application_process: 'selection_by_organizer',
)
make_user(email: '[email protected]')
admin = make_admin(email: '[email protected]')

ActionMailer::Base.deliveries.clear

DeadlinePassedMailService.send_deadline_passed_mail

mails = ActionMailer::Base.deliveries
assert_equal 2, mails.length

admin_mails = mails.select { |mail| mail.to == [admin.email] }
organizer_mails = mails.select { |mail| mail.to == [organizer.email] }
assert_equal 1, admin_mails.length
assert_equal 1, organizer_mails.length
end

it 'sends email only to admin when application process is `selection_by_travis`' do
organizer = make_user(email: '[email protected]')
make_event(
deadline: 1.days.ago, approved: true, name: 'Valid Event', organizer_id: organizer.id,
organizer_email: organizer.email, organizer_email_confirmation: organizer.email,
application_process: 'selection_by_travis',
)
make_user(email: '[email protected]')
admin = make_admin(email: '[email protected]')

ActionMailer::Base.deliveries.clear

DeadlinePassedMailService.send_deadline_passed_mail

mails = ActionMailer::Base.deliveries
assert_equal 1, mails.length
mail = mails.first
assert_equal ['[email protected]'], mail.to
assert mail.subject =~ /Valid Event/

admin_mails = mails.select { |mail| mail.to == [admin.email] }
organizer_mails = mails.select { |mail| mail.to == [organizer.email] }
assert_equal 1, admin_mails.length
assert_equal 0, organizer_mails.length
end

it 'excludes events that are listings (applications & selection are handled by organizer)' do
it 'excludes events that have the wrong deadline' do
make_event(
deadline: 1.days.ago, approved: true, name: 'Valid Event',
application_process: 'selection_by_travis'
deadline: 1.week.ago, approved: true, name: 'Past Event',
application_process: 'selection_by_organizer'
)
make_event(
deadline: 1.days.ago, approved: true, name: 'Valid Event',
deadline: Date.tomorrow, approved: true, name: 'Future Event',
application_process: 'selection_by_organizer'
)
make_admin

ActionMailer::Base.deliveries.clear

DeadlinePassedMailService.send_deadline_passed_mail

mails = ActionMailer::Base.deliveries
assert_equal 0, mails.length
end

it 'excludes events that are listings (applications & selection are handled by organizer)' do
make_event(
deadline: 1.days.ago, name: 'Listed Event',
deadline: 1.days.ago, approved: true, name: 'Listed Event',
application_process: 'application_by_organizer', application_link: 'https://myconf.com'
)
make_admin
Expand All @@ -39,18 +79,10 @@ class DeadlinePassedMailServiceTest < ActiveSupport::TestCase
DeadlinePassedMailService.send_deadline_passed_mail

mails = ActionMailer::Base.deliveries
assert_equal 2, mails.length
mail1 = mails.first
mail2 = mails.last
assert mail1.subject =~ /Valid Event/
assert mail2.subject =~ /Valid Event/
assert_equal 0, mails.length
end

it 'excludes events that are not approved' do
make_event(
deadline: 1.days.ago, approved: true, name: 'Valid Event',
application_process: 'selection_by_travis'
)
make_event(
deadline: 1.days.ago, approved: false, name: 'Unapproved Event',
application_process: 'selection_by_organizer'
Expand All @@ -62,8 +94,7 @@ class DeadlinePassedMailServiceTest < ActiveSupport::TestCase
DeadlinePassedMailService.send_deadline_passed_mail

mails = ActionMailer::Base.deliveries
assert_equal 1, mails.length
assert mails.first.subject =~ /Valid Event/
assert_equal 0, mails.length
end
end
end
17 changes: 17 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,21 @@ def assert_attribute_invalid(event, attribute)
event.valid?
refute_equal [], event.errors[attribute]
end

def assert_same_items(expected, actual)
assert same_items(expected, actual),
"Expected #{ expected.inspect } and #{ actual.inspect } to have the same items"
end

def refute_same_items(expected, actual)
refute same_items(expected, actual),
"Expected #{ expected.inspect } and #{ actual.inspect } would not have the same items"
end

private

def same_items(expected, actual)
actual.is_a?(Enumerable) && expected.is_a?(Enumerable) &&
expected.count == actual.count && actual.all? { |e| expected.include?(e) }
end
end