Permalink
Browse files

Added an admin "Send Reminder" action that is tested to the hilt. Cre…

…ated a few named_scopes for Rsvp that Rsvp.attendees now uses.
  • Loading branch information...
1 parent 4299616 commit df6bfc89ff17d866fd4dfe41a30199f57afdf422 @metaskills committed Oct 1, 2009
@@ -63,6 +63,13 @@ def toggle_reservation
render :action => 'mine'
end
+ def send_reminders
+ reminded = Rsvp.send_reminders
+ reminded_notice = reminded.map { |rsvp| "#{rsvp.name} at #{rsvp.email}" }
+ flash[:good] = "Sent reminders out to the following: #{reminded_notice.to_sentence}"
+ redirect_to rsvps_url
+ end
+
protected
View
@@ -3,6 +3,9 @@ class Rsvp < ActiveRecord::Base
MAX_SEATS = 55
ATTENDEE_RANGE = (1..5).to_a.freeze
+ named_scope :reserved, :conditions => {:reserved => true}
+ named_scope :not_reserved, :conditions => {:reserved => false}
+
validates_presence_of :name, :email, :slug
serialize :attendee_names, Array
@@ -15,13 +18,17 @@ class Rsvp < ActiveRecord::Base
class << self
def attendees
- sum :attendees, :conditions => {:reserved => true}
+ reserved.sum(:attendees)
end
def open_seats?
attendees < MAX_SEATS
end
+ def send_reminders
+ not_reserved.all.each(&:send_reminder)
+ end
+
end
@@ -47,6 +54,10 @@ def attendee_names=(names)
self[:attendee_names] = scrubbed_names
end
+ def send_reminder
+ RsvpMailer.deliver_reminder(self) unless reserved?
+ end
+
protected
@@ -3,12 +3,22 @@ class RsvpMailer < ActionMailer::Base
FROM = 'info@757studio.org'
def reservation(rsvp)
- subject '757Studio Reservation Confirmation'
+ subject '757 Studio Reservation Confirmation'
+ assign_common_attributes(rsvp)
+ end
+
+ def reminder(rsvp)
+ subject '757 Studio Reservation Reminder'
+ assign_common_attributes(rsvp)
+ end
+
+
+ protected
+
+ def assign_common_attributes(rsvp)
from FROM
recipients rsvp.email
body :rsvp => rsvp
end
-
-
end
@@ -0,0 +1,10 @@
+
+757 Studio Attendee,
+
+We have noticed that you RSVP'ed but have not yet reserved your seat.
+
+<%= mine_rsvp_url(:id =>@rsvp.slug) %>
+
+Use the link above to confirm your reservation and edit your number of attendees and their names. If needed you will also be able to cancel your reservation. Seating is limited, so please let us know if your reservation changes.
+
+
@@ -1,5 +1,5 @@
-757Studio Attendee,
+757 Studio Attendee,
To guarantee your seat, please confirm your registration using the following link:
@@ -1,4 +1,8 @@
+
+%div{:class => 'floatr'}
+ = button_to 'Send Reminders', send_reminders_rsvps_path
+
%h1 RSVPs
%ul
View
@@ -3,6 +3,9 @@
map.root :controller => 'site'
map.resources :rsvps,
+ :collection => {
+ :send_reminders => :post
+ },
:member => {
:clear => :put,
:mine => [:get,:put],
@@ -30,6 +30,33 @@ class RsvpMailerTest < ActionMailer::TestCase
end
+ context 'For #reminder' do
+
+ should 'allow each instance of Rsvp to send a reminder if NOT reserved with correct content' do
+ rsvp = rsvps(:simple)
+ assert !rsvp.reserved?
+ assert_emails(1) { rsvp.send_reminder }
+ email = deliveries.first
+ assert_equal rsvp.email, email.to.first
+ assert_equal RsvpMailer::FROM, email.from.first
+ assert_match %r|Reservation Reminder|, email.subject
+ assert_match %r|http:\/\/757studio.org/rsvps/#{rsvp.slug}/mine|m, email.body
+ end
+
+ should 'not allow each instance of Rsvp to send a reminder if it IS reserved' do
+ rsvp = rsvps(:big)
+ assert rsvp.reserved?
+ assert_no_emails { rsvp.send_reminder }
+ end
+
+ should 'have a class method that send email to all unreserved RSVPs with correct content' do
+ total_count = Rsvp.not_reserved.count
+ assert_emails(total_count) { Rsvp.send_reminders }
+ end
+
+ end
+
+
protected
@@ -19,6 +19,10 @@ class RsvpTest < ActiveSupport::TestCase
assert !Rsvp.open_seats?
assert !Rsvp.new.open_seats?, 'should delegate to class'
end
+
+ should 'return all reminded recipients from send_reminders' do
+ assert_equal [rsvps(:simple)], Rsvp.send_reminders
+ end
end

0 comments on commit df6bfc8

Please sign in to comment.