From 51e65003bd5dee264480e5a05cd04664c02fe249 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:04:55 -0800 Subject: [PATCH 1/7] Add failing tests for survey creation and response Removes optional attributes from default survey factory. --- spec/factories/surveys.rb | 2 -- spec/features/surveys_spec.rb | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 spec/features/surveys_spec.rb diff --git a/spec/factories/surveys.rb b/spec/factories/surveys.rb index cf44f7ed..c95a9d27 100644 --- a/spec/factories/surveys.rb +++ b/spec/factories/surveys.rb @@ -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 diff --git a/spec/features/surveys_spec.rb b/spec/features/surveys_spec.rb new file mode 100644 index 00000000..927c23fc --- /dev/null +++ b/spec/features/surveys_spec.rb @@ -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 From c0525160096c9a9fbcf95ca327e90c402a9b46eb Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:11:54 -0800 Subject: [PATCH 2/7] Grant conference organizers permission to manage surveys Resolves: Failures: 1) Survey as an organizer create a survey Failure/Error: click_link 'New' Capybara::ElementNotFound: Unable to find link "New" # ./spec/features/surveys_spec.rb:18:in `block (3 levels) in ' Failed examples: rspec ./spec/features/surveys_spec.rb:15 # Survey as an organizer create a survey --- .rubocop_todo.yml | 2 +- app/models/admin_ability.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0d9a6f13..4d7b21ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 19d6c4d3..4046d29f 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -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 From 58b1440cddebfbd512146d857c855de597b3528f Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:19:03 -0800 Subject: [PATCH 3/7] Add missing view for survey question creation Resolves: Failures: 1) Survey as an organizer create a survey Failure/Error: raise ActionController::MissingExactTemplate, message ActionController::MissingExactTemplate: Admin::SurveyQuestionsController#new is missing a template for request formats: text/html # :90:in `tap' Failed examples: rspec ./spec/features/surveys_spec.rb:15 # Survey as an organizer create a survey --- app/views/admin/survey_questions/new.html.haml | 1 + 1 file changed, 1 insertion(+) create mode 100644 app/views/admin/survey_questions/new.html.haml diff --git a/app/views/admin/survey_questions/new.html.haml b/app/views/admin/survey_questions/new.html.haml new file mode 100644 index 00000000..72992799 --- /dev/null +++ b/app/views/admin/survey_questions/new.html.haml @@ -0,0 +1 @@ += render partial: 'form' From d1a0167969f71c2feaffeb19fc1320f0e8b32ffa Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Wed, 16 Mar 2022 13:58:48 -0700 Subject: [PATCH 4/7] Correct failure to enable survey date pickers Resolves: app/views/admin/surveys/_form.html.haml:25: warning: key :class is duplicated and overwritten on line 25 app/views/admin/surveys/_form.html.haml:27: warning: key :class is duplicated and overwritten on line 27 --- app/views/admin/surveys/_form.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/surveys/_form.html.haml b/app/views/admin/surveys/_form.html.haml index ef35538f..b03022ab 100644 --- a/app/views/admin/surveys/_form.html.haml +++ b/app/views/admin/surveys/_form.html.haml @@ -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' From 3e7be525860473805a66db6ac6d030f99d52e6cb Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:23:46 -0800 Subject: [PATCH 5/7] Associate form label with its control Resolves: Failures: 1) Survey as an organizer create a survey Failure/Error: select 'boolean', from: 'Type of Question:', visible: false # Hidden by bootstrap-select Capybara::ElementNotFound: Unable to find select box "Type of Question:" that is not disabled and Unable to find input box with datalist completion "Type of Question:" that is not disabled # ./spec/features/surveys_spec.rb:24:in `block (3 levels) in ' # ------------------ # --- Caused by: --- # Capybara::ElementNotFound: # Unable to find select box "Type of Question:" that is not disabled # ./spec/features/surveys_spec.rb:24:in `block (3 levels) in ' Failed examples: rspec ./spec/features/surveys_spec.rb:15 # Survey as an organizer create a survey --- app/views/admin/survey_questions/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/survey_questions/_form.html.haml b/app/views/admin/survey_questions/_form.html.haml index a4e1eea6..0cde22c5 100644 --- a/app/views/admin/survey_questions/_form.html.haml +++ b/app/views/admin/survey_questions/_form.html.haml @@ -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]' } From b565be2f46763e72e34ba02ba59fe74b339c4692 Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:44:48 -0800 Subject: [PATCH 6/7] Correct assumption of survey start and end dates The logic used for the `:reply` ability incompletely duplicated that of `Survey#active?` and incorrectly assumed that surveys always have start and end dates. Resolves: Failures: 1) Survey as an attendee respond to a survey during registration Failure/Error: survey.start_date > Time.current || survey.end_date < Time.current ActionView::Template::Error: undefined method `>' for nil:NilClass survey.start_date > Time.current || survey.end_date < Time.current ^ # ./app/models/ability.rb:126:in `block in signed_in' # ./app/views/surveys/show.html.haml:28:in `block in _app_views_surveys_show_html_haml___3404959267043700678_138180' # ./app/views/surveys/show.html.haml:19:in `_app_views_surveys_show_html_haml___3404959267043700678_138180' Failed examples: rspec ./spec/features/surveys_spec.rb:37 # Survey as an attendee respond to a survey during registration --- app/models/ability.rb | 4 +--- app/models/survey.rb | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index caf8f2a4..4fc5ae34 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/app/models/survey.rb b/app/models/survey.rb index 50e251a7..66783e90 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -32,4 +32,8 @@ class Survey < ActiveRecord::Base now <= end_date end end + + def closed? + !active? + end end From 02dc5011fe8e1553f09432d6b1839ba7e563ef6a Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 11 Mar 2022 11:35:19 -0800 Subject: [PATCH 7/7] Show feedback upon survey response Resolves: Failures: 1) Survey as an attendee respond to a survey during registration Failure/Error: expect(flash).to eq('Successfully responded to survey.') expected: "Successfully responded to survey." got: "none" (compared using ==) # ./spec/features/surveys_spec.rb:49:in `block (3 levels) in ' Failed examples: rspec ./spec/features/surveys_spec.rb:37 # Survey as an attendee respond to a survey during registration --- app/controllers/surveys_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index fdf24963..a5c9fd0d 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -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