Skip to content

Commit

Permalink
Create a reminder email system that is manually triggered by the RSVP…
Browse files Browse the repository at this point in the history
…s admin.
  • Loading branch information
metaskills committed Nov 2, 2009
1 parent d34238b commit e1ecbe3
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/controllers/rsvps_controller.rb
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion 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

Expand Down Expand Up @@ -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


Expand Down
16 changes: 15 additions & 1 deletion app/models/rsvp_mailer.rb
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -25,5 +38,6 @@ def assign_common_attributes(rsvp)
recipients rsvp.email
body :rsvp => rsvp
end



end
17 changes: 17 additions & 0 deletions 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 -%>

5 changes: 3 additions & 2 deletions 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

Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -4,7 +4,8 @@

map.resources :rsvps,
:collection => {
:send_reminders => :post
:send_reminders => :post,
:send_upcoming_reminders => :post
},
:member => {
:clear => :put,
Expand Down
27 changes: 27 additions & 0 deletions test/unit/rsvp_mailer_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit e1ecbe3

Please sign in to comment.