From 105fb6c86c58591b243c810874fdd5db69cc3dc1 Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Wed, 20 Dec 2017 01:49:01 -0500 Subject: [PATCH 1/3] Add "Why attend?" question to questionnaire --- app/controllers/manage/questionnaires_controller.rb | 2 +- app/controllers/questionnaires_controller.rb | 2 +- app/models/questionnaire.rb | 1 + .../application/_questionnaire_summary.html.haml | 3 +++ app/views/manage/questionnaires/_form.html.haml | 2 ++ app/views/questionnaires/_form.html.haml | 2 ++ ...0171220042158_add_why_attend_to_questionnaires.rb | 5 +++++ .../manage/questionnaires_controller_test.rb | 6 +++--- test/controllers/questionnaires_controller_test.rb | 12 ++++++------ test/dummy/db/schema.rb | 3 ++- test/factories/questionnaire.rb | 1 + test/models/questionnaire_test.rb | 2 ++ 12 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20171220042158_add_why_attend_to_questionnaires.rb diff --git a/app/controllers/manage/questionnaires_controller.rb b/app/controllers/manage/questionnaires_controller.rb index cce4fc725..c14d22603 100644 --- a/app/controllers/manage/questionnaires_controller.rb +++ b/app/controllers/manage/questionnaires_controller.rb @@ -154,7 +154,7 @@ def questionnaire_params :portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest, :riding_bus, :phone, :can_share_info, :code_of_conduct_accepted, :travel_not_from_school, :travel_location, :data_sharing_accepted, - :resume, :delete_resume, :is_bus_captain + :resume, :delete_resume, :is_bus_captain, :why_attend ) end diff --git a/app/controllers/questionnaires_controller.rb b/app/controllers/questionnaires_controller.rb index a89be17cd..49ae84093 100644 --- a/app/controllers/questionnaires_controller.rb +++ b/app/controllers/questionnaires_controller.rb @@ -128,7 +128,7 @@ def questionnaire_params :portfolio_url, :vcs_url, :agreement_accepted, :bus_captain_interest, :riding_bus, :phone, :can_share_info, :code_of_conduct_accepted, :travel_not_from_school, :travel_location, :data_sharing_accepted, - :resume, :delete_resume + :resume, :delete_resume, :why_attend ) end diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 8bbc209cc..9a41377db 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -7,6 +7,7 @@ class Questionnaire < ApplicationRecord validates_presence_of :first_name, :last_name, :phone, :date_of_birth, :school_id, :experience, :shirt_size, :interest validates_presence_of :gender, :major, :level_of_study + validates_presence_of :why_attend validates_presence_of :agreement_accepted, message: "Must accept" validates_presence_of :code_of_conduct_accepted, message: "Must accept" validates_presence_of :data_sharing_accepted, message: "Must accept" diff --git a/app/views/application/_questionnaire_summary.html.haml b/app/views/application/_questionnaire_summary.html.haml index 8a1585817..0e14f242d 100644 --- a/app/views/application/_questionnaire_summary.html.haml +++ b/app/views/application/_questionnaire_summary.html.haml @@ -1,3 +1,6 @@ +%p + %b Why #{Rails.configuration.hackathon['name']}? +%p= @questionnaire.why_attend %p %b Experience: = Questionnaire::POSSIBLE_EXPERIENCES[@questionnaire.experience] diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index 06ce478cb..bf47a1656 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -29,6 +29,8 @@ .form-inputs %br + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" } diff --git a/app/views/questionnaires/_form.html.haml b/app/views/questionnaires/_form.html.haml index a36d4d632..227313331 100644 --- a/app/views/questionnaires/_form.html.haml +++ b/app/views/questionnaires/_form.html.haml @@ -32,6 +32,8 @@ .wizard-stage .form-inputs + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } diff --git a/db/migrate/20171220042158_add_why_attend_to_questionnaires.rb b/db/migrate/20171220042158_add_why_attend_to_questionnaires.rb new file mode 100644 index 000000000..f3251e724 --- /dev/null +++ b/db/migrate/20171220042158_add_why_attend_to_questionnaires.rb @@ -0,0 +1,5 @@ +class AddWhyAttendToQuestionnaires < ActiveRecord::Migration[5.1] + def change + add_column :questionnaires, :why_attend, :text + end +end diff --git a/test/controllers/manage/questionnaires_controller_test.rb b/test/controllers/manage/questionnaires_controller_test.rb index e53617356..65d2a3802 100644 --- a/test/controllers/manage/questionnaires_controller_test.rb +++ b/test/controllers/manage/questionnaires_controller_test.rb @@ -299,7 +299,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase should "create questionnaire and user" do assert_difference('User.count', 1) do assert_difference('Questionnaire.count', 1) do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @questionnaire.school_id, email: "test@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @questionnaire.school_id, email: "test@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major, why_attend: @questionnaire.why_attend } } end end @@ -311,7 +311,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase create(:user, email: "taken@example.com") assert_difference('User.count', 0) do assert_difference('Questionnaire.count', 0) do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @questionnaire.school_id, email: "taken@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @questionnaire.school_id, email: "taken@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major, why_attend: @questionnaire.why_attend } } end end assert_match /Email has already been taken/, flash[:notice] @@ -321,7 +321,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase should "create school if doesn't exist in questionnaire" do assert_difference('Questionnaire.count', 1) do assert_difference('School.count', 1) do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: "My New School", email: "taken@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: "My New School", email: "taken@example.com", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", gender: @questionnaire.gender, major: @questionnaire.major, why_attend: @questionnaire.why_attend } } end end assert_equal "My New School", assigns(:questionnaire).school.name diff --git a/test/controllers/questionnaires_controller_test.rb b/test/controllers/questionnaires_controller_test.rb index 92c53c2df..2f48a08f0 100644 --- a/test/controllers/questionnaires_controller_test.rb +++ b/test/controllers/questionnaires_controller_test.rb @@ -49,7 +49,7 @@ class QuestionnairesControllerTest < ActionController::TestCase should "create questionnaire" do assert_difference('Questionnaire.count', 1) do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } end assert_redirected_to questionnaires_path @@ -62,8 +62,8 @@ class QuestionnairesControllerTest < ActionController::TestCase should "not allow multiple questionnaires" do assert_difference('Questionnaire.count', 1) do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_id: @school.id, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } end assert_redirected_to questionnaires_path @@ -81,20 +81,20 @@ class QuestionnairesControllerTest < ActionController::TestCase context "#school_name" do context "on create" do should "save existing school name" do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: @school.name, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: @school.name, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } assert_redirected_to questionnaires_path assert_equal 1, School.all.count end should "create a new school when unknown" do - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: "New School", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: "New School", agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } assert_redirected_to questionnaires_path assert_equal 2, School.all.count end should "send confirmation email to questionnaire" do assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size, "no emails should be queued prior to questionnaire creation" - post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: @school.name, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender } } + post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, first_name: @questionnaire.first_name, last_name: @questionnaire.last_name, phone: @questionnaire.phone, level_of_study: @questionnaire.level_of_study, date_of_birth: @questionnaire.date_of_birth, shirt_size: @questionnaire.shirt_size, school_name: @school.name, agreement_accepted: "1", code_of_conduct_accepted: "1", data_sharing_accepted: "1", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend } } assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size, "should email confirmation to questionnaire" end end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 2f0a85e34..cf26a90f8 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170128063020) do +ActiveRecord::Schema.define(version: 20171220042158) do create_table "blazer_audits", id: :integer, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "user_id" @@ -135,6 +135,7 @@ t.integer "resume_file_size" t.datetime "resume_updated_at" t.string "interest" + t.text "why_attend" t.index ["user_id"], name: "index_questionnaires_on_user_id" end diff --git a/test/factories/questionnaire.rb b/test/factories/questionnaire.rb index 89a40af8a..4b4357790 100644 --- a/test/factories/questionnaire.rb +++ b/test/factories/questionnaire.rb @@ -18,6 +18,7 @@ gender "Male" major "Computer Science" level_of_study "University (Undergraduate)" + why_attend "This sounds cool" association :user end diff --git a/test/models/questionnaire_test.rb b/test/models/questionnaire_test.rb index f74b218ea..07fa7d1bc 100644 --- a/test/models/questionnaire_test.rb +++ b/test/models/questionnaire_test.rb @@ -11,6 +11,7 @@ class QuestionnaireTest < ActiveSupport::TestCase should strip_attribute :dietary_restrictions should strip_attribute :special_needs should strip_attribute :travel_location + should strip_attribute :why_attend should validate_presence_of :first_name should validate_presence_of :last_name @@ -22,6 +23,7 @@ class QuestionnaireTest < ActiveSupport::TestCase should validate_presence_of :level_of_study should validate_presence_of :major should validate_presence_of :gender + should validate_presence_of :why_attend should_not validate_presence_of :dietary_restrictions should_not validate_presence_of :special_needs should_not validate_presence_of :resume From d8d4a56744dc7ba02dccd6e272af376b779dce3a Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Fri, 22 Dec 2017 14:07:48 -0500 Subject: [PATCH 2/3] =?UTF-8?q?Make=20=E2=80=9CWhy=20attend=3F=E2=80=9D=20?= =?UTF-8?q?question=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/questionnaire.rb | 5 ++++- .../application/_questionnaire_summary.html.haml | 7 ++++--- app/views/manage/questionnaires/_form.html.haml | 3 ++- app/views/questionnaires/_form.html.haml | 3 ++- lib/hackathon_manager.rb | 5 +++++ .../questionnaires_controller_test.rb | 16 ++++++++++++++++ test/dummy/config/hackathon.yml | 2 ++ 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index 9a41377db..5785ca4ff 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -7,11 +7,14 @@ class Questionnaire < ApplicationRecord validates_presence_of :first_name, :last_name, :phone, :date_of_birth, :school_id, :experience, :shirt_size, :interest validates_presence_of :gender, :major, :level_of_study - validates_presence_of :why_attend validates_presence_of :agreement_accepted, message: "Must accept" validates_presence_of :code_of_conduct_accepted, message: "Must accept" validates_presence_of :data_sharing_accepted, message: "Must accept" + if HackathonManager.field_enabled?(:why_attend) + validates_presence_of :why_attend + end + has_attached_file :resume validates_attachment_content_type :resume, content_type: %w[application/pdf], message: "Invalid file type" validates_attachment_size :resume, in: 0..2.megabytes, message: "File size is too big" diff --git a/app/views/application/_questionnaire_summary.html.haml b/app/views/application/_questionnaire_summary.html.haml index 0e14f242d..200a0c3a3 100644 --- a/app/views/application/_questionnaire_summary.html.haml +++ b/app/views/application/_questionnaire_summary.html.haml @@ -1,6 +1,7 @@ -%p - %b Why #{Rails.configuration.hackathon['name']}? -%p= @questionnaire.why_attend +- if HackathonManager.field_enabled?(:why_attend) + %p + %b Why #{Rails.configuration.hackathon['name']}? + %p= @questionnaire.why_attend %p %b Experience: = Questionnaire::POSSIBLE_EXPERIENCES[@questionnaire.experience] diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index bf47a1656..d864be541 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -29,7 +29,8 @@ .form-inputs %br - = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + - if HackathonManager.field_enabled?(:why_attend) + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" } diff --git a/app/views/questionnaires/_form.html.haml b/app/views/questionnaires/_form.html.haml index 227313331..7140ca36d 100644 --- a/app/views/questionnaires/_form.html.haml +++ b/app/views/questionnaires/_form.html.haml @@ -32,7 +32,8 @@ .wizard-stage .form-inputs - = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + - if HackathonManager.field_enabled?(:why_attend) + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } diff --git a/lib/hackathon_manager.rb b/lib/hackathon_manager.rb index 964188761..eea62eadb 100644 --- a/lib/hackathon_manager.rb +++ b/lib/hackathon_manager.rb @@ -12,4 +12,9 @@ def self.reload_config(app) app.config.hackathon = hackathon end + + def self.field_enabled?(field) + disabled_fields = Rails.configuration.hackathon['disabled_fields'] || [] + !disabled_fields.include?(field.to_s) + end end diff --git a/test/controllers/questionnaires_controller_test.rb b/test/controllers/questionnaires_controller_test.rb index 2f48a08f0..b26bfff6a 100644 --- a/test/controllers/questionnaires_controller_test.rb +++ b/test/controllers/questionnaires_controller_test.rb @@ -99,6 +99,22 @@ class QuestionnairesControllerTest < ActionController::TestCase end end end + + context "disabled fields are enabled" do + should "display why_attend field" do + get :new + assert_select '#questionnaire_why_attend', 1 + end + end + + context "disabled fields are disabled" do + should "not display why_attend field when disabled" do + HackathonManager.stub :field_enabled?, false do + get :new + end + assert_select '#questionnaire_why_attend', 0 + end + end end context "while authenticated with a completed questionnaire" do diff --git a/test/dummy/config/hackathon.yml b/test/dummy/config/hackathon.yml index 1c89df62a..d268d7cfb 100644 --- a/test/dummy/config/hackathon.yml +++ b/test/dummy/config/hackathon.yml @@ -12,6 +12,8 @@ defaults: &defaults email_from: '"HackFoo" ' default_page_title: HackFoo - Jan 1-2, 2017 + # disabled_fields: + # - why_attend # disclaimer: | # Message that appears before signing up & applying. Supports markdown. # thanks_for_applying: | From 095a77f55b5ecedd1346ad621c334d36e008910e Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Fri, 22 Dec 2017 22:14:00 -0500 Subject: [PATCH 3/3] Use hackathon name from config --- app/views/manage/questionnaires/_form.html.haml | 2 +- app/views/questionnaires/_form.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/manage/questionnaires/_form.html.haml b/app/views/manage/questionnaires/_form.html.haml index d864be541..cb3ea80da 100644 --- a/app/views/manage/questionnaires/_form.html.haml +++ b/app/views/manage/questionnaires/_form.html.haml @@ -30,7 +30,7 @@ .form-inputs %br - if HackathonManager.field_enabled?(:why_attend) - = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend #{Rails.configuration.hackathon['name']}?", input_html: { rows: 3, maxlength: 280 } = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" } diff --git a/app/views/questionnaires/_form.html.haml b/app/views/questionnaires/_form.html.haml index 7140ca36d..daf0e5acb 100644 --- a/app/views/questionnaires/_form.html.haml +++ b/app/views/questionnaires/_form.html.haml @@ -33,7 +33,7 @@ .wizard-stage .form-inputs - if HackathonManager.field_enabled?(:why_attend) - = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend BrickHack?", input_html: { rows: 3, maxlength: 280 } + = f.input :why_attend, label: "Why #{Rails.configuration.hackathon['name']}?", placeholder: "In a sentence or two, why would you like to attend #{Rails.configuration.hackathon['name']}?", input_html: { rows: 3, maxlength: 280 } = f.input :experience, as: :select, collection: Questionnaire::POSSIBLE_EXPERIENCES.invert, include_blank: "(select one...)", label: "Experience", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' } = f.input :interest, as: :select, collection: Questionnaire::POSSIBLE_INTERESTS.invert, include_blank: "(select one...)", label: "Interest", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }