From f2ee4d2b966a9a1907eb402b76b15bff90776f9f Mon Sep 17 00:00:00 2001 From: razztech Date: Thu, 7 Mar 2024 19:41:38 -0800 Subject: [PATCH 01/63] Added frontend + db logic for country field in international schools --- Gemfile | 3 +++ Gemfile.lock | 6 +++++ app/controllers/schools_controller.rb | 6 ++--- app/controllers/teachers_controller.rb | 4 +-- app/models/school.rb | 8 +++--- app/views/schools/_form.html.erb | 27 ++++++++++++++++++- .../20240307225738_add_country_to_schools.rb | 5 ++++ db/schema.rb | 3 ++- spec/fixtures/schools.yml | 1 + 9 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20240307225738_add_country_to_schools.rb diff --git a/Gemfile b/Gemfile index 4e87cca0..0b73d21e 100644 --- a/Gemfile +++ b/Gemfile @@ -49,6 +49,9 @@ gem "activerecord-import", require: false gem "httparty", "~> 0.21.0" + +gem "country_select", "~> 8.0" + group :development do gem "annotate" diff --git a/Gemfile.lock b/Gemfile.lock index 47f889a5..24ef2246 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -140,6 +140,10 @@ GEM coercible (1.0.0) descendants_tracker (~> 0.0.1) concurrent-ruby (1.2.3) + countries (5.7.2) + unaccent (~> 0.3) + country_select (8.0.3) + countries (~> 5.0) crass (1.0.6) cucumber (7.1.0) builder (~> 3.2, >= 3.2.4) @@ -528,6 +532,7 @@ GEM concurrent-ruby (~> 1.0) tzinfo-data (1.2021.5) tzinfo (>= 1.0.0) + unaccent (0.4.0) unicode-display_width (2.4.2) version_gem (1.1.3) virtus (2.0.0) @@ -563,6 +568,7 @@ DEPENDENCIES axe-core-cucumber axe-core-rspec bootsnap (>= 1.4.4) + country_select (~> 8.0) cucumber-rails database_cleaner debug diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 001e9606..0ea311f1 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -12,11 +12,11 @@ def show end def search - School.all.collect { |school| ["#{school.name}, #{school.city}, #{school.state}", school.name] } + School.all.collect { |school| ["#{school.name}, #{school.country}, #{school.city}, #{school.state}", school.name] } end def create - @school = School.find_by(name: school_params[:name], city: school_params[:city], state: school_params[:state]) + @school = School.find_by(name: school_params[:name], country: school_params[:country], city: school_params[:city], state: school_params[:state]) if @school @school.assign_attributes(school_params) else @@ -64,7 +64,7 @@ def destroy private def school_params - params.require(:school).permit(:name, :city, :state, :website, :grade_level, :school_type, { tags: [] }, :nces_id) + params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type, :country, { tags: [] }, :nces_id) end def load_ordered_schools diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index d6f0a5a1..e96597f5 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -189,7 +189,7 @@ def load_school if teacher_params[:school_id].present? @school ||= School.find(teacher_params[:school_id]) end - @school ||= School.find_or_create_by(name: school_params[:name], city: school_params[:city], state: school_params[:state]) + @school ||= School.find_or_create_by(name: school_params[:name], city: school_params[:city], country: school_params[:country], state: school_params[:state]) end def teacher_params @@ -203,7 +203,7 @@ def teacher_params def school_params return unless params[:school] - params.require(:school).permit(:name, :city, :state, :website, :grade_level, :school_type) + params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type) end def omniauth_data diff --git a/app/models/school.rb b/app/models/school.rb index 82eaf4ff..8c109351 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -6,6 +6,7 @@ # # id :integer not null, primary key # city :string +# country :string # grade_level :integer # lat :float # lng :float @@ -25,10 +26,11 @@ # class School < ApplicationRecord - VALID_STATES = [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY", "International"].freeze + VALID_STATES = [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"].freeze - validates :state, inclusion: { in: VALID_STATES } - validates :name, :city, :state, :website, presence: true + validates :name, :city, :website, :country, presence: true + validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "United States" } + validates :state, presence: true, if: -> { country == "United States" } validates_format_of :website, with: /.+\..+/, on: :create before_save :update_gps_data, if: -> { lat.nil? || lng.nil? } diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index 8b46ae1c..489e9218 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -5,6 +5,16 @@ <%= f.text_field :name, placeholder: 'UC Berkeley', class: 'form-control', required: false, id: 'school_name' %> + +
+
+ <%= f.label :country, "Country", class: "label-required", for: "school_country" %> + <%= f.country_select( + :country, + { priority_countries: ['United States'], include_blank: "Select an option" }, + { class: 'form-control', required: true, id: 'school_country', format: :with_full_country_name} + ) %> +
<%= f.label :city, class: "label-required", for: "school_city" %> @@ -12,7 +22,7 @@ required: false, id: 'school_city' %>
-
+
<%= f.label :state, class: "label-required", for: "school_state" %> <%= f.select( :state, @@ -88,3 +98,18 @@ class: "form-control", title: "Please enter a valid NCES ID.", id: "school_nces_id" %>
<%- end %> + + diff --git a/db/migrate/20240307225738_add_country_to_schools.rb b/db/migrate/20240307225738_add_country_to_schools.rb new file mode 100644 index 00000000..ee25792d --- /dev/null +++ b/db/migrate/20240307225738_add_country_to_schools.rb @@ -0,0 +1,5 @@ +class AddCountryToSchools < ActiveRecord::Migration[6.1] + def change + add_column :schools, :country, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index acd0374a..a9927666 100644 --- a/db/schema.rb +++ b/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: 2024_02_20_192015) do +ActiveRecord::Schema.define(version: 2024_03_07_225738) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -96,6 +96,7 @@ t.integer "school_type" t.text "tags", default: [], array: true t.string "nces_id" + t.string "country" t.index ["name", "city", "website"], name: "index_schools_on_name_city_and_website" end diff --git a/spec/fixtures/schools.yml b/spec/fixtures/schools.yml index 1f4816ce..e33bb16f 100644 --- a/spec/fixtures/schools.yml +++ b/spec/fixtures/schools.yml @@ -4,6 +4,7 @@ # # id :integer not null, primary key # city :string +# country :string # grade_level :integer # lat :float # lng :float From 100025064f5b5283ec6826a162cc4e0994f15508 Mon Sep 17 00:00:00 2001 From: razztech Date: Fri, 8 Mar 2024 11:46:19 -0800 Subject: [PATCH 02/63] Added some new frontend logic --- app/models/school.rb | 2 +- app/views/schools/_form.html.erb | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index 8c109351..c9709cc8 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -29,7 +29,7 @@ class School < ApplicationRecord VALID_STATES = [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"].freeze validates :name, :city, :website, :country, presence: true - validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "United States" } + validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "United States" } validates :state, presence: true, if: -> { country == "United States" } validates_format_of :website, with: /.+\..+/, on: :create diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index 489e9218..00288a19 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -22,7 +22,7 @@ required: false, id: 'school_city' %>
-
+
<%= f.label :state, class: "label-required", for: "school_state" %> <%= f.select( :state, @@ -31,6 +31,13 @@ { class: 'form-control', required: false, id: 'school_state'} ) %>
+
+ <%= f.label :state, for: "school_state" %> + <%= f.text_field( + :state, placeholder: "State", + class: 'form-control' + ) %> +
@@ -102,14 +109,16 @@ From 277e4dea37f8bbff6dbfd6294a1610fbc0aaaaff Mon Sep 17 00:00:00 2001 From: razztech Date: Sun, 10 Mar 2024 20:50:33 -0700 Subject: [PATCH 03/63] Made changes to UI logic and updated tests --- app/models/school.rb | 4 +- app/views/schools/_form.html.erb | 45 ++++++++------ features/admin.feature | 40 ++++++------ features/school_form_submission.feature | 6 +- features/teacher.feature | 67 +++++++++++---------- spec/controllers/schools_controller_spec.rb | 10 +++ spec/controllers/teachers_signup_spec.rb | 1 + 7 files changed, 97 insertions(+), 76 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index c9709cc8..b9599163 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -29,8 +29,8 @@ class School < ApplicationRecord VALID_STATES = [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"].freeze validates :name, :city, :website, :country, presence: true - validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "United States" } - validates :state, presence: true, if: -> { country == "United States" } + validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "US" } + validates :state, presence: true, if: -> { country == "US" } validates_format_of :website, with: /.+\..+/, on: :create before_save :update_gps_data, if: -> { lat.nil? || lng.nil? } diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index 00288a19..b44d09be 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -22,21 +22,14 @@ required: false, id: 'school_city' %>
-
+
<%= f.label :state, class: "label-required", for: "school_state" %> - <%= f.select( - :state, - School::VALID_STATES, - { include_blank: "State" }, - { class: 'form-control', required: false, id: 'school_state'} - ) %> + <%= f.select :state, School::VALID_STATES, { include_blank: "State" }, { id: "state_select", class: 'form-control' } %>
+
<%= f.label :state, for: "school_state" %> - <%= f.text_field( - :state, placeholder: "State", - class: 'form-control' - ) %> + <%= f.text_field :state, placeholder: "State", class: 'form-control', id: "state_textfield" %>
@@ -108,17 +101,33 @@ diff --git a/features/admin.feature b/features/admin.feature index 3c066a9f..77bf135a 100644 --- a/features/admin.feature +++ b/features/admin.feature @@ -76,8 +76,8 @@ Feature: basic admin functionality Scenario: Edit teacher info as an admin Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | alonzo | @@ -96,8 +96,8 @@ Feature: basic admin functionality Scenario: Deny teacher as an admin Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -118,8 +118,8 @@ Feature: basic admin functionality Scenario: Not logged in should not have access to edit Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -128,8 +128,8 @@ Feature: basic admin functionality Scenario: Filter all teacher info as an admin Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | application_status | | Victor | Validateme | false | testteacher1@berkeley.edu | UC Berkeley | Validated | @@ -152,8 +152,8 @@ Feature: basic admin functionality Scenario: View teacher info as an admin Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | | Joseph | Test | false | testteacher@berkeley.edu | UC Berkeley | alonzo | @@ -173,8 +173,8 @@ Feature: basic admin functionality Scenario: Edit teacher info as an admin navigating from view only page to edit page Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | | Joseph | Mamoa New | false | testteacher@berkeley.edu | UC Berkeley | alonzo | @@ -197,8 +197,8 @@ Feature: basic admin functionality Scenario: Should be able to resend welcome email Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | application_status | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | alonzo | validated | @@ -234,8 +234,8 @@ Feature: basic admin functionality Scenario: Request information from a teacher as an admin Given the following schools exist: - | name | city | state | website | grade_level | school_type | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | university | public | + | name | country | city | state | website | grade_level | school_type | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | university | public | And the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -257,8 +257,8 @@ Feature: basic admin functionality # Scenario: Admin can import csv file. The loader should filter invalid record and create associate school. # Given the following schools exist: -# | name | city | state | website | -# | UC Berkeley | Berkeley | CA | https://bjc.berkeley.edu | +# | name | country | city | state | website | +# | UC Berkeley | US | Berkeley | CA | https://bjc.berkeley.edu | # Given I am on the BJC home page # Given I have an admin email # And I follow "Log In" @@ -287,8 +287,8 @@ Feature: basic admin functionality # Scenario: Importing with new schools model fields works # Given the following schools exist: -# | name | city | state | website | -# | UC Berkeley | Berkeley | CA | https://bjc.berkeley.edu | +# | name | country | city | state | website | +# | UC Berkeley | US | Berkeley | CA | https://bjc.berkeley.edu | # Given I am on the BJC home page # Given I have an admin email # And I follow "Log In" diff --git a/features/school_form_submission.feature b/features/school_form_submission.feature index 11371a11..72f25db6 100644 --- a/features/school_form_submission.feature +++ b/features/school_form_submission.feature @@ -5,9 +5,9 @@ Feature: view schools Scenario: Viewing the schools page should show the all current schools Given the following schools exist: - | name | city | state | website | - | UC Irvine | Irvine | CA | https://www.uci.edu | - | UC Scam Diego | La Jolla | CA | https://www.ucsd.edu | + | name | country | city | state | website | + | UC Irvine | US | Irvine | CA | https://www.uci.edu | + | UC Scam Diego | US | La Jolla | CA | https://www.ucsd.edu | And the following teachers exist: | first_name | last_name | admin | email | school | | Admin | User | true | testadminuser@berkeley.edu | UC Berkeley | diff --git a/features/teacher.feature b/features/teacher.feature index 2e89c0ee..d4ef8a64 100644 --- a/features/teacher.feature +++ b/features/teacher.feature @@ -23,9 +23,9 @@ Scenario: Logging in as a teacher Scenario: Logging in as a teacher with Google account should be able to edit their info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | - | Cupertino High School | Cupertino | CA | https://chs.fuhsd.org | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | + | Cupertino High School | US | Cupertino | CA | https://chs.fuhsd.org | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -48,8 +48,8 @@ Scenario: Logging in as a teacher with Google account should be able to edit the Scenario: Logging in as a teacher with Microsoft account should be able to edit their info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -62,8 +62,8 @@ Scenario: Logging in as a teacher with Microsoft account should be able to edit Scenario: Logging in as a teacher with Snap account should be able to edit their info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -76,8 +76,8 @@ Scenario: Logging in as a teacher with Snap account should be able to edit their Scenario: Logging in as a teacher with Clever account should be able to edit their info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | school | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | @@ -90,8 +90,8 @@ Scenario: Logging in as a teacher with Snap account should be able to edit their Scenario: Logged in teacher with Not_Reviewed application status can update their info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | alonzo | @@ -106,6 +106,7 @@ Scenario: Logged in teacher with Not_Reviewed application status can update thei And I set my education level target as "High School" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school And I fill in the following: + | Country | US | | City | Cupertino | | State | CA | | School Website | https://chs.fuhsd.org | @@ -118,8 +119,8 @@ Scenario: Logged in teacher with Not_Reviewed application status can update thei # TODO: Should this test updating to a new school? Scenario: Logged in teacher with not_reviewed status cannot change Snap from new form path Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | school | snap | | Joseph | Mamoa | false | testteacher@berkeley.edu | UC Berkeley | alonzo | @@ -143,8 +144,8 @@ Scenario: Logged in teacher with Not_Reviewed application status can update thei Scenario: Logged in teacher can only edit their own information Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | | Joseph | Mamoa | false | testteacher@berkeley.edu | @@ -158,8 +159,8 @@ Scenario: Logged in teacher can only edit their own information Scenario: Logging in as a teacher with not_reviewed status should see "Update" instead of "Submit" when editing info Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | | Joseph | Mamoa | false | testteacher@berkeley.edu | @@ -172,8 +173,8 @@ Scenario: Logging in as a teacher with not_reviewed status should see "Update" i Scenario: Frontend should not allow Teacher to edit their email Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | | Jane | Austin | false | testteacher@berkeley.edu | Jane | @@ -190,8 +191,8 @@ Scenario: Frontend should not allow Teacher to edit their email Scenario: Validated teacher should see resend button Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | validated | @@ -204,8 +205,8 @@ Scenario: Validated teacher should see resend button Scenario: teacher with not_reviewed status should not see resend button Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | Not Reviewed | @@ -218,8 +219,8 @@ Scenario: teacher with not_reviewed status should not see resend button Scenario: Denied teacher should not see resend button Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | denied | @@ -232,8 +233,8 @@ Scenario: Denied teacher should not see resend button Scenario: Denied teacher cannot edit their information Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | more_info | | Jane | Austin | false | testteacher@berkeley.edu | Jane | denied | Original Information | @@ -248,8 +249,8 @@ Scenario: Denied teacher cannot edit their information Scenario: Validated teacher should not see Tags or NCES ID Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | validated | @@ -263,8 +264,8 @@ Scenario: Validated teacher should not see Tags or NCES ID Scenario: Teacher with not_reviewed status should not see Tags or NCES ID Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | Not Reviewed | @@ -278,8 +279,8 @@ Scenario: Teacher with not_reviewed status should not see Tags or NCES ID Scenario: Denied teacher should not see Tags or NCES ID Given the following schools exist: - | name | city | state | website | - | UC Berkeley | Berkeley | CA | https://www.berkeley.edu | + | name | country | city | state | website | + | UC Berkeley | US | Berkeley | CA | https://www.berkeley.edu | Given the following teachers exist: | first_name | last_name | admin | email | snap | application_status | | Jane | Austin | false | testteacher@berkeley.edu | Jane | denied | diff --git a/spec/controllers/schools_controller_spec.rb b/spec/controllers/schools_controller_spec.rb index dd051c56..ee826722 100644 --- a/spec/controllers/schools_controller_spec.rb +++ b/spec/controllers/schools_controller_spec.rb @@ -43,6 +43,7 @@ school: { name: @create_school_name, city: "Berkeley", + country: "US", state: "CA", website: "www.berkeley.edu", school_type: "public", @@ -61,6 +62,7 @@ school: { name: @create_school_name, # missing city + country: "US", state: "CA", website: "www.berkeley.edu", school_type: "public", @@ -75,6 +77,7 @@ post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", # missing website @@ -90,6 +93,7 @@ post schools_path, params: { school: { # missing name + country: "US", city: "Berkeley", state: "CA", website: "www.berkeley.edu", @@ -109,6 +113,7 @@ post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "DISTRESS", website: "www.berkeley.edu", @@ -124,6 +129,7 @@ post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", website: "wwwberkeleyedu", @@ -140,6 +146,7 @@ expect { post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", website: "www.berkeley.edu", @@ -157,6 +164,7 @@ params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", website: "www.berkeley.edu", @@ -177,6 +185,7 @@ post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", website: "www.berkeley.edu", @@ -189,6 +198,7 @@ post schools_path, params: { school: { name: @create_school_name, + country: "US", city: "Berkeley", state: "CA", website: "www.berkeley.edu", diff --git a/spec/controllers/teachers_signup_spec.rb b/spec/controllers/teachers_signup_spec.rb index 3385bc29..b3f6ca1b 100644 --- a/spec/controllers/teachers_signup_spec.rb +++ b/spec/controllers/teachers_signup_spec.rb @@ -50,6 +50,7 @@ post :create, params: { school: { name: "valid_example", + country: "US", city: "Berkeley", state: "CA", website: "valid_example.com", From 43b0a3dadd597a8901cbd4d14bb699effefabf4f Mon Sep 17 00:00:00 2001 From: razztech Date: Sun, 10 Mar 2024 22:07:03 -0700 Subject: [PATCH 04/63] Update tests to use country dropdown --- features/form_submission.feature | 30 ++++++++++++++++--------- features/school_form_submission.feature | 3 ++- features/step_definitions/web_steps.rb | 16 +++++++++++-- features/teacher.feature | 19 ++++++++-------- spec/factories/factories.rb | 1 + 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/features/form_submission.feature b/features/form_submission.feature index 639b8ea5..b9b8bb9e 100644 --- a/features/form_submission.feature +++ b/features/form_submission.feature @@ -19,8 +19,9 @@ Scenario: Correctly filling out and successful form submission And I fill in "More Information" with "I am after school volunteer" And I enter my "Personal or Course Website" as "https://chs.fuhsd.org" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -33,8 +34,9 @@ Scenario: Not Correctly filling out and unsuccessful form submission And I enter my "Last Name" as "Zhu" And I set my status as "I am teaching BJC as an AP CS Principles course." And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "chs.fuhsd.org" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -53,8 +55,9 @@ Scenario: Missing the compulsory more info field And I set my education level target as "High School" And I enter my "Personal or Course Website" as "https://chs.fuhsd.org" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -72,8 +75,9 @@ Scenario: Websites validation - two invalid websites And I set my education level target as "High School" And I fill in "More Information" with "I am teaching BJC" And I fill in the school name selectize box with "Stafford High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Palo Alto" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "stafford" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -90,8 +94,9 @@ Scenario: Websites validation - one invalid website And I set my education level target as "High School" And I fill in "More Information" with "I am teaching BJC" And I fill in the school name selectize box with "Stafford High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Palo Alto" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "stafford" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -108,8 +113,9 @@ Scenario: Websites validation - one valid website And I set my education level target as "High School" And I fill in "More Information" with "I am teaching BJC" And I fill in the school name selectize box with "Stafford High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Palo Alto" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://stafford.edu" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -128,8 +134,9 @@ Scenario: Filling out new form with existing email should not update information And I set my education level target as "High School" And I fill in "More Information" with "I am teaching BJC" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -151,8 +158,9 @@ Scenario: Filling out new form with existing Snap should not create new teacher And I fill in "More Information" with "I am teaching BJC" And I set my education level target as "High School" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -172,8 +180,9 @@ Scenario: Filling out form should have the correct information in a Teacher And I fill in "More Information" with "I am a TEALS program employee!" And I set my education level target as "High School" And I fill in the school name selectize box with "Castro Valley High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Castro Valley" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://cvhs.cv.k12.ca.us" And I select "University" from "Grade Level" And I select "Public" from "School Type" @@ -200,8 +209,9 @@ Scenario: Filling out form should have the correct information in a Teacher And I fill in "More Information" with "Rebecca" And I set my education level target as "High School" And I fill in the school name selectize box with "Castro Valley High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Castro Valley" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://cvhs.cv.k12.ca.us" And I select "University" from "Grade Level" And I select "Public" from "School Type" diff --git a/features/school_form_submission.feature b/features/school_form_submission.feature index 72f25db6..bbe4249c 100644 --- a/features/school_form_submission.feature +++ b/features/school_form_submission.feature @@ -47,8 +47,9 @@ Scenario: Admins can create new schools Then I can log in with Google When I go to the new schools page And I fill in the school name selectize box with "New UC Berkeley" and choose to add a new school + And I select "United States" from "Country" And I fill in "City" with "Berkeley" - And I select "CA" from "State" + And I select "CA" from "state_select" And I fill in "School Website" with "https://www.berkeley.edu/" And I select "University" from "Grade Level" And I select "Public" from "School Type" diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 6f216b75..8056eaaa 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -98,7 +98,19 @@ def with_scope(locator, &block) end When(/^(?:|I )select "([^"]*)" from "([^"]*)"$/) do |value, field| - select(value, from: field) + # Find the select element + select_box = find_field(field) + + # Find all options with the specified value + options = select_box.all('option', text: value) + + if options.length > 1 + # If there are multiple options with the same value, choose the first one + options.first.select_option + else + # If there's only one option or no option, use the default select method + select(value, from: field) + end end When(/^(?:|I )check "([^"]*)"$/) do |field| @@ -256,4 +268,4 @@ def with_scope(locator, &block) with_scope(selector) do field_labeled(field).find(:xpath, ".//option[@selected = 'selected'][text() = '#{value}']").should be_present end -end +end \ No newline at end of file diff --git a/features/teacher.feature b/features/teacher.feature index d4ef8a64..c9c1ee2d 100644 --- a/features/teacher.feature +++ b/features/teacher.feature @@ -39,8 +39,9 @@ Scenario: Logging in as a teacher with Google account should be able to edit the And I set my status as "I am a TEALS volunteer, and am teaching the BJC curriculum." And I set my education level target as "College" And I fill in the school name selectize box with "Cupertino High School, Cupertino, CA" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I press "Update" Then I see a confirmation "Successfully updated your information" @@ -105,13 +106,12 @@ Scenario: Logged in teacher with Not_Reviewed application status can update thei And I set my status as "I am teaching BJC as an AP CS Principles course." And I set my education level target as "High School" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school - And I fill in the following: - | Country | US | - | City | Cupertino | - | State | CA | - | School Website | https://chs.fuhsd.org | - | Grade Level | High School | - | School Type | Public | + And I select "United States" from "Country" + And I enter my "City" as "Cupertino" + And I select "CA" from "state_select" + And I enter my "School Website" as "https://chs.fuhsd.org" + And I select "High School" from "Grade Level" + And I select "Public" from "School Type" And I press "Update" Then I see a confirmation "Successfully updated your information" And I am on the edit page for Joe Mamoa @@ -135,8 +135,9 @@ Scenario: Logged in teacher with Not_Reviewed application status can update thei And I set my status as "I am teaching BJC as an AP CS Principles course." And I set my education level target as "High School" And I fill in the school name selectize box with "Cupertino High School" and choose to add a new school + And I select "United States" from "Country" And I enter my "City" as "Cupertino" - And I select "CA" from "State" + And I select "CA" from "state_select" And I enter my "School Website" as "https://chs.fuhsd.org" And I press "Update" And I should see "Edit Joe Mamoa" diff --git a/spec/factories/factories.rb b/spec/factories/factories.rb index 9be9fd1b..a0aa40b2 100644 --- a/spec/factories/factories.rb +++ b/spec/factories/factories.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :school do name { "Basic School" } + country { "US" } city { "Berkeley" } state { "CA" } grade_level { 4 } From f3cd0cd2c02513b4c771f5171075d49aa56bc580 Mon Sep 17 00:00:00 2001 From: razztech Date: Mon, 11 Mar 2024 15:54:21 -0700 Subject: [PATCH 05/63] All tests are passing --- app/views/schools/_form.html.erb | 5 +---- app/views/schools/index.html.erb | 1 + app/views/schools/show.html.erb | 14 ++++++++++---- app/views/teachers/_table_headers.erb | 1 + app/views/teachers/_teacher.erb | 3 +++ app/views/teachers/_teacher_info.html.erb | 6 ++++++ app/views/teachers/index.html.erb | 1 + features/form_submission.feature | 20 ++++++++++---------- features/school_form_submission.feature | 2 +- features/step_definitions/web_steps.rb | 18 +++++++++++++----- features/teacher.feature | 6 +++--- 11 files changed, 50 insertions(+), 27 deletions(-) diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index b44d09be..c15b959d 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -12,7 +12,7 @@ <%= f.country_select( :country, { priority_countries: ['United States'], include_blank: "Select an option" }, - { class: 'form-control', required: true, id: 'school_country', format: :with_full_country_name} + { class: 'form-control', required: false, id: 'school_country', format: :with_full_country_name} ) %>
@@ -102,10 +102,8 @@ From 772f2df7c142ceccbff554d886d61dec22ba2e6d Mon Sep 17 00:00:00 2001 From: Jingchao Zhong <92573736+perryzjc@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:26:46 -0700 Subject: [PATCH 19/63] Add cucumber test for unexpected user behavior --- features/school_form_submission.feature | 19 ++++++++++++++++++- features/step_definitions/form_steps.rb | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/features/school_form_submission.feature b/features/school_form_submission.feature index 053c7074..618aae17 100644 --- a/features/school_form_submission.feature +++ b/features/school_form_submission.feature @@ -96,4 +96,21 @@ Scenario: Admin can see international schools in the submission And I select "Public" from "School Type" And I press "Submit" And I see a confirmation "Thanks for signing up for BJC" - Then I should find a teacher with email "razztech@berkeley.edu" and school country "RO" in the database + Then I should find a teacher with email "razztech@berkeley.edu" and school country "RO" in the database + +Scenario: Attempt to create an international school with missing mandatory fields + Given "razztech@berkeley.edu" is not in the database + And I am on the BJC home page + And I enter my "First Name" as "Perry" + And I enter my "Last Name" as "Zhong" + And I enter my "School Email" as "jzhong12@berkeley.edu" + And I set my status as "I am teaching BJC as an AP CS Principles course." + And I set my education level target as "High School" + And I fill in "More Information" with "I am after school volunteer" + And I enter my "Personal or Course Website" as "https://chs.fuhsd.org" + And I fill in the school name selectize box with "Bucharest International School" and choose to add a new school + # Leaving out mandatory fields "Country", "City", and "School Website" to simulate user error + And I select "University" from "Grade Level" + And I select "Public" from "School Type" + And I press "Submit" + Then the new teacher form should not be submitted diff --git a/features/step_definitions/form_steps.rb b/features/step_definitions/form_steps.rb index 8f38bf61..567706c6 100644 --- a/features/step_definitions/form_steps.rb +++ b/features/step_definitions/form_steps.rb @@ -88,3 +88,9 @@ Then(/^"([^"]*)" click and fill option for "([^"]*)"(?: within "([^"]*)")?$/) do |value| find("#school_selectize").click.set(value) end + +Then(/^the new teacher form should not be submitted$/) do + expect(current_path).to eq(new_teacher_path) + expect(page).to have_content("Your Information") + expect(page).to have_content("Create a new School") +end From 05d989eb686f2cb323bc99e812dac78c895289ba Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati Date: Wed, 13 Mar 2024 20:20:05 -0700 Subject: [PATCH 20/63] fix glitch --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index a9927666..52b296b9 100644 --- a/db/schema.rb +++ b/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: 2024_03_07_225738) do +ActiveRecord::Schema.define(version: 2024_02_18_225738) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From a2ea667c7d1bffa3792626a0e99190d5dd8f461d Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati Date: Wed, 13 Mar 2024 20:20:37 -0700 Subject: [PATCH 21/63] resolve merge conflict --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 52b296b9..a9927666 100644 --- a/db/schema.rb +++ b/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: 2024_02_18_225738) do +ActiveRecord::Schema.define(version: 2024_03_07_225738) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From fa1155b28740c27b7bd7d2830b5f02bd9d41ca3d Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:31:06 -0700 Subject: [PATCH 22/63] ok actually fixed merge conflict now --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index a9927666..0bab93fc 100644 --- a/db/schema.rb +++ b/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: 2024_03_07_225738) do +ActiveRecord::Schema.define(version: 2024_02_18_005604) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From a155d65f7fc264ba712a202f13d669417c1d021d Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:40:42 -0700 Subject: [PATCH 23/63] no choice, have to resolve conflict manually --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 0bab93fc..a9927666 100644 --- a/db/schema.rb +++ b/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: 2024_02_18_005604) do +ActiveRecord::Schema.define(version: 2024_03_07_225738) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 4af15e77cf800840e55b66d0b9b752dad5417897 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:54:58 -0700 Subject: [PATCH 24/63] added languages dropdown without selectize --- app/controllers/teachers_controller.rb | 2 +- app/javascript/packs/schools.js | 4 ++-- app/models/teacher.rb | 1 + app/views/teachers/_form.html.erb | 15 +++++++++++++++ .../20240314160959_add_languages_to_teachers.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/teachers.rb | 1 + spec/fixtures/teachers.yml | 3 ++- spec/models/teacher_spec.rb | 1 + 9 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20240314160959_add_languages_to_teachers.rb diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index 4b2954ed..2c0f6bf9 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -207,7 +207,7 @@ def load_school def teacher_params teacher_attributes = [:first_name, :last_name, :school, :email, :status, :snap, - :more_info, :personal_website, :education_level, :school_id] + :more_info, :personal_website, :education_level, :languages, :school_id] if is_admin? teacher_attributes << [:personal_email, :application_status, :request_reason, :skip_email] diff --git a/app/javascript/packs/schools.js b/app/javascript/packs/schools.js index 58b08771..212f58bf 100644 --- a/app/javascript/packs/schools.js +++ b/app/javascript/packs/schools.js @@ -28,7 +28,7 @@ let create_school = function (input, callback) { $("#school_form").show(); toggle_required(['name', 'city', 'state', 'website'], true); $(".btn-primary").show(); - let oringial_school_id = $('#teacher_school_id').val(); + let original_school_id = $('#teacher_school_id').val(); var reset_button = $("#close_button"); var name_input = $("#school_name"); // Unset the existing saved school id. @@ -38,7 +38,7 @@ let create_school = function (input, callback) { if (selectizeCallback != null) { selectizeCallback(); selectizeCallback = null; - $('#teacher_school_id').val(oringial_school_id); + $('#teacher_school_id').val(original_school_id); } toggle_required(['name', 'city', 'state', 'website'], true); $("#school_form").hide(); diff --git a/app/models/teacher.rb b/app/models/teacher.rb index 76fa7b34..e2816f02 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -11,6 +11,7 @@ # email :string # first_name :string # ip_history :inet default([]), is an Array +# languages :string # last_name :string # last_session_at :datetime # more_info :string diff --git a/app/views/teachers/_form.html.erb b/app/views/teachers/_form.html.erb index 8f16299c..c8068161 100644 --- a/app/views/teachers/_form.html.erb +++ b/app/views/teachers/_form.html.erb @@ -117,6 +117,21 @@ status ONLY IF the person viewing this page is an admin. %> +
+
+ <%= f.label :languages, "What language(s) are spoken in the classroom?", + class: "label-required" %> + <%= f.select( + :languages, + options_for_select(['English', 'Spanish', 'French', 'Other']), + { include_blank: "Select an option" }, + { class: 'form-control', required: false } + ) %> +
+
+ + +
<%= f.label :more_info, "More Information", class: "label-required" %> diff --git a/db/migrate/20240314160959_add_languages_to_teachers.rb b/db/migrate/20240314160959_add_languages_to_teachers.rb new file mode 100644 index 00000000..d2cd673a --- /dev/null +++ b/db/migrate/20240314160959_add_languages_to_teachers.rb @@ -0,0 +1,5 @@ +class AddLanguagesToTeachers < ActiveRecord::Migration[6.1] + def change + add_column :teachers, :languages, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index a9927666..82d5a35c 100644 --- a/db/schema.rb +++ b/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: 2024_03_07_225738) do +ActiveRecord::Schema.define(version: 2024_03_14_160959) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -118,6 +118,7 @@ t.inet "ip_history", default: [], array: true t.integer "session_count", default: 0 t.string "personal_email" + t.string "languages" t.index ["email", "first_name"], name: "index_teachers_on_email_and_first_name" t.index ["email", "personal_email"], name: "index_teachers_on_email_and_personal_email", unique: true t.index ["email"], name: "index_teachers_on_email", unique: true diff --git a/spec/factories/teachers.rb b/spec/factories/teachers.rb index c3466132..f1b99b1b 100644 --- a/spec/factories/teachers.rb +++ b/spec/factories/teachers.rb @@ -11,6 +11,7 @@ # email :string # first_name :string # ip_history :inet default([]), is an Array +# languages :string # last_name :string # last_session_at :datetime # more_info :string diff --git a/spec/fixtures/teachers.yml b/spec/fixtures/teachers.yml index b0420583..9f90ebbd 100644 --- a/spec/fixtures/teachers.yml +++ b/spec/fixtures/teachers.yml @@ -9,6 +9,7 @@ # email :string # first_name :string # ip_history :inet default([]), is an Array +# languages :string # last_name :string # last_session_at :datetime # more_info :string @@ -109,4 +110,4 @@ barney: application_status: Denied school: berkeley education_level: -1 - \ No newline at end of file + diff --git a/spec/models/teacher_spec.rb b/spec/models/teacher_spec.rb index e7e9918f..db78a3c4 100644 --- a/spec/models/teacher_spec.rb +++ b/spec/models/teacher_spec.rb @@ -11,6 +11,7 @@ # email :string # first_name :string # ip_history :inet default([]), is an Array +# languages :string # last_name :string # last_session_at :datetime # more_info :string From db87716758de576a3ef108f5e377a0bfdd68d24d Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:20:14 -0700 Subject: [PATCH 25/63] added selectize thingie --- app/models/teacher.rb | 8 ++++++++ app/views/teachers/_form.html.erb | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/models/teacher.rb b/app/models/teacher.rb index e2816f02..aa569ca6 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -38,6 +38,9 @@ # fk_rails_... (school_id => schools.id) # class Teacher < ApplicationRecord + + WORLD_LANGUAGES = [ 'Afrikaans', 'Albanian', 'Arabic', 'Armenian', 'Basque', 'Bengali', 'Bulgarian', 'Catalan', 'Cambodian', 'Chinese (Mandarin)', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Estonian', 'Fiji', 'Finnish', 'French', 'Georgian', 'German', 'Greek', 'Gujarati', 'Hebrew', 'Hindi', 'Hungarian', 'Icelandic', 'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Korean', 'Latin', 'Latvian', 'Lithuanian', 'Macedonian', 'Malay', 'Malayalam', 'Maltese', 'Maori', 'Marathi', 'Mongolian', 'Nepali', 'Norwegian', 'Persian', 'Polish', 'Portuguese', 'Punjabi', 'Quechua', 'Romanian', 'Russian', 'Samoan', 'Serbian', 'Slovak', 'Slovenian', 'Spanish', 'Swahili', 'Swedish ', 'Tamil', 'Tatar', 'Telugu', 'Thai', 'Tibetan', 'Tonga', 'Turkish', 'Ukrainian', 'Urdu', 'Uzbek', 'Vietnamese', 'Welsh', 'Xhosa' ].freeze + validates :first_name, :last_name, :email, :status, presence: true validates :email, uniqueness: true validates :personal_email, uniqueness: true, if: -> { personal_email.present? } @@ -164,6 +167,11 @@ def self.education_level_options Teacher.education_levels.map { |sym, val| [sym.to_s.titlecase, val] } end + def self.language_options + WORLD_LANGUAGES + #language_codes = ISO3166::Country.all.map { |country| country.languages}.flatten.uniq + end + def display_education_level if education_level_before_type_cast.to_i == -1 "?" diff --git a/app/views/teachers/_form.html.erb b/app/views/teachers/_form.html.erb index c8068161..109e2d33 100644 --- a/app/views/teachers/_form.html.erb +++ b/app/views/teachers/_form.html.erb @@ -121,11 +121,12 @@ status ONLY IF the person viewing this page is an admin. %>
<%= f.label :languages, "What language(s) are spoken in the classroom?", class: "label-required" %> - <%= f.select( + <%= select_tag( :languages, - options_for_select(['English', 'Spanish', 'French', 'Other']), - { include_blank: "Select an option" }, - { class: 'form-control', required: false } + options_for_select(Teacher.language_options), + multiple: true, + include_blank: "Select an option", + class: 'selectize' ) %>
@@ -158,6 +159,17 @@ status ONLY IF the person viewing this page is an admin. %> From ff543d6be3c86d62becbdf5b79e5fcc879b6be55 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:30:39 -0700 Subject: [PATCH 45/63] Update email_template.feature Fix cucumber test -- note that error messages have been standardized in the application to have the common format "An error occured: ..." --- features/email_template.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/email_template.feature b/features/email_template.feature index d0d8e008..28a3c89a 100644 --- a/features/email_template.feature +++ b/features/email_template.feature @@ -62,7 +62,7 @@ Scenario: Editing email template to have blank body or to field displays flash e Then I should see "An error occurred: To can't be blank" When I fill in TinyMCE email form with "" And I press "Submit" - Then I should see "Failed to save Welcome Email template: Body cannot be blank" + Then I should see "An error occured: Body can't be blank" Scenario: Updating email template with valid parameters succeeds Given I am on the email templates index From 2e1c1d15fa64d488253d548b89cbe5224ea20551 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:45:05 -0700 Subject: [PATCH 46/63] Update schools_controller.rb remove debugger --- app/controllers/schools_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 127fb8ca..500f6ca0 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -44,7 +44,6 @@ def edit def update @school = School.find(params[:id]) @school.assign_attributes(school_params) - debugger if @school.save flash[:success] = "Updated #{@school.name} successfully." redirect_to school_path(@school) From d58eda9cea0429e02df5b595fbfb2078b201bc00 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:45:42 -0700 Subject: [PATCH 47/63] fix cucumber tests --- app/controllers/email_templates_controller.rb | 2 +- app/controllers/teachers_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/email_templates_controller.rb b/app/controllers/email_templates_controller.rb index 0ee2bcc1..85c02069 100644 --- a/app/controllers/email_templates_controller.rb +++ b/app/controllers/email_templates_controller.rb @@ -36,7 +36,7 @@ def create flash[:success] = "Created #{@email_template.title} successfully." redirect_to email_templates_path else - flash.now[:alert] = "Failed to submit information: #{@email_template.errors.full_messages.join(", ")}" + flash.now[:alert] = "An error occurred: #{@email_template.errors.full_messages.join(", ")}" render "new" end end diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index fd167eab..9c923f17 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -65,7 +65,7 @@ def create if @school.new_record? @school = School.new(school_params) unless @school.save - flash[:alert] = "An error occurred! #{@school.errors.full_messages.join(', ')}" + flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}" render "new" && return end end From 838c4c02f1d096c099af3b02c84a5ebf214283f8 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:47:07 -0700 Subject: [PATCH 48/63] change new --> edit redirect for update school failure --- app/controllers/teachers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index 9c923f17..886ccc89 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -102,7 +102,7 @@ def update @school.update(school_params) if school_params unless @school.save flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}" - render "new" && return + render "edit" && return end @teacher.school = @school end From b1fe2d5e9317e0c839496fb6d754e20be83bd893 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:49:44 -0700 Subject: [PATCH 49/63] actually fixed it now --- app/controllers/email_templates_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/email_templates_controller.rb b/app/controllers/email_templates_controller.rb index 85c02069..45f63b99 100644 --- a/app/controllers/email_templates_controller.rb +++ b/app/controllers/email_templates_controller.rb @@ -18,7 +18,7 @@ def update flash[:success] = "Updated #{@email_template.title} template successfully." redirect_to email_templates_path else - flash.now[:alert] = "Failed to save #{@email_template.title} template: #{@email_template.errors.full_messages.join(", ")}" + flash.now[:alert] = "An error occured: #{@email_template.errors.full_messages.join(", ")}" render "edit" end end From 66eb04c604dd74620e796ef580de1af4fa8d53ab Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:51:01 -0700 Subject: [PATCH 50/63] it turns out I don't know how to spell the word 'occured' --- features/email_template.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/email_template.feature b/features/email_template.feature index 28a3c89a..3da35895 100644 --- a/features/email_template.feature +++ b/features/email_template.feature @@ -62,7 +62,7 @@ Scenario: Editing email template to have blank body or to field displays flash e Then I should see "An error occurred: To can't be blank" When I fill in TinyMCE email form with "" And I press "Submit" - Then I should see "An error occured: Body can't be blank" + Then I should see "An error occurred: Body can't be blank" Scenario: Updating email template with valid parameters succeeds Given I am on the email templates index From 6e46e5cd0159cf66ef4b1cb05b415952bec0a8f2 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:12:12 -0700 Subject: [PATCH 51/63] fixed another myterious cucumber test bug --- app/controllers/email_templates_controller.rb | 2 +- features/teacher_info_request.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/email_templates_controller.rb b/app/controllers/email_templates_controller.rb index 45f63b99..76a78b65 100644 --- a/app/controllers/email_templates_controller.rb +++ b/app/controllers/email_templates_controller.rb @@ -18,7 +18,7 @@ def update flash[:success] = "Updated #{@email_template.title} template successfully." redirect_to email_templates_path else - flash.now[:alert] = "An error occured: #{@email_template.errors.full_messages.join(", ")}" + flash.now[:alert] = "An error occurred: #{@email_template.errors.full_messages.join(", ")}" render "edit" end end diff --git a/features/teacher_info_request.feature b/features/teacher_info_request.feature index 367d60a4..ca698981 100644 --- a/features/teacher_info_request.feature +++ b/features/teacher_info_request.feature @@ -25,7 +25,7 @@ Feature: Request additional information for teacher application And I should see "Request Info from Joseph Mamoa" And I fill in "request_reason" with "Please provide more details on your teaching experience" And I press "Submit" - Then I can send a request info email + Then I send a request info email And I follow "Logout" Given I am on the BJC home page From f9388fc79b881b1614f65656e4c141c9645d486a Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:17:23 -0700 Subject: [PATCH 52/63] remove country from teachers table --- app/views/schools/index.html.erb | 1 - app/views/teachers/_table_headers.erb | 1 - app/views/teachers/_teacher.erb | 3 --- 3 files changed, 5 deletions(-) diff --git a/app/views/schools/index.html.erb b/app/views/schools/index.html.erb index 103478dc..ae0d33fa 100644 --- a/app/views/schools/index.html.erb +++ b/app/views/schools/index.html.erb @@ -6,7 +6,6 @@ Name Location - Country URL Teachers Grade Level diff --git a/app/views/teachers/_table_headers.erb b/app/views/teachers/_table_headers.erb index f519ec1e..8c070619 100644 --- a/app/views/teachers/_table_headers.erb +++ b/app/views/teachers/_table_headers.erb @@ -4,6 +4,5 @@ Status Snap! School -Country Approved? Created diff --git a/app/views/teachers/_teacher.erb b/app/views/teachers/_teacher.erb index beed2b95..7523cca7 100644 --- a/app/views/teachers/_teacher.erb +++ b/app/views/teachers/_teacher.erb @@ -27,9 +27,6 @@ <%= link_to(teacher.school.name, school_path(teacher.school)) %> <%= teacher.school.location %> - - <%= teacher.school.country %> - <%= teacher.short_application_status %> From 8ca38723be52e72970f4d5783b59fc95a7bcde0a Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:18:50 -0700 Subject: [PATCH 53/63] removed one unnecessary deletion --- app/views/schools/index.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/schools/index.html.erb b/app/views/schools/index.html.erb index ae0d33fa..103478dc 100644 --- a/app/views/schools/index.html.erb +++ b/app/views/schools/index.html.erb @@ -6,6 +6,7 @@ Name Location + Country URL Teachers Grade Level From 05df57cbc122e105c7c238b449ce53376a4dde88 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:21:52 -0700 Subject: [PATCH 54/63] update location method to display country --- app/models/school.rb | 2 +- app/views/teachers/_teacher_info.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index f33f4c8b..b07a7047 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -61,7 +61,7 @@ def website end def location - "#{city}, #{state}" + "#{city}, #{state}, #{country}" end # TODO: Consider renaming this. diff --git a/app/views/teachers/_teacher_info.html.erb b/app/views/teachers/_teacher_info.html.erb index 38622fc5..6a08e630 100644 --- a/app/views/teachers/_teacher_info.html.erb +++ b/app/views/teachers/_teacher_info.html.erb @@ -74,7 +74,7 @@
School Location:
- <%= "#{teacher.school.location}, #{teacher.school.country}" %> + <%= "#{teacher.school.location}" %>
From 38b2ce1871a35c318bef7bf890a6ce9c76ac7486 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:25:58 -0700 Subject: [PATCH 55/63] update selectize options --- app/models/school.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index b07a7047..6a15ad62 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -78,11 +78,11 @@ def display_grade_level end def selectize_options - [name_location, to_json(only: [:id, :name, :city, :state, :website]) ] + [name_location, to_json(only: [:id, :name, :city, :state, :country, :website]) ] end def name_location - "#{name} (#{city}, #{state})" + "#{name} (#{city}, #{state}, #{country})" end def update_gps_data From 8f831eb05a3a0ae60a676505006e82ad42ae4a90 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:28:46 -0700 Subject: [PATCH 56/63] revert placeholder --- app/views/schools/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/schools/_form.html.erb b/app/views/schools/_form.html.erb index b0b3a37e..1d911cee 100644 --- a/app/views/schools/_form.html.erb +++ b/app/views/schools/_form.html.erb @@ -2,7 +2,7 @@
<%= f.label :name, "School Name", class: "label-required" %> - <%= f.text_field :name, placeholder: 'Name of School', class: 'form-control', + <%= f.text_field :name, placeholder: 'UC Berkeley', class: 'form-control', required: false, id: 'school_name' %>
From fb9e87742532dc68fed65583c1b966e3a86057e7 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:21:52 -0700 Subject: [PATCH 57/63] update location method to display country --- app/models/school.rb | 2 +- app/views/teachers/_teacher_info.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index f33f4c8b..b07a7047 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -61,7 +61,7 @@ def website end def location - "#{city}, #{state}" + "#{city}, #{state}, #{country}" end # TODO: Consider renaming this. diff --git a/app/views/teachers/_teacher_info.html.erb b/app/views/teachers/_teacher_info.html.erb index 38622fc5..6a08e630 100644 --- a/app/views/teachers/_teacher_info.html.erb +++ b/app/views/teachers/_teacher_info.html.erb @@ -74,7 +74,7 @@
School Location:
- <%= "#{teacher.school.location}, #{teacher.school.country}" %> + <%= "#{teacher.school.location}" %>
From 4cf6fbc746a93731082c4b49146de84ed854d70a Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:25:58 -0700 Subject: [PATCH 58/63] update selectize options --- app/models/school.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index b07a7047..6a15ad62 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -78,11 +78,11 @@ def display_grade_level end def selectize_options - [name_location, to_json(only: [:id, :name, :city, :state, :website]) ] + [name_location, to_json(only: [:id, :name, :city, :state, :country, :website]) ] end def name_location - "#{name} (#{city}, #{state})" + "#{name} (#{city}, #{state}, #{country})" end def update_gps_data From eeea4caa2dcca937fe2d5074a94d89c8c072a51a Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 14:53:15 -0700 Subject: [PATCH 59/63] add back teachers to table to prevent cucumber bugs --- app/views/teachers/_table_headers.erb | 1 + app/views/teachers/_teacher.erb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/views/teachers/_table_headers.erb b/app/views/teachers/_table_headers.erb index 8c070619..f519ec1e 100644 --- a/app/views/teachers/_table_headers.erb +++ b/app/views/teachers/_table_headers.erb @@ -4,5 +4,6 @@ Status Snap! School +Country Approved? Created diff --git a/app/views/teachers/_teacher.erb b/app/views/teachers/_teacher.erb index 7523cca7..beed2b95 100644 --- a/app/views/teachers/_teacher.erb +++ b/app/views/teachers/_teacher.erb @@ -27,6 +27,9 @@ <%= link_to(teacher.school.name, school_path(teacher.school)) %> <%= teacher.school.location %> + + <%= teacher.school.country %> + <%= teacher.short_application_status %> From fa97d32051cefd796433c41f61d61d2709dd5301 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:30:11 -0700 Subject: [PATCH 60/63] make search_list change --- app/controllers/schools_controller.rb | 2 +- app/models/school.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 500f6ca0..191191f5 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -12,7 +12,7 @@ def show end def search - School.all.collect { |school| ["#{school.name}, #{school.country}, #{school.city}, #{school.state}", school.name] } + School.search_list end def create diff --git a/app/models/school.rb b/app/models/school.rb index 6a15ad62..2d12c61e 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -101,6 +101,18 @@ def maps_marker_data } end + def format_school(data) + name, city, state, country = data + country_str = country == "US" ? "" : ", #{country}" + "#{name} (#{city}, #{state}#{country_str})" + end + + def self.search_list + School.pluck(:name, :city, :state, :country).map do |data| + format_school(data) + end + end + def self.grade_level_options School.grade_levels.map { |key, _val| [key.to_s.titlecase, key] } end From c027698129c2f92211f7bdb0535808ff9704c800 Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:58:18 -0700 Subject: [PATCH 61/63] added unique school params and DRY out code --- app/controllers/concerns/school_params.rb | 17 +++++++++++++++++ app/controllers/schools_controller.rb | 7 ++----- app/controllers/teachers_controller.rb | 9 +++------ 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 app/controllers/concerns/school_params.rb diff --git a/app/controllers/concerns/school_params.rb b/app/controllers/concerns/school_params.rb new file mode 100644 index 00000000..5bb01362 --- /dev/null +++ b/app/controllers/concerns/school_params.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module SchoolParams + private + def unique_school_params + { + name: school_params[:name], + country: school_params[:country], + city: school_params[:city], + state: school_params[:state] + } + end + + def school_params + params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type, :country, { tags: [] }, :nces_id) + end +end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 191191f5..ecdbfc37 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class SchoolsController < ApplicationController + include SchoolParams before_action :require_admin def index @@ -16,7 +17,7 @@ def search end def create - @school = School.find_by(name: school_params[:name], country: school_params[:country], city: school_params[:city], state: school_params[:state]) + @school = School.find_by(**unique_school_params) if @school @school.assign_attributes(school_params) else @@ -64,10 +65,6 @@ def destroy end private - def school_params - params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type, :country, { tags: [] }, :nces_id) - end - def load_ordered_schools @ordered_schools ||= School.all.order(:name) end diff --git a/app/controllers/teachers_controller.rb b/app/controllers/teachers_controller.rb index 886ccc89..ec6cd27e 100644 --- a/app/controllers/teachers_controller.rb +++ b/app/controllers/teachers_controller.rb @@ -6,6 +6,7 @@ require "activerecord-import" class TeachersController < ApplicationController + include SchoolParams include CsvProcess before_action :load_pages, only: [:new, :create, :edit, :update] @@ -63,6 +64,7 @@ def create load_school if @school.new_record? + return unless params[:school] @school = School.new(school_params) unless @school.save flash[:alert] = "An error occurred: #{@school.errors.full_messages.join(', ')}" @@ -205,7 +207,7 @@ def load_school if teacher_params[:school_id].present? @school ||= School.find(teacher_params[:school_id]) end - @school ||= School.find_or_create_by(name: school_params[:name], city: school_params[:city], country: school_params[:country], state: school_params[:state]) + @school ||= School.find_or_create_by(**unique_school_params) end def teacher_params @@ -218,11 +220,6 @@ def teacher_params params.require(:teacher).permit(*teacher_attributes) end - def school_params - return unless params[:school] - params.require(:school).permit(:name, :country, :city, :state, :website, :grade_level, :school_type) - end - def omniauth_data @omniauth_data ||= session[:auth_data]&.slice("first_name", "last_name", "email") end From f41d0b94367877c204c3a4840e646fce02251e9c Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:01:30 -0700 Subject: [PATCH 62/63] converted valid states list using country gem --- app/models/school.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/school.rb b/app/models/school.rb index 2d12c61e..040ddbd9 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -26,8 +26,7 @@ # class School < ApplicationRecord - VALID_STATES = [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY"].freeze - + VALID_STATES = ISO3166::Country['US'].subdivisions.keys.freeze validates :name, :city, :website, :country, presence: true validates :country, inclusion: { in: ISO3166::Country.all.map(&:alpha2), message: "%{value} is not a valid country" } validates :state, presence: true, if: -> { country == "US" } From 1f682da9753058c0d8b1353344f74896334ab45c Mon Sep 17 00:00:00 2001 From: Arush Chhatrapati <65872167+ArushC@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:02:34 -0700 Subject: [PATCH 63/63] fixed rubocop --- app/models/school.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/school.rb b/app/models/school.rb index 040ddbd9..b51b546c 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -26,7 +26,7 @@ # class School < ApplicationRecord - VALID_STATES = ISO3166::Country['US'].subdivisions.keys.freeze + VALID_STATES = ISO3166::Country["US"].subdivisions.keys.freeze validates :name, :city, :website, :country, presence: true validates :country, inclusion: { in: ISO3166::Country.all.map(&:alpha2), message: "%{value} is not a valid country" } validates :state, presence: true, if: -> { country == "US" }