Skip to content

Commit

Permalink
Add surveys during proposal submission
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKvalheim committed Jun 17, 2022
1 parent c9f410e commit 08d8590
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
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
2 changes: 1 addition & 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
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

= render partial: 'surveys/list', locals: { surveys: @surveys, conference: @conference }
26 changes: 26 additions & 0 deletions spec/features/surveys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,30 @@
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)
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)
expect(find(:link, survey.title).sibling('.fa-solid')[:title]).to eq('Thank you for filling out the survey')
end
end
end

0 comments on commit 08d8590

Please sign in to comment.