Permalink
Browse files

Unit test the Rsvp state changes and validations while under max seat…

…s. Fixed bug which now allows attendees to update non-reserved attributes under this use case.
  • Loading branch information...
metaskills committed Oct 2, 2009
1 parent 1cfa60c commit ceed398f1f47dab62ad657e85abde0c36feb020e
Showing with 36 additions and 7 deletions.
  1. +7 −1 app/models/rsvp.rb
  2. +29 −6 test/unit/rsvp_test.rb
View
@@ -62,7 +62,13 @@ def send_reminder
protected
def validate
- errors.add :reservation, 'can not be confirmed because all seats are currently taken' if reserved? && !open_seats?
+ validate_new_reserved_state
+ end
+
+ def validate_new_reserved_state
+ if reserved_changed? && reserved?
+ errors.add :reservation, 'can not be confirmed because all seats are currently taken' unless open_seats?
+ end
end
def default_attendee_names
View
@@ -58,12 +58,35 @@ class RsvpTest < ActiveSupport::TestCase
assert @rsvp.reload.reserved?
end
- should 'be able to create new unreserved rsvps when open_seats? returns false' do
- reserve_all_seats!
- assert_nothing_raised() { @rsvp.save! }
- @rsvp.toggle(:reserved)
- assert_raise(ActiveRecord::RecordInvalid) { @rsvp.save! }
- assert @rsvp.errors.on(:reservation)
+ context 'when all seats are reserved' do
+
+ setup do
+ reserve_all_seats!
+ end
+
+ should 'be able to create new unreserved rsvps' do
+ assert !@rsvp.reserved?
+ assert_nothing_raised() { @rsvp.save! }
+ end
+
+ should 'be allowed to edit non-reserved attributes' do
+ rsvp = rsvps(:big)
+ assert rsvp.reserved?
+ rsvp.email = 'newbig@megacorp.com'
+ rsvp.attendee_names = ['Mr One','Mr Two','Mr Three']
+ assert rsvp.save
+ end
+
+ should 'not be allowed to change rsvp state to reserved' do
+ rsvp = rsvps(:simple)
+ assert !rsvp.reserved?
+ assert_raise(ActiveRecord::RecordInvalid) do
+ rsvp.toggle(:reserved)
+ rsvp.save!
+ end
+ assert rsvp.errors.on(:reservation)
+ end
+
end
context 'attendees & serialized attendee_names' do

0 comments on commit ceed398

Please sign in to comment.