VRFS-2072 copy all 1-time cancellations instead of just the first

This commit is contained in:
Brian Smith 2014-08-24 15:12:38 -04:00
parent 6144cda136
commit 82090f5f55
2 changed files with 24 additions and 3 deletions

View File

@ -140,7 +140,7 @@ module JamRuby
# if this slot was not chosen, try to get any RSVPs that were 1-time cancellations and copy those
else
rejected_req_slots = RsvpRequestRsvpSlot.where("chosen != true AND rsvp_slot_id = ?", slot.id).order("created_at ASC")
rejected_req_slots = RsvpRequestRsvpSlot.where("(chosen is null OR chosen = FALSE) AND rsvp_slot_id = ?", slot.id).order("created_at ASC")
rejected_req_slots.each do |req_slot|
# get RsvpRequest corresponding to this RsvpRequestRsvpSlot
rsvp = RsvpRequest.find_by_id(req_slot.rsvp_request_id)
@ -157,7 +157,6 @@ module JamRuby
# .last => new_slot above
new_session.rsvp_slots.last.rsvp_requests_rsvp_slots << new_rsvp_req_slot
break
end
end
end

View File

@ -81,6 +81,8 @@ describe "MusicSessionScheduler" do
responder1 = FactoryGirl.create(:user)
responder2 = FactoryGirl.create(:user)
responder3 = FactoryGirl.create(:user)
responder4 = FactoryGirl.create(:user)
responder5 = FactoryGirl.create(:user)
music_session = FactoryGirl.create(:music_session, :creator => creator)
@ -92,11 +94,14 @@ describe "MusicSessionScheduler" do
slot1 = FactoryGirl.create(:rsvp_slot, :music_session => music_session, :instrument => JamRuby::Instrument.find('electric guitar'))
slot2 = FactoryGirl.create(:rsvp_slot, :music_session => music_session, :instrument => JamRuby::Instrument.find('drums'))
slot3 = FactoryGirl.create(:rsvp_slot, :music_session => music_session, :instrument => JamRuby::Instrument.find('bass guitar'))
slot4 = FactoryGirl.create(:rsvp_slot, :music_session => music_session, :instrument => JamRuby::Instrument.find('computer'))
# create RSVPs
rsvp1 = RsvpRequest.create({:session_id => music_session.id, :rsvp_slots => [slot1.id, slot2.id]}, responder1)
rsvp2 = RsvpRequest.create({:session_id => music_session.id, :rsvp_slots => [slot2.id]}, responder2)
rsvp3 = RsvpRequest.create({:session_id => music_session.id, :rsvp_slots => [slot3.id]}, responder3)
rsvp4 = RsvpRequest.create({:session_id => music_session.id, :rsvp_slots => [slot4.id]}, responder4)
rsvp5 = RsvpRequest.create({:session_id => music_session.id, :rsvp_slots => [slot4.id]}, responder5)
# approve RSVPs
rs1 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp1.id, slot1.id)
@ -113,6 +118,14 @@ describe "MusicSessionScheduler" do
# cancel RSVP for all future sessions
RsvpRequest.cancel({:id => rsvp3.id, :session_id => music_session.id, :cancelled => "all"}, creator)
# cancel slot 4 for responder 4
rs4 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp4.id, slot4.id)
RsvpRequest.cancel({:id => rsvp4.id, :session_id => music_session.id, :cancelled => "yes"}, responder4)
# cancel slot 4 for responder 5
rs5 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp5.id, slot4.id)
RsvpRequest.cancel({:id => rsvp5.id, :session_id => music_session.id, :cancelled => "yes"}, responder5)
# copy the session and its details
new_session = music_session.copy
@ -141,10 +154,13 @@ describe "MusicSessionScheduler" do
s1 = RsvpSlot.where(:instrument_id => 'electric guitar').order("created_at ASC").last
s2 = RsvpSlot.where(:instrument_id => 'drums').order("created_at ASC").last
s3 = RsvpSlot.where(:instrument_id => 'bass guitar').order("created_at ASC").last
s4 = RsvpSlot.where(:instrument_id => 'computer').order("created_at ASC").last
r1 = RsvpRequest.where(:user_id => responder1.id).order("created_at ASC").last
r2 = RsvpRequest.where(:user_id => responder2.id).order("created_at ASC").last
r3 = RsvpRequest.where(:user_id => responder3.id).order("created_at ASC").last
r4 = RsvpRequest.where(:user_id => responder4.id).order("created_at ASC").last
r5 = RsvpRequest.where(:user_id => responder5.id).order("created_at ASC").last
# user 1
RsvpRequestRsvpSlot.where(:rsvp_request_id => r1.id, :rsvp_slot_id => s1.id).count.should == 1 # approved
@ -156,8 +172,14 @@ describe "MusicSessionScheduler" do
# user 3
RsvpRequestRsvpSlot.where(:rsvp_request_id => r3.id, :rsvp_slot_id => s3.id).count.should == 0 # cancelled all future
# user 4
RsvpRequestRsvpSlot.where(:rsvp_request_id => r4.id, :rsvp_slot_id => s4.id).count.should == 1 # 1-time cancellation
# user 5
RsvpRequestRsvpSlot.where(:rsvp_request_id => r5.id, :rsvp_slot_id => s4.id).count.should == 1 # 1-time cancellation
# should copy all requests except the one that cancelled for all future sessions (3 original requests + 2 copied)
RsvpRequest.all.count.should == 5
RsvpRequest.all.count.should == 9
end
end
end