Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surveys during proposal submission #3058

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .haml-lint_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ linters:
- "app/views/admin/emails/index.html.haml"
- "app/views/admin/events/_proposal.html.haml"
- "app/views/admin/events/index.html.haml"
- "app/views/admin/events/show.html.haml"
- "app/views/admin/tracks/index.html.haml"
- "app/views/admin/tracks/show.html.haml"
- "app/views/admin/versions/_object_desc_and_link.html.haml"
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Metrics/BlockNesting:
# Offense count: 14
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 652
Max: 655

# Offense count: 29
# Configuration parameters: IgnoredMethods.
Expand Down
1 change: 1 addition & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def index
@event = @program.events.new
@event.event_users.new(user: current_user, event_role: 'submitter')
@events = current_user.proposals(@conference)
@surveys = @conference.surveys.during_proposal.select(&:active?)
end

def show
Expand Down
4 changes: 4 additions & 0 deletions app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Conference < ApplicationRecord
has_many :event_types, through: :program

has_many :surveys, as: :surveyable, dependent: :destroy do
def during_proposal
where(target: targets[:during_proposal])
end

def for_registration
where(target: targets[:during_registration])
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ def speaker_emails
#
# Returns +Hash+
def progress_status
surveys = conference.surveys.during_proposal.select(&:active?)

{
registered: speakers.all? { |speaker| program.conference.user_registered? speaker },
surveys: (surveys.all? { |survey| survey.replied?(submitter) } if surveys.present?),
commercials: commercials.any?,
biographies: speakers.all? { |speaker| !speaker.biography.blank? },
subtitle: !subtitle.blank?,
Expand Down
6 changes: 5 additions & 1 deletion app/models/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Survey < ActiveRecord::Base
has_many :survey_questions, dependent: :destroy
has_many :survey_submissions, dependent: :destroy

enum target: [:after_conference, :during_registration, :after_event]
enum target: [:after_conference, :during_registration, :after_event, :during_proposal]
validates :title, presence: true

##
Expand Down Expand Up @@ -36,4 +36,8 @@ def active?
def closed?
!active?
end

def replied?(user_id)
survey_submissions.where(user_id: user_id).any?
end
end
5 changes: 5 additions & 0 deletions app/views/admin/events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
%td= link_to "#{'Speaker'.pluralize(@event.speakers.count)} must be registered to the conference", admin_conference_registrations_path(@event.program.conference.short_title)
%td{ 'class' => class_for_todo(progress_status['registered']) }
%span{ 'class' => [icon_for_todo(progress_status['registered']), 'fa-lg'] }
- unless progress_status['surveys'].nil?
%tr
%td= link_to 'Respond to surveys', admin_conference_surveys_path(@event.program.conference.short_title)
%td{ 'class' => class_for_todo(progress_status['surveys']) }
%span{ 'class' => [icon_for_todo(progress_status['surveys']), 'fa-lg'] }
%tr
%td
- speakers_count = @event.speakers.count
Expand Down
4 changes: 4 additions & 0 deletions app/views/proposals/_tooltip.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Speaker(s) registered to the conference
- else
= link_to 'Speaker(s) not registered to the conference', new_conference_conference_registration_path(event.program.conference.short_title)
- unless progress_status['surveys'].nil?
%li{'class'=>class_for_todo(progress_status['surveys'])}
%span{'class'=>icon_for_todo(progress_status['surveys'])}
= link_to 'Respond to surveys', '#surveys'
%li{'class'=>class_for_todo(progress_status['biographies'])}
%span{'class'=>icon_for_todo(progress_status['biographies'])}
- if progress_status['biographies']
Expand Down
7 changes: 7 additions & 0 deletions app/views/proposals/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,10 @@
.col-md-12
- if can? :create, @event
= link_to "New Proposal", new_conference_program_proposal_path(@conference.short_title), class: 'btn btn-success pull-right'

- if @surveys.any?
.row
.col-md-12
%h2#surveys Surveys

= render partial: 'surveys/list', locals: { surveys: @surveys, conference: @conference }
2 changes: 1 addition & 1 deletion app/views/surveys/_list.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- surveys.each do |survey|
- if survey.survey_submissions.find_by(user: current_user)
- if survey.replied?(current_user)
%i.fa-solid.fa-square-check.text-success{ title: 'Thank you for filling out the survey' }
- else
%i.fa-solid.fa-square-minus.text-danger{ title: 'Please fill out the survey' }
Expand Down
32 changes: 32 additions & 0 deletions spec/features/surveys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,36 @@
expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey')
end
end

context 'as a speaker' do
let(:speaker) { create(:user) }

before :each do
sign_in speaker
end

scenario 'respond to a survey during proposal submission', feature: true, js: true do
create :cfp, program: conference.program
create :event, program: conference.program, submitter: speaker
survey = create(:survey, surveyable: conference, target: :during_proposal)
create :boolean_mandatory, survey: survey

visit conference_program_proposals_path(conference.short_title)
within('.progress') { expect(page).to have_text '4 left' }
click_on 'Complete your proposal'
within('.popover') { expect(find(:link, 'Respond to surveys')).to have_sibling('.fa-xmark') }
expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Please fill out the survey')

click_link survey.title
choose 'Yes'
click_button 'Submit'
expect(flash).to eq('Successfully responded to survey.')

visit conference_program_proposals_path(conference.short_title)
within('.progress') { expect(page).to have_text '3 left' }
click_on 'Complete your proposal'
within('.popover') { expect(find(:link, 'Respond to surveys')).to have_sibling('.fa-check') }
expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey')
end
end
end