Merge pull request #2969 from AndrewKvalheim/test-survey-create-and-respond
Basic feature test of survey creation and response
This commit is contained in:
commit
db22aa27a0
10 changed files with 70 additions and 10 deletions
|
|
@ -426,7 +426,7 @@ Lint/UriRegexp:
|
||||||
# Offense count: 127
|
# Offense count: 127
|
||||||
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 71
|
Max: 72
|
||||||
|
|
||||||
# Offense count: 313
|
# Offense count: 313
|
||||||
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,6 @@ class SurveysController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_back(fallback_location: root_path)
|
redirect_back(fallback_location: root_path, notice: 'Successfully responded to survey.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -122,9 +122,7 @@ class Ability
|
||||||
# if not, do not allow replies.
|
# if not, do not allow replies.
|
||||||
|
|
||||||
# do not allow replies before the start_date or after the end_date of survey
|
# do not allow replies before the start_date or after the end_date of survey
|
||||||
cannot :reply, Survey do |survey|
|
cannot :reply, Survey, &:closed?
|
||||||
survey.start_date > Time.current || survey.end_date < Time.current
|
|
||||||
end
|
|
||||||
|
|
||||||
can [:destroy], Openid
|
can [:destroy], Openid
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,10 @@ class AdminAbility
|
||||||
can :manage, Room, venue: { conference_id: conf_ids }
|
can :manage, Room, venue: { conference_id: conf_ids }
|
||||||
can :manage, Sponsor, conference_id: conf_ids
|
can :manage, Sponsor, conference_id: conf_ids
|
||||||
can :manage, SponsorshipLevel, 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 :manage, Ticket, conference_id: conf_ids
|
||||||
can :create, TicketScanning do |ticket_scanning|
|
can :create, TicketScanning do |ticket_scanning|
|
||||||
conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id
|
conf_id = ticket_scanning.physical_ticket.ticket_purchase.conference_id
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,8 @@ class Survey < ActiveRecord::Base
|
||||||
now <= end_date
|
now <= end_date
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def closed?
|
||||||
|
!active?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
= f.label :max_choices
|
= f.label :max_choices
|
||||||
= f.number_field :max_choices, class: 'form-control'
|
= f.number_field :max_choices, class: 'form-control'
|
||||||
.form-group
|
.form-group
|
||||||
%label{ required: 'required' }
|
%label{ for: 'survey_question_kind', required: 'required' }
|
||||||
Type of Question:
|
Type of Question:
|
||||||
.form-group
|
.form-group
|
||||||
%select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' }
|
%select.selectpicker.form-control{ id: 'survey_question_kind', name: 'survey_question[kind]' }
|
||||||
|
|
|
||||||
1
app/views/admin/survey_questions/new.html.haml
Normal file
1
app/views/admin/survey_questions/new.html.haml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
= render partial: 'form'
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
= f.select :target, Survey.targets.keys, class: 'form-control'
|
= f.select :target, Survey.targets.keys, class: 'form-control'
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :start_date
|
= 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.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'
|
= f.submit nil, class: 'btn btn-primary'
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :survey do
|
factory :survey do
|
||||||
title { 'This is my survey' }
|
title { 'This is my survey' }
|
||||||
start_date { Date.current - 1.day }
|
|
||||||
end_date { Date.current + 1.day }
|
|
||||||
|
|
||||||
factory :conference_survey do
|
factory :conference_survey do
|
||||||
association :surveyable, factory: :conference
|
association :surveyable, factory: :conference
|
||||||
|
|
|
||||||
55
spec/features/surveys_spec.rb
Normal file
55
spec/features/surveys_spec.rb
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue