added ability to retrieve RSVP requests by approval status
This commit is contained in:
parent
69ed727775
commit
75b22ced5b
|
|
@ -7,7 +7,7 @@ module JamRuby
|
|||
|
||||
validates :canceled, :inclusion => {:in => [nil, true, false]}
|
||||
|
||||
def self.index(music_session, user = nil)
|
||||
def self.index(music_session, user=nil, options={})
|
||||
query = RsvpRequest
|
||||
.includes(:user)
|
||||
.joins(
|
||||
|
|
@ -27,6 +27,12 @@ module JamRuby
|
|||
}
|
||||
)
|
||||
|
||||
if options[:status] == 'approved'
|
||||
query = query.where("rrrs.chosen = true")
|
||||
elsif options[:status] == 'pending'
|
||||
query = query.where("rrrs.chosen is null")
|
||||
end
|
||||
|
||||
query = query.where("rsvp_requests.user_id = ?", user.id) unless user.nil?
|
||||
return query.uniq
|
||||
end
|
||||
|
|
|
|||
|
|
@ -89,8 +89,6 @@ describe RsvpRequest do
|
|||
|
||||
rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)
|
||||
|
||||
request_slots = RsvpRequestRsvpSlot.all
|
||||
|
||||
# accept 1 of the slots
|
||||
rs1 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot1.id)
|
||||
rs2 = RsvpRequestRsvpSlot.find_by_rsvp_slot_id(@slot2.id)
|
||||
|
|
@ -133,6 +131,42 @@ describe RsvpRequest do
|
|||
rsvps = RsvpRequest.index(@music_session, @non_session_invitee)
|
||||
rsvps.count.should == 1
|
||||
end
|
||||
|
||||
it "should allow retrieval of RSVps by session and approval status" do
|
||||
# allow open RSVPs
|
||||
@music_session.open_rsvps = true
|
||||
@music_session.save
|
||||
|
||||
approved_rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot1.id, @slot2.id]}, @non_session_invitee)
|
||||
|
||||
rs1 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(approved_rsvp.id, @slot1.id)
|
||||
rs2 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(approved_rsvp.id, @slot2.id)
|
||||
RsvpRequest.update({:id => approved_rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs1.id, :accept => true}, {:request_slot_id => rs2.id, :accept => false}]}, @session_creator)
|
||||
|
||||
user2 = FactoryGirl.create(:user)
|
||||
declined_rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot2.id]}, user2)
|
||||
|
||||
rs2 = RsvpRequestRsvpSlot.find_by_rsvp_request_id_and_rsvp_slot_id(declined_rsvp, @slot2.id)
|
||||
RsvpRequest.update({:id => declined_rsvp.id, :session_id => @music_session.id, :rsvp_responses => [{:request_slot_id => rs2.id, :accept => false}]}, @session_creator)
|
||||
|
||||
user3 = FactoryGirl.create(:user)
|
||||
pending_rsvp = RsvpRequest.create({:session_id => @music_session.id, :rsvp_slots => [@slot2.id]}, user3)
|
||||
|
||||
rsvps = RsvpRequest.index(@music_session, nil, {:status => "pending"})
|
||||
rsvps.count.should == 1
|
||||
|
||||
rsvps = RsvpRequest.index(@music_session, user3, {:status => "pending"})
|
||||
rsvps.count.should == 1
|
||||
|
||||
rsvps = RsvpRequest.index(@music_session, nil, {:status => "approved"})
|
||||
rsvps.count.should == 1
|
||||
|
||||
rsvps = RsvpRequest.index(@music_session, @non_session_invitee, {:status => "approved"})
|
||||
rsvps.count.should == 1
|
||||
|
||||
rsvps = RsvpRequest.index(@music_session)
|
||||
rsvps.count.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ class ApiRsvpRequestsController < ApiController
|
|||
|
||||
# retrieve all requests for this session
|
||||
if music_session.creator.id == current_user.id
|
||||
@rsvp_requests = RsvpRequest.index(music_session)
|
||||
@rsvp_requests = RsvpRequest.index(music_session, nil, params)
|
||||
|
||||
# scope the response to the current user
|
||||
else
|
||||
@rsvp_requests = RsvpRequest.index(music_session, current_user)
|
||||
@rsvp_requests = RsvpRequest.index(music_session, current_user, params)
|
||||
end
|
||||
|
||||
respond_with @rsvp_requests, responder: ApiResponder, :status => 200
|
||||
|
|
|
|||
Loading…
Reference in New Issue