VRFS-1749 RsvpRequest model tests wip

This commit is contained in:
Brian Smith 2014-06-07 13:19:02 -04:00
parent a09326470e
commit 02a0ea12ac
2 changed files with 44 additions and 21 deletions

View File

@ -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'

View File

@ -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