diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 54049455..4e60c36c 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -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" @@ -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 diff --git a/app/mailers/organizer_mailer.rb b/app/mailers/organizer_mailer.rb index 6364adf4..51837333 100644 --- a/app/mailers/organizer_mailer.rb +++ b/app/mailers/organizer_mailer.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 0942c24b..87d900b3 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/services/deadline_passed_mail_service.rb b/app/services/deadline_passed_mail_service.rb index 462ff4f1..06a2d0a8 100644 --- a/app/services/deadline_passed_mail_service.rb +++ b/app/services/deadline_passed_mail_service.rb @@ -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 diff --git a/app/views/organizer_mailer/approved_event.text.erb b/app/views/organizer_mailer/approved_event.text.erb deleted file mode 100644 index 82672d28..00000000 --- a/app/views/organizer_mailer/approved_event.text.erb +++ /dev/null @@ -1,11 +0,0 @@ -Dear <%= @event.organizer_name %>, - -Your event <%= @event.name %> has been approved on diversitytickets.org and is now visible to the public. You can view it here: https://diversitytickets.org/events/<%= @event.id %>. As of now, applicants can apply for diversity tickets by clicking on the "Apply" link and filling out the form. - -You have the option of receiving an email reminder to be notified when the number of submitted applications for your event has exceeded the amount of tickets you provide. In order to receive this information, please adjust your email preferences in your account settings to allow us to send you notifications: https://diversitytickets.org/users/<%= @event.organizer_id %>/edit - -If you have any more questions, please read the FAQ (https://diversitytickets.org/faq). If you need more help, contact diversityticketsorg@gmail.com. - -The Diversity Tickets Team - -- diff --git a/app/views/organizer_mailer/approved_event/application_by_organizer.text.erb b/app/views/organizer_mailer/approved_event/application_by_organizer.text.erb new file mode 100644 index 00000000..102704d2 --- /dev/null +++ b/app/views/organizer_mailer/approved_event/application_by_organizer.text.erb @@ -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 diversityticketsorg@gmail.com if you have any questions. + +Best, +The Diversity Tickets Team + +- diff --git a/app/views/organizer_mailer/approved_event/selection_by_organizer.text.erb b/app/views/organizer_mailer/approved_event/selection_by_organizer.text.erb new file mode 100644 index 00000000..f90879d6 --- /dev/null +++ b/app/views/organizer_mailer/approved_event/selection_by_organizer.text.erb @@ -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 diversityticketsorg@gmail.com if you have any questions. + +Best, +The Diversity Tickets Team + +- diff --git a/app/views/organizer_mailer/approved_event/selection_by_travis.text.erb b/app/views/organizer_mailer/approved_event/selection_by_travis.text.erb new file mode 100644 index 00000000..b9c75c58 --- /dev/null +++ b/app/views/organizer_mailer/approved_event/selection_by_travis.text.erb @@ -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 diversityticketsorg@gmail.com if you have any questions. + +Best, +The Diversity Tickets Team + +- diff --git a/app/views/organizer_mailer/passed_event_deadline.text.erb b/app/views/organizer_mailer/passed_event_deadline.text.erb new file mode 100644 index 00000000..9caff88d --- /dev/null +++ b/app/views/organizer_mailer/passed_event_deadline.text.erb @@ -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 diversitytickets.org@gmail.com if you have any questions. + +Best, +The Diversity Tickets Team + +- diff --git a/test/controllers/applications_controller_test.rb b/test/controllers/applications_controller_test.rb index e6dcc3a0..1e6d3ed6 100644 --- a/test/controllers/applications_controller_test.rb +++ b/test/controllers/applications_controller_test.rb @@ -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 @@ -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 diff --git a/test/mailers/organizer_mailer_test.rb b/test/mailers/organizer_mailer_test.rb index d70acd05..29506e1c 100644 --- a/test/mailers/organizer_mailer_test.rb +++ b/test/mailers/organizer_mailer_test.rb @@ -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 ['info@diversitytickets.org'], 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 ['info@diversitytickets.org'], 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 ['info@diversitytickets.org'], 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 ['info@diversitytickets.org'], 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 ['info@diversitytickets.org'], 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 diff --git a/test/services/deadline_passed_mail_service_test.rb b/test/services/deadline_passed_mail_service_test.rb index c1a4ca21..93450f74 100644 --- a/test/services/deadline_passed_mail_service_test.rb +++ b/test/services/deadline_passed_mail_service_test.rb @@ -1,12 +1,39 @@ 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: 'bad@example.com') - make_admin(email: 'good@example.com') + 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: 'organizer@example.com') + 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: 'user@example.com') + admin = make_admin(email: 'admin@example.com') + + 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: 'organizer@example.com') + 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: 'user@example.com') + admin = make_admin(email: 'admin@example.com') ActionMailer::Base.deliveries.clear @@ -14,22 +41,35 @@ class DeadlinePassedMailServiceTest < ActiveSupport::TestCase mails = ActionMailer::Base.deliveries assert_equal 1, mails.length - mail = mails.first - assert_equal ['good@example.com'], 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 @@ -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' @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index bab3a611..372d3dc4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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