From b1f4ede9976e7ee8e8fc5b25ddaeceab58ecb2c9 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 22 Aug 2014 02:14:07 -0400 Subject: [PATCH] VRFS-2072 fix session scheduler bug where RSVP requests were not being carried forward --- ruby/lib/jam_ruby/models/music_session.rb | 14 ++- .../resque/music_session_scheduler_spec.rb | 93 +++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index c3255c586..14be15a3e 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -135,10 +135,12 @@ module JamRuby new_rsvp_req_slot.rsvp_slot = new_slot new_rsvp_req_slot.chosen = true + # .last => new_slot above + new_session.rsvp_slots.last.rsvp_requests_rsvp_slots << new_rsvp_req_slot + # 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 = false OR chosen is null) AND rsvp_slot_id = ?", slot.id).order("created_at ASC") - + rejected_req_slots = RsvpRequestRsvpSlot.where("chosen != true 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) @@ -151,7 +153,10 @@ module JamRuby new_rsvp_req_slot = RsvpRequestRsvpSlot.new new_rsvp_req_slot.rsvp_request = new_rsvp new_rsvp_req_slot.rsvp_slot = new_slot - new_rsvp_req_slot.chosen = true + new_rsvp_req_slot.chosen = nil + + # .last => new_slot above + new_session.rsvp_slots.last.rsvp_requests_rsvp_slots << new_rsvp_req_slot break end end @@ -174,8 +179,9 @@ module JamRuby # mark the next session as scheduled self.next_session_scheduled = true self.save - end + return new_session + end end def grouped_tracks diff --git a/ruby/spec/jam_ruby/resque/music_session_scheduler_spec.rb b/ruby/spec/jam_ruby/resque/music_session_scheduler_spec.rb index af872943b..c5a9b66bc 100644 --- a/ruby/spec/jam_ruby/resque/music_session_scheduler_spec.rb +++ b/ruby/spec/jam_ruby/resque/music_session_scheduler_spec.rb @@ -64,7 +64,100 @@ describe "MusicSessionScheduler" do @scheduler.run MusicSession.all.count.should == 3 + end + it "should copy all fields" do + SessionInfoComment.delete_all + Notification.delete_all + RsvpRequestRsvpSlot.delete_all + RsvpRequest.delete_all + RsvpSlot.delete_all + Invitation.delete_all + MusicSession.delete_all + User.delete_all + + # set up data + creator = FactoryGirl.create(:user) + responder1 = FactoryGirl.create(:user) + responder2 = FactoryGirl.create(:user) + responder3 = FactoryGirl.create(:user) + + music_session = FactoryGirl.create(:music_session, :creator => creator) + + # do one more delete since the MusicSession factory creates a chosen RSVP slot + RsvpRequestRsvpSlot.delete_all + RsvpRequest.delete_all + RsvpSlot.delete_all + + 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')) + + # 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) + + # approve RSVPs + rs1 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp1.id, slot1.id) + + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp1.id, slot2.id) + RsvpRequest.update({:id => rsvp1.id, :session_id => music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => false}]}, creator) + + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp2.id, slot2.id) + RsvpRequest.update({:id => rsvp1.id, :session_id => music_session.id, :rsvp_responses => [{:request_slot_id => rs2.id, :accept => true}]}, creator) + + rs3 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(rsvp3.id, slot3.id) + RsvpRequest.update({:id => rsvp3.id, :session_id => music_session.id, :rsvp_responses => [{:request_slot_id => rs3.id, :accept => true}]}, creator) + + # cancel RSVP for all future sessions + RsvpRequest.cancel({:id => rsvp3.id, :session_id => music_session.id, :cancelled => "all"}, creator) + + # copy the session and its details + new_session = music_session.copy + + # verify session fields + new_session.description.should == music_session.description + new_session.user_id.should == music_session.user_id + new_session.band_id.should == music_session.band_id + new_session.fan_access.should == music_session.fan_access + new_session.scheduled_start.should == music_session.scheduled_start + 1.week + new_session.scheduled_duration.should == music_session.scheduled_duration + new_session.musician_access.should == music_session.musician_access + new_session.approval_required.should == music_session.approval_required + new_session.fan_chat.should == music_session.fan_chat + new_session.genre_id.should == music_session.genre_id + new_session.legal_policy.should == music_session.legal_policy + new_session.language.should == music_session.language + new_session.name.should == music_session.name + new_session.recurring_mode.should == music_session.recurring_mode + new_session.timezone.should == music_session.timezone + new_session.open_rsvps.should == music_session.open_rsvps + new_session.is_unstructured_rsvp.should == music_session.is_unstructured_rsvp + new_session.legal_terms.should == music_session.legal_terms + + # verify rsvp details (slots, rsvp requests, etc.) + new_session.rsvp_slots.count.should == music_session.rsvp_slots.count + 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 + + 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 + + # user 1 + RsvpRequestRsvpSlot.where(:rsvp_request_id => r1.id, :rsvp_slot_id => s1.id).count.should == 1 # approved + RsvpRequestRsvpSlot.where(:rsvp_request_id => r1.id, :rsvp_slot_id => s2.id).count.should == 0 # declined + + # user 2 + RsvpRequestRsvpSlot.where(:rsvp_request_id => r2.id, :rsvp_slot_id => s2.id).count.should == 1 # approved + + # user 3 + RsvpRequestRsvpSlot.where(:rsvp_request_id => r3.id, :rsvp_slot_id => s3.id).count.should == 0 # cancelled all future + + # should copy all requests except the one that cancelled for all future sessions (3 original requests + 2 copied) + RsvpRequest.all.count.should == 5 end end end \ No newline at end of file