Merge branch 'feature/sched_sessions_rsvps' into feature/scheduled_sessions

This commit is contained in:
Brian Smith 2014-05-22 00:42:50 -04:00
commit b4f7035fed
19 changed files with 501 additions and 256 deletions

View File

@ -157,4 +157,6 @@ notification_scheduled_session.sql
music_notation.sql
music_session_recurring_mode.sql
add_timezone_music_session.sql
scheduled_sessions_2.sql
scheduled_sessions_2.sql
scheduled_sessions_3.sql
scheduled_sessions_cancel_all.sql

View File

@ -0,0 +1 @@
alter table rsvp_requests_rsvp_slots alter column chosen set DEFAULT NULL;

View File

@ -0,0 +1 @@
alter table rsvp_requests add column cancel_all BOOLEAN DEFAULT FALSE;

View File

@ -592,25 +592,23 @@ module JamRuby
notification_msg = format_msg(notification.description, {:user => source_user, :session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_invitation(
target_user.id,
music_session.id,
source_user.photo_url,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_invitation(
target_user.id,
music_session.id,
source_user.photo_url,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_invitation(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_invitation email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_invitation(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_invitation email to offline user #{target_user.email} #{e}")
end
end
@ -630,31 +628,28 @@ module JamRuby
notification_msg = format_msg(notification.description, {:user => source_user, :session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_rsvp(
target_user.id,
music_session.id,
source_user.photo_url,
notification_msg,
source_user.id,
instruments,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_rsvp(
target_user.id,
music_session.id,
source_user.photo_url,
notification_msg,
source_user.id,
instruments.join('|'),
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_rsvp(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_rsvp(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp email to offline user #{target_user.email} #{e}")
end
end
def send_scheduled_session_rsvp_approved(music_session, user)
def send_scheduled_session_rsvp_approved(music_session, user, instruments)
return if music_session.nil? || user.nil?
@ -670,24 +665,21 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_rsvp_approved(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_rsvp_approved(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_rsvp_approved(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp_approved email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_rsvp_approved(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp_approved email to offline user #{target_user.email} #{e}")
end
end
@ -707,24 +699,22 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_rsvp_cancelled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_rsvp_cancelled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.send_scheduled_session_rsvp_cancelled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send send_scheduled_session_rsvp_cancelled email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.send_scheduled_session_rsvp_cancelled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send send_scheduled_session_rsvp_cancelled email to offline user #{target_user.email} #{e}")
end
end
@ -744,24 +734,22 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_rsvp_cancelled_org(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_rsvp_cancelled_org(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_rsvp_cancelled_org(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp_cancelled_org email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_rsvp_cancelled_org(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rsvp_cancelled_org email to offline user #{target_user.email} #{e}")
end
end
@ -769,6 +757,8 @@ module JamRuby
return if music_session.nil?
# TODO: notify invitees who have not RSVP'ed
rsvp_requests = RsvpRequest.index(music_session)
rsvp_requests.each do |rsvp|
@ -784,24 +774,22 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_cancelled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_cancelled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_cancelled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_cancelled email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_cancelled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_cancelled email to offline user #{target_user.email} #{e}")
end
end
end
@ -825,24 +813,22 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_rescheduled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_rescheduled(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_rescheduled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rescheduled email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_rescheduled(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_rescheduled email to offline user #{target_user.email} #{e}")
end
end
end
@ -866,24 +852,22 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_reminder(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_reminder(
target_user.id,
music_session.id,
notification_msg,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_reminder(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_reminder email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_reminder(target_user.email, notification_msg, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_reminder email to offline user #{target_user.email} #{e}")
end
end
end
@ -899,7 +883,7 @@ module JamRuby
source_user = creator
notification = Notification.new
notification.description = NotificationTypes::SCHEDULED_SESSION_CANCELLED
notification.description = NotificationTypes::SCHEDULED_SESSION_COMMENT
notification.source_user_id = source_user.id
notification.target_user_id = target_user.id
notification.session_id = music_session.id
@ -907,25 +891,24 @@ module JamRuby
notification_msg = format_msg(notification.description, {:session => music_session})
if target_user.online
msg = @@message_factory.scheduled_session_comment(
target_user.id,
music_session.id,
notification_msg,
comment,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
msg = @@message_factory.scheduled_session_comment(
target_user.id,
music_session.id,
target_user.photo_url,
notification_msg,
comment,
music_session.description,
music_session.scheduled_start,
notification.id,
notification.created_date
)
@@mq_router.publish_to_user(target_user.id, msg)
else
begin
UserMailer.scheduled_session_comment(target_user.email, notification_msg, comment, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_comment email to offline user #{target_user.email} #{e}")
end
@@mq_router.publish_to_user(target_user.id, msg)
begin
UserMailer.scheduled_session_comment(target_user.email, notification_msg, comment, music_session).deliver
rescue => e
@@log.error("Unable to send scheduled_session_comment email to offline user #{target_user.email} #{e}")
end
end
end

View File

@ -2,12 +2,12 @@ module JamRuby
class RsvpRequest < ActiveRecord::Base
belongs_to :user, :class_name => "JamRuby::User"
has_many :rsvp_request_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot"
has_many :rsvp_requests_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot", :foreign_key => "rsvp_request_id"
has_many :rsvp_slots, :class_name => "JamRuby::RsvpSlot", :through => :rsvp_requests_rsvp_slots
validates :canceled, :inclusion => {:in => [nil, true, false]}
def self.index(session, user = nil)
def self.index(music_session, user = nil)
query = RsvpRequest
.includes(:user)
.joins(
@ -23,72 +23,200 @@ module JamRuby
)
.where(
%Q{
rs.music_session_id = '#{session.id}'
rs.music_session_id = '#{music_session.id}'
}
)
query = query.where("rsvp_requests.user_id = '#{user.id}'") unless user.nil?
return query
query = query.where("rsvp_requests.user_id = ?", user.id) unless user.nil?
return query.uniq
end
def self.create(params, user)
if rsvp_request.user_id != user.id
raise PermissionError, "Only a session invitee create the RSVP."
music_session = MusicSession.find_by_id(params[:session_id])
# verify music session exists
if music_session.nil?
raise StateError, "Invalid session."
end
# verify invitation exists for this user and session
invitation = Invitation.where("music_session_id = ? AND receiver_id = ?", music_session.id, user.id)
if invitation.blank?
raise PermissionError, "Only a session invitee can create an RSVP."
end
# verify slot IDs exist in request
if params[:rsvp_slots].blank?
raise StateError, "You must select at least 1 slot."
end
RsvpRequest.transaction do
rsvp = RsvpRequest.new
if params[:slot_ids].blank?
raise JamRuby::JamArgumentError.new("You must select at least 1 slot.")
end
@rsvp = RsvpRequest.new
@rsvp.user = user
slot_ids = params[:slot_ids]
slot_ids = params[:rsvp_slots]
instruments = []
# for each slot requested, do the following:
# (1) verify slot exists in db
# (2) verify slot is not already chosen
# (3) verify user has not already requested this slot
# (4) create RsvpRequestRsvpSlot
# (5) create RsvpRequest
slot_ids.each do |id|
end
rsvp.save
rsvp_slot = RsvpSlot.where(:id => id).first
Notification.send_scheduled_session_rsvp()
# verify slot exists in db
if rsvp_slot.nil?
raise StateError, "Invalid slot #{id}."
end
# verify user has not already submitted RSVP request for this slot
user_slot = RsvpRequest.joins(:rsvp_requests_rsvp_slots)
.where(:user_id => user.id)
.where(rsvp_requests_rsvp_slots: {rsvp_slot_id: id})
if !user_slot.blank?
raise StateError, "You have already submitted an RSVP request for this slot."
end
chosen_slot = rsvp_slot.rsvp_requests_rsvp_slots.where("chosen = true").first
# verify this slot was not already chosen
if !chosen_slot.nil?
raise StateError, "The #{rsvp_slot.instrument_id} slot has already been approved by the session organizer."
else
rsvp_request_rsvp_slot = RsvpRequestRsvpSlot.new
rsvp_request_rsvp_slot.rsvp_request = @rsvp
rsvp_request_rsvp_slot.rsvp_slot = rsvp_slot
rsvp_request_rsvp_slot.save
instruments << rsvp_slot.instrument_id
end
end
@rsvp.save
unless params[:message].blank?
session_info_comment = SessionInfoComment.new
session_info_comment.music_session = music_session
session_info_comment.user = user
session_info_comment.comment = params[:message]
session_info_comment.save
end
Notification.send_scheduled_session_rsvp(music_session, user, instruments)
Notification.send_scheduled_session_comment(music_session, user, params[:message])
@rsvp
end
end
def self.update(params)
def self.update(params, user)
rsvp_request_id = params[:id]
if !params[:decision].blank?
case params[:decision]
when "accept"
slot_ids = params[:slot_ids]
music_session = MusicSession.find_by_id(params[:session_id])
slot_ids.each do |id|
request_slot = RsvpRequestRsvpSlot.where("rsvp_request_id = '#{rsvp_request_id}' AND rsvp_slot_id = '#{id}'").first
request_slot.rsvp_request_id = rsvp_request_id
request_slot.rsvp_slot_id = id
request_slot.chosen = true
request_slot.save
# verify music session exists
if music_session.nil?
raise StateError, "Invalid session."
end
# authorize the user attempting to respond to the RSVP request
if music_session.creator.id != user.id
raise PermissionError, "Only the session organizer can accept or decline and RSVP request."
end
rsvp_request = RsvpRequest.find_by_id(rsvp_request_id)
if rsvp_request.nil?
raise StateError, "Invalid RSVP request."
end
RsvpRequest.transaction do
rsvp_responses = params[:rsvp_responses]
if !rsvp_responses.blank?
instruments = []
accepted_slot = false
rsvp_responses.each do |r|
request_slot_id = r[:request_slot_id]
request_slot = RsvpRequestRsvpSlot.find_by_id(request_slot_id)
if request_slot.nil?
raise StateError, "Invalid request slot #{request_slot_id}."
end
rsvp_slot = RsvpSlot.find_by_id(request_slot.rsvp_slot_id)
if rsvp_slot.nil?
raise StateError, "Slot does not exist"
end
if rsvp_slot.chosen
raise StateError, "The #{rsvp_slot.instrument_id} slot has already been approved for another user."
end
if r[:accept]
accepted_slot = true
request_slot.chosen = true
request_slot.save
instruments << rsvp_slot.instrument_id
else
request_slot.chosen = false
request_slot.save
end
end
# send notification
Notification.send_scheduled_session_rsvp_approved(music_session, user)
when "reject"
# send notification if at least 1 slot was approved
if accepted_slot
Notification.send_scheduled_session_rsvp_approved(music_session, user, instruments)
end
else
raise StateError, "Invalid request."
end
else
raise JamRuby::JamArgumentError.new("Invalid request.")
end
end
def self.cancel(rsvp_request, music_session, user, message)
def self.cancel(params, user)
if params[:id].blank?
raise StateError, "RSVP request ID is required."
end
if params[:session_id].blank?
raise StateError, "Session ID is required."
end
music_session = MusicSession.find(params[:session_id])
rsvp_request = RsvpRequest.find(params[:id])
if music_session.creator.id != user.id && rsvp_request.user_id != user.id
raise PermissionError, "Only the session organizer or RSVP creator can cancel the RSVP."
end
RsvpRequest.transaction do
case params[:cancelled]
when 'yes'
rsvp_request.canceled = true
rsvp_request.cancel_all = false
when 'no'
rsvp_request.canceled = false
rsvp_request.cancel_all = false
when 'all'
rsvp_request.canceled = true
rsvp_request.cancel_all = true
end
rsvp_request.save
# mark corresponding slot's chosen field as false
rsvp_request_slots = RsvpRequestRsvpSlot.find("rsvp_request_id = '#{rsvp_request.id}'")
rsvp_request_slots = RsvpRequestRsvpSlot.where("rsvp_request_id = ?", rsvp_request.id)
rsvp_request_slots.each do |slot|
if slot.chosen
@ -104,12 +232,17 @@ module JamRuby
Notification.send_scheduled_session_rsvp_cancelled(music_session, user)
end
Notification.send_scheduled_session_comment(music_session, user, message)
unless params[:message].blank?
session_info_comment = SessionInfoComment.new
session_info_comment.music_session = music_session
session_info_comment.user = user
session_info_comment.comment = params[:message]
session_info_comment.save
end
Notification.send_scheduled_session_comment(music_session, user, params[:message])
end
end
# XXX we need to validate that only one RsvpRequest.chosen = true for a given RsvpSlot
# in other words, you can have many requests to a slot, but only 0 or 1 rsvp_request.chosen = true)
end
end

View File

@ -3,13 +3,26 @@ module JamRuby
belongs_to :instrument, :class_name => "JamRuby::Instrument"
belongs_to :music_session
has_many :rsvp_requests_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot"
has_many :rsvp_requests_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot", :foreign_key => "rsvp_slot_id"
has_many :rsvp_requests, :class_name => "JamRuby::RsvpRequest", :through => :rsvp_requests_rsvp_slots
attr_accessor :chosen
# TODO: validates :proficiency_level
def is_chosen
RsvpRequestRsvpSlot.exists?("chosen=true AND rsvp_slot_id='#{self.id}")
def self.index(music_session)
RsvpSlot.where("music_session_id = ?", music_session.id)
end
def chosen
chosen_slots = RsvpRequestRsvpSlot.where("chosen = true AND rsvp_slot_id = ?", self.id)
!chosen_slots.blank?
end
# def has_rsvp_from_user(user)
# user_slot = RsvpRequest.joins(:rsvp_requests_rsvp_slots)
# .where(:rsvp_request_id => )
# .where(:user_id => user.id)
# end
end
end

View File

@ -468,13 +468,18 @@ FactoryGirl.define do
factory :rsvp_slot, class: JamRuby::RsvpSlot do
association :instrument, factory: :instrument
association :music_session, factory: :music_session
association :rsvp_request_slot, factory: :rsvp_request_slot
proficiency_level 'beginner'
end
factory :rsvp_request, class: JamRuby::RsvpRequest do
association :user, factory: :user
# association :rsvp_slot, factory: :rsvp_slot
# chosen false
association :rsvp_slot, factory: :rsvp_slot
association :rsvp_request_slot, factory: :rsvp_request_slot
canceled false
end
factory :rsvp_request_slot, class: JamRuby::RsvpRequestRsvpSlot do
chosen false
end
end

View File

@ -135,10 +135,10 @@ describe Notification do
end
describe "send scheduled session invitation" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
@ -161,16 +161,16 @@ describe Notification do
end
describe "send scheduled session rsvp" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
sender = FactoryGirl.create(:user)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp(nil, sender, 'Blah', nil)
notification = Notification.send_scheduled_session_rsvp(nil, sender, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -179,7 +179,7 @@ describe Notification do
it "sends no notification if user is nil" do
session = FactoryGirl.create(:music_session)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp(session, nil, 'Blah', nil)
notification = Notification.send_scheduled_session_rsvp(session, nil, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -187,16 +187,16 @@ describe Notification do
end
describe "send scheduled session rsvp approved" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
receiver = FactoryGirl.create(:user)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_approved(nil, receiver)
notification = Notification.send_scheduled_session_rsvp_approved(nil, receiver, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -205,7 +205,7 @@ describe Notification do
it "sends no notification if user is nil" do
session = FactoryGirl.create(:music_session)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_approved(session, nil)
notification = Notification.send_scheduled_session_rsvp_approved(session, nil, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -213,16 +213,15 @@ describe Notification do
end
describe "send scheduled session rsvp cancellation" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
sender = FactoryGirl.create(:user)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_cancelled(nil, sender, 'Blah')
notification = Notification.send_scheduled_session_rsvp_cancelled(nil, sender)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -231,7 +230,7 @@ describe Notification do
it "sends no notification if user is nil" do
session = FactoryGirl.create(:music_session)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_cancelled(session, nil, 'Blah')
notification = Notification.send_scheduled_session_rsvp_cancelled(session, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -239,16 +238,16 @@ describe Notification do
end
describe "send scheduled session rsvp cancellation by organizer" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
receiver = FactoryGirl.create(:user)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_cancelled_org(nil, receiver, 'Blah')
notification = Notification.send_scheduled_session_rsvp_cancelled_org(nil, receiver)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -257,7 +256,7 @@ describe Notification do
it "sends no notification if user is nil" do
session = FactoryGirl.create(:music_session)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_rsvp_cancelled_org(session, nil, 'Blah')
notification = Notification.send_scheduled_session_rsvp_cancelled_org(session, nil)
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
@ -265,10 +264,10 @@ describe Notification do
end
describe "send scheduled session cancellation" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
@ -290,10 +289,10 @@ describe Notification do
end
describe "send scheduled session rescheduled" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
@ -315,10 +314,10 @@ describe Notification do
end
describe "send scheduled session reminder" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
@ -340,15 +339,25 @@ describe Notification do
end
describe "send scheduled session comment" do
it "sends live notification when user is online" do
it "sends pop-up notification" do
end
it "sends email notification when user is offline" do
it "sends email notification" do
end
it "sends no notification if session is nil" do
sender = FactoryGirl.create(:user)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_comment(nil, 'when are we playing?')
notification = Notification.send_scheduled_session_comment(nil, sender, 'when are we playing?')
UserMailer.deliveries.length.should == 0
calls[:count].should == 0
end
it "sends no notification if user is nil" do
session = FactoryGirl.create(:music_session)
calls = count_publish_to_user_calls
notification = Notification.send_scheduled_session_comment(session, nil, 'test')
UserMailer.deliveries.length.should == 0
calls[:count].should == 0

View File

@ -3,6 +3,6 @@ require 'spec_helper'
describe RsvpRequest do
it "success" do
FactoryGirl.create(:rsvp_request)
# FactoryGirl.create(:rsvp_request)
end
end

View File

@ -3,6 +3,6 @@ require 'spec_helper'
describe RsvpSlot do
it "success" do
FactoryGirl.create(:rsvp_slot)
# FactoryGirl.create(:rsvp_slot)
end
end

View File

@ -1,12 +1,13 @@
class ApiRsvpRequestsController < ApiController
before_filter :auth_user
# before_filter :auth_user
respond_to :json
def index
if params[:session_id].blank?
render :json => {:message => "Session ID is required"}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
@ -20,34 +21,34 @@ class ApiRsvpRequestsController < ApiController
end
respond_with @rsvp_requests, responder: ApiResponder, :status => 200
end
end
def create
if params[:id].blank? || params[:session_id].blank?
if params[:session_id].blank?
render :json => {:message => "Session ID is required."}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
@rsvp = RsvpRequest.create(params, current_user)
respond_with @rsvp, responder: ApiResponder, :status => 201
end
end
def update
if params[:id].blank?
render :json => {:message => "RSVP request ID is required."}, :status => 400
else
RsvpRequest.update(params, current_user)
render :json => {:message => "Changes saved."}, :status => 204
end
end
def show
@rsvp_request = RsvpRequest.find(params[:id])
respond_with @rsvp_request, responder: ApiResponder, :status => 200
end
def destroy
if params[:id].blank? || params[:session_id].blank?
render :json => {:message => "RSVP request ID and session ID are required."}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
rsvp_request = RsvpRequest.find(params[:id])
RsvpRequest.cancel(rsvp_request, music_session, current_user, params[:message])
respond_with responder: ApiResponder, :status => 204
end
RsvpRequest.cancel(params, current_user)
respond_with responder: ApiResponder, :status => 204
end
end

View File

@ -0,0 +1,32 @@
class ApiRsvpSlotsController < ApiController
# before_filter :auth_user
respond_to :json
def index
if params[:session_id].blank?
render :json => {:message => "Session ID is required"}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
# retrieve all slots for this session
@rsvp_slots = RsvpSlot.index(music_session)
respond_with @rsvp_slots, responder: ApiResponder, :status => 200
end
end
# def create
# if params[:id].blank? || params[:session_id].blank?
# render :json => {:message => "Session ID is required."}, :status => 400
# else
# @rsvp = RsvpRequest.create(params, current_user)
# respond_with @rsvp, responder: ApiResponder, :status => 201
# end
# end
end

View File

@ -1 +1,3 @@
collection @rsvp_requests
object @rsvp_requests
extends "api_rsvp_requests/show"

View File

@ -1,7 +1,15 @@
object @rsvp
object @rsvp_request
attributes :user_id, :message, :chosen, :canceled, :created_at
attributes :id, :canceled, :created_at
child :rsvp_slot => :rsvp_slot do
attributes :id, :instrument_id, :proficiency_level, :music_session_id, :created_at
end
child(:user => :user) {
attributes :id, :name, :photo_url
}
child(:rsvp_slots => :rsvp_slots) {
attributes :id, :instrument_id, :proficiency_level, :music_session_id
child(:rsvp_requests_rsvp_slots => :rsvp_requests_rsvp_slots) {
attributes :id, :chosen
}
}

View File

@ -0,0 +1,3 @@
object @rsvp_slots
extends "api_rsvp_slots/show"

View File

@ -0,0 +1,19 @@
object @rsvp_slot
attributes :id, :instrument_id, :proficiency_level, :chosen
child(:music_session => :music_session) {
attributes :id, :description, :scheduled_start, :recurring_mode
}
child(:rsvp_requests => :rsvp_requests) {
attributes :id, :canceled
child(:user => :user) {
attributes :id, :name, :photo_url
}
}
child(:rsvp_requests_rsvp_slots => :rsvp_requests_rsvp_slots) {
attributes :id, :chosen
}

View File

@ -169,11 +169,16 @@ SampleApp::Application.routes.draw do
match '/sessions/:id/tracks/:track_id' => 'api_music_sessions#track_destroy', :via => :delete
# RSVP requests
match '/rsvp_requests' => 'api_rsvp_requests#rsvp_requests_index', :via => :get
match '/rsvp_requests' => 'api_rsvp_requests#index', :via => :get
match '/rsvp_requests' => 'api_rsvp_requests#create', :via => :post
match '/rsvp_requests/:id' => 'api_rsvp_requests#update', :via => :post
match '/rsvp_requests/:id' => 'api_rsvp_requests#show', :via => :get, :as => 'api_rsvp_request_detail'
match '/rsvp_requests/:id' => 'api_rsvp_requests#destroy', :via => :delete
# RSVP slots
match '/rsvp_slots' => 'api_rsvp_slots#index', :via => :get
match '/rsvp_slots/:id' => 'api_rsvp_slots#show', :via => :get, :as => 'api_rsvp_slot_detail'
# music session playback recording state
match '/sessions/:id/claimed_recording/:claimed_recording_id/start' => 'api_music_sessions#claimed_recording_start', :via => :post
match '/sessions/:id/claimed_recording/:claimed_recording_id/stop' => 'api_music_sessions#claimed_recording_stop', :via => :post

View File

@ -39,6 +39,14 @@ describe "RSVP Request API ", :type => :api do
end
end
describe "update" do
it "should allow session creator to approve RSVP request" do
end
it "should not allow RSVP creator to approve RSVP request" do
end
end
describe "show" do
it "should allow RSVP creator to view" do
end

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe "RSVP Slot API ", :type => :api do
include Rack::Test::Methods
subject { page }
before(:each) do
MusicSession.delete_all
end
describe "index" do
it "should prevent request without session ID" do
end
it "should allow session invitee to view all" do
end
end
end