Permalink
Browse files

Create a reminder email system that is manually triggered by the RSVP…

…s admin.
  • Loading branch information...
1 parent d34238b commit e1ecbe35f1b89b4f2339df132c3698a4e01799e5 @metaskills committed Nov 2, 2009
@@ -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
View
@@ -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
View
@@ -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
@@ -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 -%>
+
@@ -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
View
@@ -4,7 +4,8 @@
map.resources :rsvps,
:collection => {
- :send_reminders => :post
+ :send_reminders => :post,
+ :send_upcoming_reminders => :post
},
:member => {
:clear => :put,
@@ -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

0 comments on commit e1ecbe3

Please sign in to comment.