From 0fe76dae13932c183e441c89bbce9b2e3623fa66 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Tue, 10 Jun 2014 00:35:38 -0400 Subject: [PATCH] VRFS-1749 finished RsvpRequest model tests --- ruby/lib/jam_ruby/models/notification.rb | 1 + ruby/lib/jam_ruby/models/rsvp_request.rb | 5 +- .../spec/jam_ruby/models/rsvp_request_spec.rb | 152 ++++++++++++++++-- 3 files changed, 143 insertions(+), 15 deletions(-) diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 0d3266d40..6fd14da13 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -886,6 +886,7 @@ module JamRuby rsvp_requests = RsvpRequest.index(music_session) target_users = rsvp_requests.map { |r| r.user } + target_users = target_users.concat([music_session.creator]) pending_invites = music_session.pending_invitations # remove the creator from the array diff --git a/ruby/lib/jam_ruby/models/rsvp_request.rb b/ruby/lib/jam_ruby/models/rsvp_request.rb index 1eb651bd9..2883c18b7 100644 --- a/ruby/lib/jam_ruby/models/rsvp_request.rb +++ b/ruby/lib/jam_ruby/models/rsvp_request.rb @@ -105,10 +105,10 @@ module JamRuby session_info_comment.user = user session_info_comment.comment = params[:message] session_info_comment.save + Notification.send_scheduled_session_comment(music_session, user, params[:message]) end Notification.send_scheduled_session_rsvp(music_session, user, instruments) - Notification.send_scheduled_session_comment(music_session, user, params[:message]) @rsvp end @@ -239,9 +239,8 @@ module JamRuby session_info_comment.user = user session_info_comment.comment = params[:message] session_info_comment.save + Notification.send_scheduled_session_comment(music_session, user, params[:message]) end - - Notification.send_scheduled_session_comment(music_session, user, params[:message]) end end end diff --git a/ruby/spec/jam_ruby/models/rsvp_request_spec.rb b/ruby/spec/jam_ruby/models/rsvp_request_spec.rb index 551b53f0e..ca186a344 100644 --- a/ruby/spec/jam_ruby/models/rsvp_request_spec.rb +++ b/ruby/spec/jam_ruby/models/rsvp_request_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe RsvpRequest do before(:each) do + SessionInfoComment.delete_all + Notification.delete_all RsvpRequestRsvpSlot.delete_all RsvpRequest.delete_all RsvpSlot.delete_all @@ -55,11 +57,17 @@ describe RsvpRequest do end it "should allow invitee to RSVP to session with closed RSVPs" do - rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "We be jammin!"}, @session_invitee) # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "We be jammin!" - # verify 2 notifications were created + # verify 2 notifications were created for this music session (1 for RSVP and 1 for comment) + notifications = Notification.where(:session_id => @music_session.id) + notifications.count.should == 2 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_COMMENT).count.should == 1 end it "should allow non-invitee to RSVP to session with open RSVPs" do @@ -106,7 +114,7 @@ describe RsvpRequest do user2 = FactoryGirl.create(:user) RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @non_session_invitee) - RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id], :message => "Let's Jam!"}, user2) + RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id], :message => "Let's Jam 2!"}, user2) rsvps = RsvpRequest.index(@music_session) rsvps.count.should == 2 @@ -120,7 +128,7 @@ describe RsvpRequest do user2 = FactoryGirl.create(:user) RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @non_session_invitee) - RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id], :message => "Let's Jam!"}, user2) + RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id], :message => "Let's Jam 2!"}, user2) rsvps = RsvpRequest.index(@music_session, @non_session_invitee) rsvps.count.should == 1 @@ -129,35 +137,155 @@ describe RsvpRequest do describe "update" do it "should only allow session organizer to approve request" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + # attempt to approve with non-organizer + rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id) + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id) + expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_invitee)}.to raise_error(PermissionError) # approve with organizer + rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id) + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id) + expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_creator)}.to_not raise_error # verify notification was created + n = Notification.find_by_source_user_id(@session_creator.id) + n.description.should == NotificationTypes::SCHEDULED_SESSION_RSVP_APPROVED end it "should not allow approval of RSVP for a slot that has already been approved" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + + # approve + rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id) + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id) + expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_creator)}.to_not raise_error + + # approve again + rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id) + rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id) + expect {RsvpRequest.update({:id => rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => true}]}, @session_creator)}.to raise_error(StateError) end end describe "cancel" do - it "should allow session organizer to cancel" do + it "should allow session organizer to cancel an RSVP to a single session" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Let's Jam!" + + # cancel + expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "yes", :message => "Sorry, you're booted for this session"}, @session_creator)}.to_not raise_error + + rsvp = RsvpRequest.find_by_id(rsvp.id) + rsvp.canceled.should == true + rsvp.cancel_all.should == false + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_creator) + comment.comment.should == "Sorry, you're booted for this session" + + # verify 4 notifications were created for this music session (1 for RSVP, 1 for cancellation, and 2 for comments) + notifications = Notification.where(:session_id => @music_session.id) + notifications.count.should == 4 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP_CANCELLED_ORG).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_COMMENT).count.should == 2 end - it "should allow RSVP creator to cancel" do - # test comment + it "should allow session organizer to cancel an RSVP for all future sessions" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) - # verify notification was created + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Let's Jam!" + + # cancel + expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "all", :message => "Sorry, you're booted for this session"}, @session_creator)}.to_not raise_error + + rsvp = RsvpRequest.find_by_id(rsvp.id) + rsvp.canceled.should == true + rsvp.cancel_all.should == true + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_creator) + comment.comment.should == "Sorry, you're booted for this session" + + # verify 4 notifications were created for this music session (1 for RSVP, 1 for cancellation, and 2 for comments) + notifications = Notification.where(:session_id => @music_session.id) + notifications.count.should == 4 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP_CANCELLED_ORG).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_COMMENT).count.should == 2 + end + + it "should allow RSVP creator to cancel an RSVP to a single session" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Let's Jam!" + + # cancel + expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "yes", :message => "Sorry, I'm bailing for this session"}, @session_invitee)}.to_not raise_error + + rsvp = RsvpRequest.find_by_id(rsvp.id) + rsvp.canceled.should == true + rsvp.cancel_all.should == false + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Sorry, I'm bailing for this session" + + # verify 4 notifications were created for this music session (1 for RSVP, 1 for cancellation, and 2 for comments) + notifications = Notification.where(:session_id => @music_session.id) + notifications.count.should == 4 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP_CANCELLED).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_COMMENT).count.should == 2 + end + + it "should allow RSVP creator to cancel an RSVP for all future sessions" do + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Let's Jam!" + + # cancel + expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "all", :message => "Sorry, I'm bailing for all sessions"}, @session_invitee)}.to_not raise_error + + rsvp = RsvpRequest.find_by_id(rsvp.id) + rsvp.canceled.should == true + rsvp.cancel_all.should == true + + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Sorry, I'm bailing for all sessions" + + # verify 4 notifications were created for this music session (1 for RSVP, 1 for cancellation, and 2 for comments) + notifications = Notification.where(:session_id => @music_session.id) + notifications.count.should == 4 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_RSVP_CANCELLED).count.should == 1 + notifications.where(:description => NotificationTypes::SCHEDULED_SESSION_COMMENT).count.should == 2 end it "should not allow anyone else to cancel" do - end + user = FactoryGirl.create(:user) - it "should allow user to cancel a single session" do - end + rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee) - it "should allow user to cancel all future sessions" do + # verify comment + comment = SessionInfoComment.find_by_creator_id(@session_invitee) + comment.comment.should == "Let's Jam!" + + # cancel + expect {RsvpRequest.cancel({:id => rsvp.id, :session_id => @music_session.id, :cancelled => "all", :message => "I'm gonna cancel all your RSVPs"}, user)}.to raise_error(PermissionError) end end end \ No newline at end of file