Skip to content

Commit

Permalink
Remove volunteer/register buttons when rsvps are closed. Display text…
Browse files Browse the repository at this point in the history
… "RSVPs are closed!" on upcoming and event show page.

Allow organizers to reopen RSVPs for an event from organizer console.
  • Loading branch information
Bita Djaghouri committed Aug 2, 2015
1 parent 81edc1c commit d8648d3
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 70 deletions.
6 changes: 6 additions & 0 deletions app/controllers/events/organizer_tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ def close_rsvps
flash[:notice] = "RSVPs closed successfully."
redirect_to event_organizer_tools_path(@event)
end

def reopen_rsvps
@event.reopen_rsvps
flash[:notice] = "RSVPs reopened successfully."
redirect_to event_organizer_tools_path(@event)
end
end
73 changes: 45 additions & 28 deletions app/controllers/rsvps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,58 @@ class RsvpsController < ApplicationController


def volunteer
@rsvp = @event.rsvps.build(user: current_user)
@rsvp.setup_for_role(Role::VOLUNTEER)
render :new
if @event.open?
@rsvp = @event.rsvps.build(user: current_user)
@rsvp.setup_for_role(Role::VOLUNTEER)
render :new
else
redirect_for_closed_event
end
end

def learn
@rsvp = @event.rsvps.build(user: current_user)
@rsvp.setup_for_role(Role::STUDENT)
render :new
if @event.open?
@rsvp = @event.rsvps.build(user: current_user)
@rsvp.setup_for_role(Role::STUDENT)
render :new
else
redirect_for_closed_event
end
end

def create
@rsvp = Rsvp.new(rsvp_params)
@rsvp.event = @event
@rsvp.user = current_user
if Role.attendee_role_ids.include?(params[:rsvp][:role_id].to_i)
@rsvp.role = Role.find(params[:rsvp][:role_id])
end

Rsvp.transaction do
if @event.students_at_limit? && @rsvp.role_student?
@rsvp.waitlist_position = (@event.student_waitlist_rsvps.maximum(:waitlist_position) || 0) + 1
if @event.open?
@rsvp = Rsvp.new(rsvp_params)
@rsvp.event = @event
@rsvp.user = current_user
if Role.attendee_role_ids.include?(params[:rsvp][:role_id].to_i)
@rsvp.role = Role.find(params[:rsvp][:role_id])
end

if @event.volunteers_at_limit? && @rsvp.role_volunteer?
@rsvp.waitlist_position = (@event.volunteer_waitlist_rsvps.maximum(:waitlist_position) || 0 ) + 1
end
Rsvp.transaction do
if @event.students_at_limit? && @rsvp.role_student?
@rsvp.waitlist_position = (@event.student_waitlist_rsvps.maximum(:waitlist_position) || 0) + 1
end

set_dietary_restrictions(@rsvp, params[:dietary_restrictions])
if @event.volunteers_at_limit? && @rsvp.role_volunteer?
@rsvp.waitlist_position = (@event.volunteer_waitlist_rsvps.maximum(:waitlist_position) || 0 ) + 1
end

if @rsvp.save
apply_other_changes_from_params
set_dietary_restrictions(@rsvp, params[:dietary_restrictions])

RsvpMailer.confirmation(@rsvp).deliver_now
notice_message = 'Thanks for signing up!'
notice_message << " We've added you to the waitlist." if @rsvp.waitlisted?
redirect_to @event, notice: notice_message
else
render :new
if @rsvp.save
apply_other_changes_from_params

RsvpMailer.confirmation(@rsvp).deliver_now
notice_message = 'Thanks for signing up!'
notice_message << " We've added you to the waitlist." if @rsvp.waitlisted?
redirect_to @event, notice: notice_message
else
render :new
end
end
else
redirect_for_closed_event
end
end

Expand Down Expand Up @@ -84,6 +96,11 @@ def destroy

protected

def redirect_for_closed_event
flash[:error] = "Sorry. This event is closed!"
redirect_to @event
end

def apply_other_changes_from_params
@rsvp.user.update_attributes(gender: params[:user][:gender])

Expand Down
5 changes: 5 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def close_rsvps
self.save
end

def reopen_rsvps
self.open = true
self.save
end

def closed?
!open?
end
Expand Down
22 changes: 17 additions & 5 deletions app/views/events/_organizer_preworkshop_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<% rsvp_button =
if @event.open
[event_close_rsvps_path(@event),
'fa fa-pencil',
'Close RSVPs',
"Prevent RSVPs from volunteers and students. This will also close the waitlist. To close RSVPs just for students, change the number of attendees by editing the event."
]
else
[event_reopen_rsvps_path(@event),
'fa fa-pencil',
'Open RSVPs',
"Reopen RSVPs for volunteers and students."
]
end
%>
<% [
[event_organizers_path(@event),
'fa fa-key',
Expand Down Expand Up @@ -38,11 +54,7 @@
"Organizing events is a lot of work! RailsBridge has put together a detailed
guide to running a workshop (easily used for other events, too)."
],
[event_close_rsvps_path(@event),
'fa fa-pencil',
'Close RSVPs',
"Prevent RSVPs from volunteers and students. This will also close the waitlist. To close RSVPs just for students, change the number of attendees by editing the event."
]
rsvp_button
].each do |button| %>
<%= render 'shared/organizer_action',
path: button[0],
Expand Down
10 changes: 7 additions & 3 deletions app/views/shared/_rsvp_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<%= link_to 'Cancel RSVP', event_rsvp_path(event, event.rsvp_for_user(current_user)), data: {confirm: 'Are you sure you want to cancel your RSVP?'}, method: :delete, class: 'btn' %>
<% end %>
<% if event.no_rsvp?(current_user) %>
<% if event.allow_student_rsvp? %>
<%= link_to student_attend_button_text(event), learn_new_event_rsvp_path(event), class: 'btn' %>
<% if event.open? %>
<% if event.allow_student_rsvp? %>
<%= link_to student_attend_button_text(event), learn_new_event_rsvp_path(event), class: 'btn' %>
<% end %>
<%= link_to volunteer_attend_button_text(event), volunteer_new_event_rsvp_path(event), class: 'btn' %>
<% else %>
<div class='rsvp-text'>RSVPs are closed!</div>
<% end %>
<%= link_to volunteer_attend_button_text(event), volunteer_new_event_rsvp_path(event), class: 'btn' %>
<% end %>
22 changes: 13 additions & 9 deletions app/views/shared/_rsvp_actions_unauthenticated.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<% if event.allow_student_rsvp? %>
<% if event.open? %>
<% if event.allow_student_rsvp? %>
<a href="#sign_in_dialog"
class="btn sign-in-button"
data-sign-up-return-to="<%= event_path(event) %>"
data-return-to="<%= if stay_on_event then event_path(event) else learn_new_event_rsvp_path(event) end %>">
<%= student_attend_button_text(event) %>
</a>
<% end %>
<a href="#sign_in_dialog"
class="btn sign-in-button"
data-sign-up-return-to="<%= event_path(event) %>"
data-return-to="<%= if stay_on_event then event_path(event) else learn_new_event_rsvp_path(event) end %>">
<%= student_attend_button_text(event) %>
data-return-to="<%= if stay_on_event then event_path(event) else volunteer_new_event_rsvp_path(event) end %>">
<%= volunteer_attend_button_text(event) %>
</a>
<% else %>
<div class='rsvp-text'>RSVPs are closed!</div>
<% end %>
<a href="#sign_in_dialog"
class="btn sign-in-button"
data-sign-up-return-to="<%= event_path(event) %>"
data-return-to="<%= if stay_on_event then event_path(event) else volunteer_new_event_rsvp_path(event) end %>">
<%= volunteer_attend_button_text(event) %>
</a>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
get "diets"
get "rsvp_preview"
get "close_rsvps"
get "reopen_rsvps"
end

collection do
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/rsvps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,30 @@ def extract_rsvp_params(rsvp)
end
end

describe "when the event is closed" do
before do
@event.update_attributes(open: false)
end

it 'does not allow RSVPing' do
get :volunteer, event_id: @event.id
response.should redirect_to(event_path(@event))
flash[:error].should be_present

get :learn, event_id: @event.id
response.should redirect_to(event_path(@event))
flash[:error].should be_present

rsvp_params = extract_rsvp_params build(:student_rsvp, event: @event)
post :create, event_id: @event.id, rsvp: rsvp_params
response.should redirect_to(event_path(@event))
flash[:error].should be_present

end
end

describe "#volunteer" do

it "creates an RSVP for the volunteer role" do
get :volunteer, event_id: @event.id
assigns(:rsvp).role.should == Role::VOLUNTEER
Expand Down
100 changes: 76 additions & 24 deletions spec/features/organizer_closes_rsvps_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,94 @@
require 'rails_helper'

describe "organizer closes RSVPs" do
describe "Opening and closing an event for RSVP" do

context "when RSVPs are open" do
before do
@event = create(:event)
@event.open = true
@event.save
end

it "allows volunteers to RSVP" do
create(:event)

visit root_path
context "when potential attendees view closed event" do
before do
visit root_path
end

within(".upcoming-events") do
expect(page).to have_link('Volunteer')
it "allows volunteers to RSVP" do
within(".upcoming-events") do
expect(page).to have_link('Volunteer')
end
end
end

it "allows students to RSVP"
it "allows students to RSVP" do
within(".upcoming-events") do
expect(page).to have_link("Attend as a student")
end
end
end

it "allows the organizers to close RSVPs" do
event = create(:event)
organizer = create(:user)
event.organizers << organizer
sign_in_as(organizer)
context "when organizer manages the event" do
it "allows the organizers to close RSVPs" do
organizer = create(:user)
@event.organizers << organizer
sign_in_as(organizer)

visit event_organizer_tools_path(event)
click_link("Close RSVPs")
visit event_organizer_tools_path(@event)
click_link("Close RSVPs")

within(".alert-success") do
expect(page).to have_content("RSVPs closed successfully.")
within(".alert-success") do
expect(page).to have_content("RSVPs closed successfully.")
end
expect(@event.reload).to be_closed
end
expect(event.reload).to be_closed
end

end

context "when RSVPs are closed" do
it "prevents volunteers from RSVPing"
it "pevents students from RSVPing"
it "allows organizers to reopen RSVPs"
end
before do
@event = create(:event)
@event.open = false
@event.save
end

context "when potential attendees view closed event" do
before do
visit root_path
end

it "prevents volunteers from RSVPing" do
within(".upcoming-events") do
expect(page).to_not have_link('Volunteer')
end
end

it "prevents students from RSVPing" do
within(".upcoming-events") do
expect(page).to_not have_link("Attend as a student")
end
end

it "presents message that RSVPs are closed" do
within(".upcoming-events") do
expect(page).to have_content("RSVPs are closed!")
end
end
end

context "when organizer manages the event" do
it "allows organizers to reopen RSVPs" do
organizer = create(:user)
@event.organizers << organizer
sign_in_as(organizer)

visit event_organizer_tools_path(@event)
click_link("Open RSVPs")

within(".alert-success") do
expect(page).to have_content("RSVPs reopened successfully.")
end
expect(@event.reload).to be_open
end
end
end
end
10 changes: 9 additions & 1 deletion spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,15 @@
it "closes the event" do
event = create(:event, open: true)
event.close_rsvps
expect(event.reload).to be_closed
expect(event).to be_closed
end
end

describe "#reopen_rsvps" do
it "reopens the event" do
event = create(:event, open: false)
event.reopen_rsvps
expect(event).to be_open
end
end

Expand Down

0 comments on commit d8648d3

Please sign in to comment.