Skip to content

feat(questionnaire): add country field for questionnaire #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 3, 2021
Merged
2 changes: 1 addition & 1 deletion app/controllers/questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def questionnaire_params
params.require(:questionnaire).permit(
:email, :experience, :gender,
:date_of_birth, :interest, :school_id, :school_name, :major, :level_of_study,
:shirt_size, :dietary_restrictions, :special_needs, :international,
:shirt_size, :dietary_restrictions, :special_needs, :international, :country,
:portfolio_url, :vcs_url, :bus_captain_interest,
:phone, :can_share_info, :travel_not_from_school, :travel_location,
:graduation_year, :race_ethnicity, :resume, :delete_resume, :why_attend, agreement_ids: []
Expand Down
199 changes: 198 additions & 1 deletion app/models/questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class Questionnaire < ApplicationRecord

include ActiveModel::Dirty
include DeletableAttachment

before_validation :consolidate_school_names
before_validation :clean_for_non_rsvp
before_validation :clean_negative_special_needs
Expand All @@ -24,6 +23,7 @@ class Questionnaire < ApplicationRecord

validates_presence_of :phone, :date_of_birth, :school_id, :experience, :shirt_size, :interest
validates_presence_of :gender, :major, :level_of_study, :graduation_year, :race_ethnicity
validates :country, presence: { message: %[information is missing from application. Please update your <a href="#{Rails.application.routes.url_helpers.edit_questionnaires_path}">Application</a>] }

DIETARY_SPECIAL_NEEDS_MAX_LENGTH = 500
validates_length_of :dietary_restrictions, maximum: DIETARY_SPECIAL_NEEDS_MAX_LENGTH
Expand Down Expand Up @@ -121,6 +121,203 @@ class Questionnaire < ApplicationRecord
"Other"
].freeze

POSSIBLE_COUNTRIES = [
"United States",
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
"Belgium",
"Belize",
"Benin",
"Bhutan",
"Bolivia",
"Bosnia and Herzegovina",
"Botswana",
"Brazil",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Cameroon",
"Canada",
"Cape Verde",
"Central African Republic",
"Chad",
"Chile",
"China",
"Colombia",
"Comoros",
"Congo, Democratic Republic of the Congo",
"Congo, Republic of the",
"Costa Rica",
"Cote d'Ivoire (Ivory Coast)",
"Croatia",
"Cuba",
"Cyprus",
"Czech Republic",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"Timor-Leste (East Timor)",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Estonia",
"Ethiopia",
"Fiji",
"Finland",
"France",
"Gabon",
"Gambia, The",
"Georgia",
"Germany",
"Ghana",
"Greece",
"Grenada",
"Guatemala",
"Guinea",
"Guinea-Bissau",
"Guyana",
"Haiti",
"Honduras",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Korea, North",
"Korea, South",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macedonia, North",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",
"Mauritius",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Morocco",
"Mozambique",
"Myanmar",
"Namibia",
"Nauru",
"Nepal",
"Netherlands",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"Norway",
"Oman",
"Pakistan",
"Palau",
"Panama",
"Papua New Guinea",
"Paraguay",
"Peru",
"Philippines",
"Poland",
"Portugal",
"Qatar",
"Romania",
"Russia",
"Rwanda",
"Saint Kitts and Nevis",
"Saint Lucia",
"Saint Vincent",
"Samoa",
"San Marino",
"Sao Tome and Principe",
"Saudi Arabia",
"Senegal",
"Serbia and Montenegro",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"South Sudan",
"Spain",
"Sri Lanka",
"Sudan",
"Suriname",
"Swaziland",
"Sweden",
"Switzerland",
"Syria",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tonga",
"Trinidad and Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Tuvalu",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Vatican City",
"Venezuela",
"Vietnam",
"Yemen",
"Zambia",
"Zimbabwe"
].freeze

validates_inclusion_of :experience, in: POSSIBLE_EXPERIENCES
validates_inclusion_of :interest, in: POSSIBLE_INTERESTS
# validates_inclusion_of :school_id, :in => School.select(:id)
Expand Down
10 changes: 10 additions & 0 deletions app/views/application/_missing_country_notice.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.alert#disclaimer
%h1.section-title
%span.emphasized.fa.fa-exclamation-circle
Missing
%span.emphasized Country Information
%p
You have not provided the country you are hacking from. Please
%strong
#{link_to "edit your application", edit_questionnaires_path}
and specify your country.
1 change: 1 addition & 0 deletions app/views/manage/questionnaires/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
= f.input :level_of_study, input_html: { "data-validate" => "presence" }
= f.input :major, input_html: { "data-validate" => "presence" }
= f.input :gender, input_html: { "data-validate" => "presence" }
= f.input :country, as: :select, collection: Questionnaire::POSSIBLE_COUNTRIES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }

- if !HackathonConfig['digital_hackathon']
.card.mb-4
Expand Down
2 changes: 2 additions & 0 deletions app/views/manage/questionnaires/_overview.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
= @questionnaire.age_at_time_of_event / 1.year
%dt.col-md-4 Gender
%dd.col-md-8= @questionnaire.gender
%dt.col-md-4 Country
%dd.col-md-8= @questionnaire.country

= render 'checkin_compliance_card'

Expand Down
1 change: 1 addition & 0 deletions app/views/questionnaires/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

= f.input :graduation_year, as: :select, collection: Questionnaire::POSSIBLE_GRAD_YEARS, include_blank: "(select one...)", label: "Graduation year", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
= f.input :race_ethnicity, as: :select, collection: Questionnaire::POSSIBLE_RACE_ETHNICITIES, include_blank: "(select one...)", label: "Race/Ethnicity", input_html: { "data-validate" => "presence" }, wrapper_html: { class: 'input--half' }
= f.input :country, as: :select, collection: Questionnaire::POSSIBLE_COUNTRIES, include_blank: "(select one...)", input_html: { "data-validate" => "presence" }

= f.input :portfolio_url, label: "Portfolio link", placeholder: "http://mywebsite.com"
= f.input :vcs_url, label: "GitHub/GitLab/Bitbucket link", placeholder: "https://github.com/coderit"
Expand Down
2 changes: 2 additions & 0 deletions app/views/questionnaires/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.form-container
- if @questionnaire.unaccepted_agreements.any?
= render partial: 'unaccepted_agreements_notice'
- if @questionnaire.country.blank?
= render partial: 'missing_country_notice'
.form-container
#disclaimer
%h1.section-title
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20210130175752_add_country_to_questionnaires.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCountryToQuestionnaires < ActiveRecord::Migration[5.2]
def change
add_column :questionnaires, :country, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_01_28_025749) do
ActiveRecord::Schema.define(version: 2021_01_30_175752) do

create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -257,6 +257,7 @@
t.integer "graduation_year"
t.string "race_ethnicity"
t.integer "bus_list_id"
t.string "country"
t.index ["bus_list_id"], name: "index_questionnaires_on_bus_list_id"
t.index ["user_id"], name: "index_questionnaires_on_user_id"
end
Expand Down
14 changes: 7 additions & 7 deletions test/controllers/questionnaires_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
end

assert_redirected_to questionnaires_path
Expand All @@ -60,8 +60,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, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
end

assert_redirected_to questionnaires_path
Expand All @@ -80,21 +80,21 @@ class QuestionnairesControllerTest < ActionController::TestCase
should "not allow creation" do
HackathonConfig['accepting_questionnaires'] = false
assert_difference('Questionnaire.count', 0) do
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
end
end
end

context "#school_name" do
context "on create" do
should "save existing school name" do
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
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, 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", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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", major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
assert_redirected_to questionnaires_path
assert_equal 2, School.all.count
end
Expand All @@ -103,7 +103,7 @@ class QuestionnairesControllerTest < ActionController::TestCase
message = create(:message, type: 'automated', trigger: "questionnaire.pending")
assert_difference 'enqueued_jobs.size', 1 do
assert_difference 'Questionnaire.count', 1 do
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
post :create, params: { questionnaire: { experience: @questionnaire.experience, interest: @questionnaire.interest, country: @questionnaire.country, 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, major: @questionnaire.major, gender: @questionnaire.gender, why_attend: @questionnaire.why_attend, graduation_year: @questionnaire.graduation_year, race_ethnicity: @questionnaire.race_ethnicity, agreement_ids: @questionnaire.agreements.map(&:id) } }
end
end
questionnaire = Questionnaire.last
Expand Down
1 change: 1 addition & 0 deletions test/factories/questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
special_needs { "" }
can_share_info { true }
gender { "Male" }
country { "United States" }
major { "Computer Science" }
level_of_study { "University (Undergraduate)" }
graduation_year { Date.today.year }
Expand Down