From e1ecbe35f1b89b4f2339df132c3698a4e01799e5 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 2 Nov 2009 09:17:40 -0500 Subject: [PATCH] Create a reminder email system that is manually triggered by the RSVPs admin. --- app/controllers/rsvps_controller.rb | 6 +++++ app/models/rsvp.rb | 10 ++++++- app/models/rsvp_mailer.rb | 16 ++++++++++- .../upcoming_event_reminder.text.plain.erb | 17 ++++++++++++ app/views/rsvps/index.html.haml | 5 ++-- config/routes.rb | 3 ++- test/unit/rsvp_mailer_test.rb | 27 +++++++++++++++++++ 7 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 app/views/rsvp_mailer/upcoming_event_reminder.text.plain.erb diff --git a/app/controllers/rsvps_controller.rb b/app/controllers/rsvps_controller.rb index 24dbe00..c62fcc4 100644 --- a/app/controllers/rsvps_controller.rb +++ b/app/controllers/rsvps_controller.rb @@ -70,6 +70,12 @@ def send_reminders redirect_to rsvps_url end + def send_upcoming_reminders + RsvpMailer.deliver_upcoming_event_reminders + flash[:good] = "Sent upcoming event reminders to #{Rsvp.count} people." + redirect_to rsvps_url + end + protected diff --git a/app/models/rsvp.rb b/app/models/rsvp.rb index 2aff25d..1666766 100644 --- a/app/models/rsvp.rb +++ b/app/models/rsvp.rb @@ -1,7 +1,7 @@ class Rsvp < ActiveRecord::Base extend ActiveSupport::Memoizable - + MAX_SEATS = 50 ATTENDEE_RANGE = (1..5).to_a.freeze @@ -36,6 +36,14 @@ def send_open_seats(exception=nil) open_seats? ? not_reserved.all.reject{ |r| r == exception }.each{ |r| r.send_open_seat(true) } : [] end + def event_date + Date.parse('2009-11-05') + end + + def event_today? + event_date == Date.today + end + end diff --git a/app/models/rsvp_mailer.rb b/app/models/rsvp_mailer.rb index 8f748bb..f49743d 100644 --- a/app/models/rsvp_mailer.rb +++ b/app/models/rsvp_mailer.rb @@ -2,6 +2,14 @@ class RsvpMailer < ActionMailer::Base FROM = 'info@757studio.org' + class << self + + def deliver_upcoming_event_reminders + Rsvp.all.each { |rsvp| self.deliver_upcoming_event_reminder(rsvp) } + end + + end + def reservation(rsvp) subject '757 Studio Reservation Confirmation' assign_common_attributes(rsvp) @@ -17,6 +25,11 @@ def open_seat(rsvp) assign_common_attributes(rsvp) end + def upcoming_event_reminder(rsvp) + subject "757 Studio [#{rsvp.reserved? ? 'RESERVED' : 'WAITING'}]" + assign_common_attributes(rsvp) + end + protected @@ -25,5 +38,6 @@ def assign_common_attributes(rsvp) recipients rsvp.email body :rsvp => rsvp end - + + end diff --git a/app/views/rsvp_mailer/upcoming_event_reminder.text.plain.erb b/app/views/rsvp_mailer/upcoming_event_reminder.text.plain.erb new file mode 100644 index 0000000..79e5220 --- /dev/null +++ b/app/views/rsvp_mailer/upcoming_event_reminder.text.plain.erb @@ -0,0 +1,17 @@ + +757 Studio Attendee, + +<%- if Rsvp.event_today? -%> +Today is the day! +<%- else -%> +The event is only <%= (Rsvp.event_date-Date.today).days.inspect %> away! +<%- end -%> + +<%- if @rsvp.reserved? -%> +<%= mine_rsvp_url(:id =>@rsvp.slug) %> + +From this page, you will be able to edit your number of attendees and their names. If needed you will also be able to cancel your reservation with this link. Seating is limited, so please let us know if your reservation changes. +<%- else -%> +Seats are currently filled and you are on the waiting list. But when and if anyone cancels their reservation, you will receive an email with a chance to claim their seat. +<%- end -%> + diff --git a/app/views/rsvps/index.html.haml b/app/views/rsvps/index.html.haml index dd06e77..8d67420 100644 --- a/app/views/rsvps/index.html.haml +++ b/app/views/rsvps/index.html.haml @@ -1,7 +1,8 @@ -%div{:class => 'floatr'} - = button_to 'Send Reminders', send_reminders_rsvps_path +%div{:class => 'floatr right'} + = button_to 'Send Rsvp Reminders', send_reminders_rsvps_path + = button_to 'Send Upcoming Reminders', send_upcoming_reminders_rsvps_path %h1 RSVPs diff --git a/config/routes.rb b/config/routes.rb index d0b514d..7c67a2f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,8 @@ map.resources :rsvps, :collection => { - :send_reminders => :post + :send_reminders => :post, + :send_upcoming_reminders => :post }, :member => { :clear => :put, diff --git a/test/unit/rsvp_mailer_test.rb b/test/unit/rsvp_mailer_test.rb index 9faf94e..bc06d82 100644 --- a/test/unit/rsvp_mailer_test.rb +++ b/test/unit/rsvp_mailer_test.rb @@ -111,6 +111,33 @@ class RsvpMailerTest < ActionMailer::TestCase end + context 'For #upcoming_event_reminder' do + + should 'send emails to all Rsvps with different body content depending on their current state' do + Rsvp.stubs :event_date => Date.today+3.days + RsvpMailer.deliver_upcoming_event_reminders + assert_equal Rsvp.count, deliveries.size + # Unreserved Email + assert email_for_simple = deliveries.detect { |email| rsvps(:simple).email == email.to.first } + assert_match %r|WAITING|, email_for_simple.subject + assert_match %r|The event is only 3 days|, email_for_simple.body + assert_match %r|you are on the waiting list|, email_for_simple.body + # Reserved Email + assert email_for_big = deliveries.detect { |email| rsvps(:big).email == email.to.first } + assert_match %r|RESERVED|, email_for_big.subject + assert_match %r|The event is only 3 days|, email_for_big.body + assert_match %r|please let us know if your reservation changes|, email_for_big.body + end + + should 'send email with body that says even is TODAY when it is today' do + Rsvp.stubs :event_date => Date.today + RsvpMailer.deliver_upcoming_event_reminders + assert_match %r|Today is the day!|, deliveries.first.body + end + + end + + protected