VRFS-1749 finished RsvpRequest model tests

This commit is contained in:
Brian Smith 2014-06-10 00:35:38 -04:00
parent 11c7f87fa1
commit 0fe76dae13
3 changed files with 143 additions and 15 deletions

View File

@ -886,6 +886,7 @@ module JamRuby
rsvp_requests = RsvpRequest.index(music_session) rsvp_requests = RsvpRequest.index(music_session)
target_users = rsvp_requests.map { |r| r.user } target_users = rsvp_requests.map { |r| r.user }
target_users = target_users.concat([music_session.creator])
pending_invites = music_session.pending_invitations pending_invites = music_session.pending_invitations
# remove the creator from the array # remove the creator from the array

View File

@ -105,10 +105,10 @@ module JamRuby
session_info_comment.user = user session_info_comment.user = user
session_info_comment.comment = params[:message] session_info_comment.comment = params[:message]
session_info_comment.save session_info_comment.save
Notification.send_scheduled_session_comment(music_session, user, params[:message])
end end
Notification.send_scheduled_session_rsvp(music_session, user, instruments) Notification.send_scheduled_session_rsvp(music_session, user, instruments)
Notification.send_scheduled_session_comment(music_session, user, params[:message])
@rsvp @rsvp
end end
@ -239,9 +239,8 @@ module JamRuby
session_info_comment.user = user session_info_comment.user = user
session_info_comment.comment = params[:message] session_info_comment.comment = params[:message]
session_info_comment.save session_info_comment.save
Notification.send_scheduled_session_comment(music_session, user, params[:message])
end end
Notification.send_scheduled_session_comment(music_session, user, params[:message])
end end
end end
end end

View File

@ -3,6 +3,8 @@ require 'spec_helper'
describe RsvpRequest do describe RsvpRequest do
before(:each) do before(:each) do
SessionInfoComment.delete_all
Notification.delete_all
RsvpRequestRsvpSlot.delete_all RsvpRequestRsvpSlot.delete_all
RsvpRequest.delete_all RsvpRequest.delete_all
RsvpSlot.delete_all RsvpSlot.delete_all
@ -55,11 +57,17 @@ describe RsvpRequest do
end end
it "should allow invitee to RSVP to session with closed RSVPs" do 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 # 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 end
it "should allow non-invitee to RSVP to session with open RSVPs" do it "should allow non-invitee to RSVP to session with open RSVPs" do
@ -106,7 +114,7 @@ describe RsvpRequest do
user2 = FactoryGirl.create(:user) 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, @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 = RsvpRequest.index(@music_session)
rsvps.count.should == 2 rsvps.count.should == 2
@ -120,7 +128,7 @@ describe RsvpRequest do
user2 = FactoryGirl.create(:user) 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, @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 = RsvpRequest.index(@music_session, @non_session_invitee)
rsvps.count.should == 1 rsvps.count.should == 1
@ -129,35 +137,155 @@ describe RsvpRequest do
describe "update" do describe "update" do
it "should only allow session organizer to approve request" 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 # 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 # 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 # verify notification was created
n = Notification.find_by_source_user_id(@session_creator.id)
n.description.should == NotificationTypes::SCHEDULED_SESSION_RSVP_APPROVED
end end
it "should not allow approval of RSVP for a slot that has already been approved" do 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
end end
describe "cancel" do 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 end
it "should allow RSVP creator to cancel" do it "should allow session organizer to cancel an RSVP for all future sessions" do
# test comment 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 end
it "should not allow anyone else to cancel" do it "should not allow anyone else to cancel" do
end user = FactoryGirl.create(:user)
it "should allow user to cancel a single session" do rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id], :message => "Let's Jam!"}, @session_invitee)
end
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 end
end end