Merge pull request #2969 from AndrewKvalheim/test-survey-create-and-respond

Basic feature test of survey creation and response
This commit is contained in:
Henne Vogelsang 2022-03-29 15:07:10 +02:00 committed by GitHub
commit db22aa27a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 70 additions and 10 deletions

View file

@ -426,7 +426,7 @@ Lint/UriRegexp:
# Offense count: 127
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 71
Max: 72
# Offense count: 313
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.

View file

@ -40,6 +40,6 @@ class SurveysController < ApplicationController
end
end
redirect_back(fallback_location: root_path)
redirect_back(fallback_location: root_path, notice: 'Successfully responded to survey.')
end
end

View file

@ -122,9 +122,7 @@ class Ability
# if not, do not allow replies.
# do not allow replies before the start_date or after the end_date of survey
cannot :reply, Survey do |survey|
survey.start_date > Time.current || survey.end_date < Time.current
end
cannot :reply, Survey, &:closed?
can [:destroy], Openid

View file

@ -142,6 +142,10 @@ class AdminAbility
can :manage, Room, venue: { conference_id: conf_ids }
can :manage, Sponsor, conference_id: conf_ids
can :manage, SponsorshipLevel, conference_id: conf_ids
can :manage, Survey, surveyable_type: 'Conference',
surveyable_id: conf_ids
can :manage, SurveyQuestion, survey: { surveyable_type: 'Conference',
surveyable_id: conf_ids }
can :manage, Ticket, conference_id: conf_ids
can :create, TicketScanning do |ticket_scanning|
conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id

View file

@ -32,4 +32,8 @@ class Survey < ActiveRecord::Base
now <= end_date
end
end
def closed?
!active?
end
end

View file

@ -30,7 +30,7 @@
= f.label :max_choices
= f.number_field :max_choices, class: 'form-control'
.form-group
%label{ required: 'required' }
%label{ for: 'survey_question_kind', required: 'required' }
Type of Question:
.form-group
%select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' }

View file

@ -0,0 +1 @@
= render partial: 'form'

View file

@ -22,7 +22,7 @@
= f.select :target, Survey.targets.keys, class: 'form-control'
.form-group
= f.label :start_date
= f.text_field :start_date, class: 'datetimepicker', class: 'form-control'
= f.text_field :start_date, class: 'datetimepicker form-control'
= f.label :end_date
= f.text_field :end_date, class: 'datetimepicker', class: 'form-control'
= f.text_field :end_date, class: 'datetimepicker form-control'
= f.submit nil, class: 'btn btn-primary'

View file

@ -3,8 +3,6 @@
FactoryBot.define do
factory :survey do
title { 'This is my survey' }
start_date { Date.current - 1.day }
end_date { Date.current + 1.day }
factory :conference_survey do
association :surveyable, factory: :conference

View file

@ -0,0 +1,55 @@
# frozen_string_literal: true
require 'spec_helper'
feature Survey do
let(:conference) { create(:conference) }
context 'as an organizer' do
let(:organizer) { create(:organizer, resource: conference) }
before :each do
sign_in organizer
end
scenario 'create a survey', feature: true, js: true do
visit admin_conference_path(conference)
click_link 'Surveys'
click_link 'New'
fill_in 'Title', with: 'Example Survey'
click_button 'Create Survey'
expect(flash).to eq('Successfully created survey')
fill_in :survey_question_title, with: 'Example question'
select 'boolean', from: 'Type of Question:', visible: false # Hidden by bootstrap-select
click_button 'Create Survey question'
expect(flash).to eq('Successfully created Survey Question.')
end
end
context 'as an attendee' do
let(:attendee) { create(:user) }
before :each do
sign_in attendee
end
scenario 'respond to a survey during registration', feature: true, js: true do
create :registration_period, conference: conference
create :registration, conference: conference, user: attendee
survey = create(:survey, surveyable: conference, target: :during_registration)
create :boolean_mandatory, survey: survey
visit conference_conference_registration_path(conference)
expect(find(:link, survey.title).sibling('.fa')[: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_conference_registration_path(conference)
expect(find(:link, survey.title).sibling('.fa')[:title]).to eq('Thank you for filling out the survey')
end
end
end