Skip to content

Commit

Permalink
Merge branch 'custom_questions' of https://github.com/aangott/bridge_…
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Mar 21, 2017
2 parents 2e95194 + ea7d84d commit 1486f39
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 7 deletions.
13 changes: 7 additions & 6 deletions app/controllers/events/attendees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ def find_event
def attendee_csv_data(rsvps)
CSV.generate do |csv|
csv << [
'Name', 'Attending As', 'Dietary Info', 'Childcare Info',
'Job Details', 'Gender', 'Plus-One Host', 'Waitlisted',
'Waitlist Position'
'Name', 'Attending As', 'Custom Question Answer', 'Dietary Info',
'Childcare Info', 'Job Details', 'Gender', 'Plus-One Host',
'Waitlisted', 'Waitlist Position'
]

rsvps.includes(:user).joins(:bridgetroll_user).order('users.first_name ASC, users.last_name ASC').each do |rsvp|
waitlisted = rsvp.waitlisted? ? 'yes' : 'no'
csv << [
rsvp.user.full_name, rsvp.role.title, rsvp.full_dietary_info,
rsvp.childcare_info, rsvp.job_details, rsvp.user.gender,
rsvp.plus_one_host, waitlisted, rsvp.waitlist_position
rsvp.user.full_name, rsvp.role.title, rsvp.custom_question_answer,
rsvp.full_dietary_info, rsvp.childcare_info, rsvp.job_details,
rsvp.user.gender, rsvp.plus_one_host, waitlisted,
rsvp.waitlist_position
]
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ def levels
course.levels
end

def asks_custom_question?
custom_question.present?
end

private

DEFAULT_DETAIL_FILES = Dir[Rails.root.join('app', 'models', 'event_details', '*.html')]
Expand Down
1 change: 1 addition & 0 deletions app/policies/event_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def permitted_attributes
:has_childcare,
:restrict_operating_systems,
:survey_greeting,
:custom_question,
{
event_sessions_attributes: EventSessionPolicy.new(user, EventSession).permitted_attributes + [:id],
allowed_operating_system_ids: []
Expand Down
1 change: 1 addition & 0 deletions app/policies/rsvp_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def permitted_attributes
:operating_system_id,
:job_details,
:class_level,
:custom_question_answer,
:dietary_info,
:needs_childcare,
:plus_one_host,
Expand Down
3 changes: 3 additions & 0 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@

<div>
<%= f.input :volunteer_details, label: 'RSVP confirmation details sent to Volunteers after sign up', input_html: {rows: 4} %>
</div>

<div>
<%= f.input :custom_question, label: 'Anything else you want to ask users who RSVP? (e.g., t-shirt size)', input_html: {rows: 4} %>
</div>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/events/attendees/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<tr>
<th class='attendee-name'>Name</th>
<th class='attendee-role'>Attending As</th>
<th class='attendee-custom-question-answer'>Custom Question Answer</th>
<th class='attendee-dietary-info'>Dietary Info</th>
<th class='attendee-childcare-info'>Childcare Info</th>
<th class='attendee-job-details'>Job Details</th>
Expand All @@ -53,6 +54,7 @@
<%= link_to rsvp.user.full_name, user_profile_path(rsvp.user) %>
</td>
<td data-label="Attending as:"><%= rsvp.role.title %></td>
<%= content_tag_maybe_hidden(:td, rsvp.custom_question_answer, 'data-label' => 'Custom question answer:') %>
<%= content_tag_maybe_hidden(:td, rsvp.full_dietary_info, 'data-label' => 'Dietary info:') %>
<%= content_tag_maybe_hidden(:td, rsvp.childcare_info, 'data-label' => 'Childcare info:') %>
<td data-label="Job details:"><%= rsvp.job_details %></td>
Expand Down
6 changes: 6 additions & 0 deletions app/views/rsvps/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<% end %>
</div>

<% if @event.asks_custom_question? %>
<div class="field question">
<%= f.input :custom_question_answer, label: @event.custom_question, input_html: {rows: 3} %>
</div>
<% end %>
<% if @event.food_provided? %>
<div class="field">
<p class="question">The food's on us. Let us know if you have any dietary restrictions.</p>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170319191233_add_custom_question_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCustomQuestionToEvents < ActiveRecord::Migration[5.0]
def change
add_column :events, :custom_question, :text
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCustomQuestionAnswerToRsvps < ActiveRecord::Migration[5.0]
def change
add_column :rsvps, :custom_question_answer, :text
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170202035358) do
ActiveRecord::Schema.define(version: 20170319192836) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "unaccent"
Expand Down Expand Up @@ -120,6 +120,7 @@
t.string "imported_event_data"
t.integer "chapter_id", null: false
t.boolean "food_provided", default: true, null: false
t.text "custom_question"
t.index ["chapter_id"], name: "index_events_on_chapter_id"
end

Expand Down Expand Up @@ -266,6 +267,7 @@
t.boolean "checkiner", default: false
t.text "plus_one_host"
t.string "token"
t.text "custom_question_answer"
t.index ["token"], name: "index_rsvps_on_token", unique: true
t.index ["user_id", "event_id", "user_type"], name: "index_rsvps_on_user_id_and_event_id_and_event_type", unique: true
end
Expand Down
24 changes: 24 additions & 0 deletions spec/features/events/event_rsvp_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@
end
end
end

describe 'displaying custom question field' do
before do
@event.update(custom_question: custom_question)
visit volunteer_new_event_rsvp_path(@event)
end

context 'when event asks a custom question' do
let(:custom_question) { 'What is your t-shirt size?' }

it 'diplays a field for the user to respond to the custom question' do
expect(page).to have_content custom_question
expect(page).to have_field('rsvp_custom_question_answer')
end
end

context 'when event does not ask a custom question' do
let(:custom_question) { '' }

it 'does not display a field for the user to respond to the custom question' do
expect(page).not_to have_field('rsvp_custom_question_answer')
end
end
end
end

context "for a non-teaching event" do
Expand Down
22 changes: 22 additions & 0 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,26 @@ def add_rsvp(factory, session_checkins, additional_rsvp_options = {})
end
end
end

describe '#asks_custom_question?' do
context 'when event asks a custom question' do
before do
allow(subject).to receive(:custom_question) { 'What is your t-shirt size?' }
end

it 'returns true' do
expect(subject.asks_custom_question?).to eql true
end
end

context 'when event does not ask a custom question' do
before do
allow(subject).to receive(:custom_question) { '' }
end

it 'returns false' do
expect(subject.asks_custom_question?).to eql false
end
end
end
end

0 comments on commit 1486f39

Please sign in to comment.