From 02a0ea12aca8a738018d2cbdf59308bb34167a8c Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 7 Jun 2014 13:19:02 -0400 Subject: [PATCH] VRFS-1749 RsvpRequest model tests wip --- ruby/spec/factories.rb | 2 +- .../spec/jam_ruby/models/rsvp_request_spec.rb | 63 +++++++++++++------ 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/ruby/spec/factories.rb b/ruby/spec/factories.rb index 4498ee90c..99efdfc49 100644 --- a/ruby/spec/factories.rb +++ b/ruby/spec/factories.rb @@ -93,7 +93,7 @@ FactoryGirl.define do recurring_mode 'once' genre JamRuby::Genre.first association :creator, :factory => :user - open_rsvps true + open_rsvps false factory :recurring_music_session_weekly do recurring_mode 'weekly' diff --git a/ruby/spec/jam_ruby/models/rsvp_request_spec.rb b/ruby/spec/jam_ruby/models/rsvp_request_spec.rb index 8d84b7c8b..e8a78efd1 100644 --- a/ruby/spec/jam_ruby/models/rsvp_request_spec.rb +++ b/ruby/spec/jam_ruby/models/rsvp_request_spec.rb @@ -34,15 +34,6 @@ describe RsvpRequest do describe "create" do it "should require a valid music session" do - # u = FactoryGirl.create(:user) - # r = FactoryGirl.create(:user) - # s = FactoryGirl.create(:music_session) - # invitation = Invitation.new(:sender => u, :receiver => r, :music_session => s) - # invitation.save - - # x = Invitation.all - # puts x.count - expect {RsvpRequest.create({:session_id => "1234", :rsvp_slots => [@slot1.id, @slot2.id]}, @session_invitee)}.to raise_error(JamRuby::StateError) end @@ -51,11 +42,32 @@ describe RsvpRequest do end it "should not allow user to RSVP for slot he has already RSVPed to" do + # allow open RSVPs + @music_session.open_rsvps = true + @music_session.save + + RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee) + expect {RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)}.to raise_error(JamRuby::StateError) + 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) + + # verify comment + + # verify 2 notifications were created end it "should allow non-invitee to RSVP to session with open RSVPs" do + # allow open RSVPs + @music_session.open_rsvps = true + @music_session.save + + expect {RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)}.to_not raise_error # verify notification was created + n = Notification.find_by_source_user_id(@non_session_invitee.id) + n.description.should == NotificationTypes::SCHEDULED_SESSION_RSVP end it "should not allow user to RSVP to slot that has already been accepted" do @@ -77,26 +89,37 @@ describe RsvpRequest do end it "should not allow non-invitee to RSVP to session with closed RSVPs" do - @music_session.open_rsvps = false - @music_session.save - expect {RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)}.to raise_error(JamRuby::PermissionError) 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) - - # verify comment - - # verify 2 notification were created - end end describe "index" do it "should allow retrieval of RSVPs by session" do + # allow open RSVPs + @music_session.open_rsvps = true + @music_session.save + + 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) + + rsvps = RsvpRequest.index(@music_session) + rsvps.count.should == 2 end it "should allow retrieval of RSVPs by session and user" do + # allow open RSVPs + @music_session.open_rsvps = true + @music_session.save + + 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) + + rsvps = RsvpRequest.index(@music_session, @non_session_invitee) + rsvps.count.should == 1 end end