From ad03606d6664710ad992fc8d04b5ea8c99f1caec Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Wed, 15 Dec 2021 16:55:06 +0100 Subject: [PATCH] Add benchmarks to survey and admin data items. Remove them from measures. Modify seeder Calculate benchmarks for measures based on a weighted average of survey and admin data items Added architectural records --- Gemfile | 25 +- app/controllers/categories_controller.rb | 2 - app/controllers/legacy/admin_controller.rb | 5 +- .../legacy/application_controller.rb | 10 +- app/controllers/legacy/attempts_controller.rb | 14 +- .../legacy/categories_controller.rb | 13 +- .../legacy/districts_controller.rb | 5 +- .../legacy/question_lists_controller.rb | 8 +- .../legacy/questions_controller.rb | 9 +- .../legacy/recipient_lists_controller.rb | 8 +- .../legacy/recipients_controller.rb | 23 +- .../legacy/schedules_controller.rb | 15 +- app/controllers/legacy/schools_controller.rb | 13 +- app/controllers/legacy/welcome_controller.rb | 2 - app/controllers/overview_controller.rb | 1 - app/controllers/sqm_application_controller.rb | 3 +- app/helpers/gauge_helper.rb | 17 +- app/helpers/header_helper.rb | 13 +- app/helpers/schedules_helper.rb | 5 +- app/helpers/variance_helper.rb | 5 +- app/lib/seeder.rb | 27 +- app/models/academic_year.rb | 2 - app/models/application_record.rb | 2 +- app/models/category.rb | 2 +- app/models/legacy/attempt.rb | 24 +- app/models/legacy/category.rb | 36 ++- app/models/legacy/question.rb | 13 +- app/models/legacy/question_list.rb | 5 +- app/models/legacy/recipient.rb | 6 +- app/models/legacy/recipient_list.rb | 5 +- app/models/legacy/recipient_schedule.rb | 57 +++-- app/models/legacy/schedule.rb | 6 +- app/models/legacy/school_question.rb | 20 +- app/models/legacy/user_school.rb | 2 - app/models/measure.rb | 47 +++- app/models/survey_item_response.rb | 27 +- app/presenters/admin_data_presenter.rb | 4 +- app/presenters/gauge_presenter.rb | 1 + app/presenters/measure_presenter.rb | 19 +- app/presenters/scale.rb | 2 +- app/presenters/student_survey_presenter.rb | 4 +- app/presenters/subcategory_presenter.rb | 4 +- app/presenters/teacher_survey_presenter.rb | 4 +- .../variance_chart_row_presenter.rb | 2 +- app/services/survey_responses_data_loader.rb | 9 +- app/views/legacy/questions/show.json.jbuilder | 3 +- .../legacy/recipients/index.json.jbuilder | 3 +- .../legacy/recipients/show.json.jbuilder | 3 +- .../school/schedules/index.json.jbuilder | 3 +- .../school/schedules/show.json.jbuilder | 3 +- bin/bundle | 44 ++-- bin/rails | 6 +- bin/rake | 6 +- bin/rspec | 14 +- bin/setup | 2 +- bin/spring | 12 +- bin/update | 2 +- bin/yarn | 14 +- config/environments/production.rb | 4 +- config/initializers/array_monkey_patches.rb | 2 +- config/initializers/friendly_id.rb | 4 +- config/puma.rb | 10 +- config/routes.rb | 6 +- config/spring.rb | 8 +- .../20170224181252_devise_create_users.rb | 5 +- .../20210917074250_add_slug_to_district.rb | 3 +- ...ull_constraints_from_measure_benchmarks.rb | 1 - ...between_survey_item_response_and_school.rb | 2 +- ...211119223051_make_school_dese_id_unique.rb | 2 +- ...17142634_add_benchmarks_to_survey_items.rb | 8 + ...3827_add_benchmarks_to_admin_data_items.rb | 8 + ...7164449_remove_benchmarks_from_measures.rb | 8 + db/schema.rb | 14 +- doc/architectural_decision_records/1.md | 31 +++ .../adr_template.md | 24 ++ lib/tasks/data.rake | 238 +++++++++--------- lib/tasks/dupes.rake | 24 +- lib/tasks/survey.rake | 4 +- .../controllers/categories_controller_spec.rb | 8 +- spec/controllers/home_controller_spec.rb | 6 +- .../legacy/attempts_controller_spec.rb | 108 ++++---- .../legacy/categories_controller_spec.rb | 82 +++--- .../legacy/districts_controller_spec.rb | 76 +++--- .../legacy/question_lists_controller_spec.rb | 76 +++--- .../legacy/questions_controller_spec.rb | 78 +++--- .../legacy/recipient_lists_controller_spec.rb | 100 ++++---- .../legacy/recipients_controller_spec.rb | 87 +++---- .../legacy/schedules_controller_spec.rb | 87 +++---- .../legacy/schools_controller_spec.rb | 232 +++++++++-------- .../legacy/welcome_controller_spec.rb | 6 +- spec/controllers/overview_controller_spec.rb | 6 +- spec/factories.rb | 31 ++- spec/lib/seeder_spec.rb | 73 +++--- spec/lib/tasks/survey_rake_spec.rb | 70 +++--- spec/models/legacy/attempt_spec.rb | 13 +- spec/models/legacy/district_spec.rb | 3 +- spec/models/legacy/question_spec.rb | 36 ++- spec/models/legacy/recipient_list_spec.rb | 6 +- spec/models/legacy/recipient_spec.rb | 9 +- spec/models/legacy/schedule_spec.rb | 16 +- spec/models/legacy/school_category_spec.rb | 55 ++-- spec/models/measure_spec.rb | 153 +++++++++++ spec/models/survey_item_response_spec.rb | 192 +++++++++----- spec/presenters/category_presenter_spec.rb | 16 +- spec/presenters/gauge_presenter_spec.rb | 5 +- spec/presenters/measure_presenter_spec.rb | 43 ++-- spec/presenters/scale_spec.rb | 7 +- .../subcategory_card_presenter_spec.rb | 24 +- spec/presenters/subcategory_presenter_spec.rb | 42 ++-- .../variance_chart_row_presenter_spec.rb | 99 +++++--- spec/rails_helper.rb | 6 +- .../routing/legacy/categories_routing_spec.rb | 38 ++- spec/routing/legacy/districts_routing_spec.rb | 38 ++- .../legacy/question_lists_routing_spec.rb | 38 ++- spec/routing/legacy/questions_routing_spec.rb | 38 ++- .../legacy/recipient_lists_routing_spec.rb | 49 ++-- .../routing/legacy/recipients_routing_spec.rb | 49 ++-- spec/routing/legacy/schedules_routing_spec.rb | 49 ++-- spec/routing/legacy/schools_routing_spec.rb | 38 ++- spec/spec_helper.rb | 115 ++++----- spec/support/shared_contexts/rake.rb | 8 +- spec/system/authentication_spec.rb | 2 +- spec/system/journey_spec.rb | 16 +- spec/views/categories/show.html.erb_spec.rb | 39 +-- spec/views/home/index.html.erb_spec.rb | 1 - .../legacy/categories/edit.html.erb_spec.rb | 29 ++- .../legacy/categories/index.html.erb_spec.rb | 46 ++-- .../legacy/categories/new.html.erb_spec.rb | 29 ++- .../legacy/categories/show.html.erb_spec.rb | 12 +- .../legacy/districts/edit.html.erb_spec.rb | 17 +- .../legacy/districts/index.html.erb_spec.rb | 26 +- .../legacy/districts/new.html.erb_spec.rb | 17 +- .../legacy/districts/show.html.erb_spec.rb | 12 +- .../question_lists/edit.html.erb_spec.rb | 21 +- .../question_lists/index.html.erb_spec.rb | 36 +-- .../question_lists/new.html.erb_spec.rb | 21 +- .../question_lists/show.html.erb_spec.rb | 14 +- .../legacy/questions/edit.html.erb_spec.rb | 37 ++- .../legacy/questions/index.html.erb_spec.rb | 60 ++--- .../legacy/questions/new.html.erb_spec.rb | 37 ++- .../legacy/questions/show.html.erb_spec.rb | 22 +- .../recipient_lists/edit.html.erb_spec.rb | 28 +-- .../recipient_lists/index.html.erb_spec.rb | 38 +-- .../recipient_lists/new.html.erb_spec.rb | 23 +- .../recipient_lists/show.html.erb_spec.rb | 14 +- .../legacy/recipients/edit.html.erb_spec.rb | 48 ++-- .../legacy/recipients/index.html.erb_spec.rb | 74 +++--- .../legacy/recipients/new.html.erb_spec.rb | 46 ++-- .../legacy/recipients/show.html.erb_spec.rb | 28 +-- .../legacy/schedules/edit.html.erb_spec.rb | 39 ++- .../legacy/schedules/new.html.erb_spec.rb | 39 ++- .../legacy/schedules/show.html.erb_spec.rb | 22 +- .../legacy/schools/edit.html.erb_spec.rb | 16 +- .../views/legacy/schools/new.html.erb_spec.rb | 16 +- .../legacy/schools/show.html.erb_spec.rb | 12 +- spec/views/overview/index.html.erb_spec.rb | 64 +++-- .../overview/variance_chart.html.erb_spec.rb | 10 +- 157 files changed, 2440 insertions(+), 1929 deletions(-) create mode 100644 db/migrate/20211217142634_add_benchmarks_to_survey_items.rb create mode 100644 db/migrate/20211217163827_add_benchmarks_to_admin_data_items.rb create mode 100644 db/migrate/20211217164449_remove_benchmarks_from_measures.rb create mode 100644 doc/architectural_decision_records/1.md create mode 100644 doc/architectural_decision_records/adr_template.md create mode 100644 spec/models/measure_spec.rb diff --git a/Gemfile b/Gemfile index 60ef5eab..78eed45a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,18 @@ source 'https://rubygems.org' -ruby "3.0.2" +ruby '3.0.2' git_source(:github) do |repo_name| - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') "https://github.com/#{repo_name}.git" end - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.1.4.1' gem 'pg' # Use Puma as the app server -gem "puma", ">= 5.5.2" +gem 'puma', '>= 5.5.2' # Use SCSS for stylesheets gem 'sassc-rails', require: false # Use Uglifier as compressor for JavaScript assets @@ -33,7 +32,7 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development -gem "nokogiri", ">= 1.12.5" +gem 'nokogiri', '>= 1.12.5' gem 'bootsnap', require: false @@ -64,24 +63,24 @@ end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console' gem 'listen', '~> 3.0.5' + gem 'web-console' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'nested_scaffold' + gem 'seed_dump' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' - gem 'seed_dump' - gem 'nested_scaffold' end group 'test' do - gem 'rspec-rails', '~> 4.1.2' - gem 'rails-controller-testing' - gem 'capybara' gem 'apparition', github: 'twalpole/apparition', ref: 'ca86be4d54af835d531dbcd2b86e7b2c77f85f34' - gem 'launchy' + gem 'capybara' gem 'database_cleaner' + gem 'launchy' + gem 'rails-controller-testing' + gem 'rspec-rails', '~> 4.1.2' gem 'timecop' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 28648b63..0f47bbfb 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,9 +1,7 @@ class CategoriesController < SqmApplicationController - def show @categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) } @category = CategoryPresenter.new(category: Category.find_by_slug(params[:id])) end - end diff --git a/app/controllers/legacy/admin_controller.rb b/app/controllers/legacy/admin_controller.rb index bd26b05e..99235260 100644 --- a/app/controllers/legacy/admin_controller.rb +++ b/app/controllers/legacy/admin_controller.rb @@ -1,8 +1,5 @@ module Legacy class AdminController < Legacy::ApplicationController - - def index - end - + def index; end end end diff --git a/app/controllers/legacy/application_controller.rb b/app/controllers/legacy/application_controller.rb index e31d4ff9..80cbc526 100644 --- a/app/controllers/legacy/application_controller.rb +++ b/app/controllers/legacy/application_controller.rb @@ -2,21 +2,21 @@ module Legacy class ApplicationController < ActionController::Base protect_from_forgery with: :exception, prepend: true - layout "legacy/application" + layout 'legacy/application' def verify_admin - return true #if current_user.admin?(@school) + return true # if current_user.admin?(@school) redirect_to root_path, notice: 'You must be logged in as an admin of that school to access that page.' - return false + false end def authenticate(username, password) - return true if username == "boston" + return true if username == 'boston' + authenticate_or_request_with_http_basic do |u, p| u == username && p == password end end - end end diff --git a/app/controllers/legacy/attempts_controller.rb b/app/controllers/legacy/attempts_controller.rb index 75481040..8738861f 100644 --- a/app/controllers/legacy/attempts_controller.rb +++ b/app/controllers/legacy/attempts_controller.rb @@ -1,7 +1,7 @@ module Legacy class AttemptsController < Legacy::ApplicationController # before_action :set_attempt, only: [:edit, :update] - protect_from_forgery :except => [:twilio] + protect_from_forgery except: [:twilio] def twilio recipient = Recipient.where(phone: twilio_params['From']).first @@ -15,19 +15,19 @@ module Legacy twilio_details: all_twilio_details.join('~!~') ) - unless (['start', 'resume', 'restart', 'yes', 'go'].index(twilio_params[:Body].downcase).nil?) + unless %w[start resume restart yes go].index(twilio_params[:Body].downcase).nil? recipient.update(opted_out: false) render plain: 'Thank you, you will now begin receiving messages again.' return end - unless (['stop', 'cancel', 'quit', 'no'].index(twilio_params[:Body].downcase).nil?) + unless %w[stop cancel quit no].index(twilio_params[:Body].downcase).nil? recipient.update(opted_out: true) render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.' return end - unless (['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil?) + unless ['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil? render plain: 'Thank you, this question has been skipped.' return end @@ -90,8 +90,10 @@ module Legacy # Never trust parameters from the scary internet, only allow the white list through. def twilio_params - { "Body" => "5", "" => "US", "To" => "+16172023890", "ToZip" => "02135", "NumSegments" => "1", "MessageSid" => "SMe37977e625b7f0b429339e752dddefef", "AccountSid" => "AC57dc8a5a6d75addb9528e730e92f66b2", "From" => "+16502693205", "ApiVersion" => "2010-04-01" } - params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia) + { 'Body' => '5', '' => 'US', 'To' => '+16172023890', 'ToZip' => '02135', 'NumSegments' => '1', + 'MessageSid' => 'SMe37977e625b7f0b429339e752dddefef', 'AccountSid' => 'AC57dc8a5a6d75addb9528e730e92f66b2', 'From' => '+16502693205', 'ApiVersion' => '2010-04-01' } + params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, + :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia) end end end diff --git a/app/controllers/legacy/categories_controller.rb b/app/controllers/legacy/categories_controller.rb index 4af54115..e7fc28e8 100644 --- a/app/controllers/legacy/categories_controller.rb +++ b/app/controllers/legacy/categories_controller.rb @@ -1,7 +1,7 @@ module Legacy class CategoriesController < Legacy::ApplicationController before_action :set_school, only: [:show] - before_action :set_category, only: [:show, :edit, :update, :destroy] + before_action :set_category, only: %i[show edit update destroy] # GET /categories # GET /categories.json @@ -17,7 +17,7 @@ module Legacy school_categories = SchoolCategory.for(@school, @category) @years = school_categories.map(&:year).map(&:to_i).sort - @year = (params[:year] || @years.last || "2019").to_i + @year = (params[:year] || @years.last || '2019').to_i if school_categories.empty? school_categories = [SchoolCategory.new(school: @school, category: @category, year: @year)] @@ -28,12 +28,11 @@ module Legacy missing_categories = Legacy::Category.for_parent(@category) - @child_school_categories.map(&:category) missing_categories.each do |category| next if category.benchmark.present? + @child_school_categories << category.school_categories.new(school: @school) end - if district.name == "Boston" - @child_school_categories = @child_school_categories.reject { |csc| csc.admin? } - end + @child_school_categories = @child_school_categories.reject { |csc| csc.admin? } if district.name == 'Boston' @questions = @category.questions.created_in(@year) end @@ -44,8 +43,7 @@ module Legacy end # GET /categories/1/edit - def edit - end + def edit; end # POST /categories # POST /categories.json @@ -91,6 +89,7 @@ module Legacy def set_school redirect_to root_path and return false unless params.include?(:school_id) + @school = Legacy::School.friendly.find(params[:school_id]) redirect_to root_path and return false if @school.nil? end diff --git a/app/controllers/legacy/districts_controller.rb b/app/controllers/legacy/districts_controller.rb index 4d8a5711..01adc74d 100644 --- a/app/controllers/legacy/districts_controller.rb +++ b/app/controllers/legacy/districts_controller.rb @@ -1,6 +1,6 @@ module Legacy class DistrictsController < Legacy::ApplicationController - before_action :set_district, only: [:show, :edit, :update, :destroy] + before_action :set_district, only: %i[show edit update destroy] # GET /districts # GET /districts.json @@ -21,8 +21,7 @@ module Legacy end # GET /districts/1/edit - def edit - end + def edit; end # POST /districts # POST /districts.json diff --git a/app/controllers/legacy/question_lists_controller.rb b/app/controllers/legacy/question_lists_controller.rb index b7efc71b..6dca78c6 100644 --- a/app/controllers/legacy/question_lists_controller.rb +++ b/app/controllers/legacy/question_lists_controller.rb @@ -1,6 +1,6 @@ module Legacy class QuestionListsController < Legacy::ApplicationController - before_action :set_question_list, only: [:show, :edit, :update, :destroy] + before_action :set_question_list, only: %i[show edit update destroy] # GET /question_lists # GET /question_lists.json @@ -10,8 +10,7 @@ module Legacy # GET /question_lists/1 # GET /question_lists/1.json - def show - end + def show; end # GET /question_lists/new def new @@ -19,8 +18,7 @@ module Legacy end # GET /question_lists/1/edit - def edit - end + def edit; end # POST /question_lists # POST /question_lists.json diff --git a/app/controllers/legacy/questions_controller.rb b/app/controllers/legacy/questions_controller.rb index 25aec47b..91c6de2e 100644 --- a/app/controllers/legacy/questions_controller.rb +++ b/app/controllers/legacy/questions_controller.rb @@ -3,7 +3,7 @@ module Legacy before_action :authenticate_user!, except: [:show] before_action :verify_super_admin, except: [:show] before_action :set_school, only: [:show] - before_action :set_question, only: [:show, :edit, :update, :destroy] + before_action :set_question, only: %i[show edit update destroy] # GET /questions # GET /questions.json @@ -13,8 +13,7 @@ module Legacy # GET /questions/1 # GET /questions/1.json - def show - end + def show; end # GET /questions/new def new @@ -22,8 +21,7 @@ module Legacy end # GET /questions/1/edit - def edit - end + def edit; end # POST /questions # POST /questions.json @@ -69,6 +67,7 @@ module Legacy def set_school redirect_to root_path and return false unless params.include?(:school_id) + @school = Legacy::School.friendly.find(params[:school_id]) redirect_to root_path and return false if @school.nil? end diff --git a/app/controllers/legacy/recipient_lists_controller.rb b/app/controllers/legacy/recipient_lists_controller.rb index 4887dabc..87505e1a 100644 --- a/app/controllers/legacy/recipient_lists_controller.rb +++ b/app/controllers/legacy/recipient_lists_controller.rb @@ -3,7 +3,7 @@ module Legacy before_action :authenticate_user! before_action :set_school before_action :verify_admin - before_action :set_recipient_list, only: [:show, :edit, :update, :destroy] + before_action :set_recipient_list, only: %i[show edit update destroy] # GET schools/1/recipient_lists def index @@ -11,8 +11,7 @@ module Legacy end # GET schools/1/recipient_lists/1 - def show - end + def show; end # GET schools/1/recipient_lists/new def new @@ -20,8 +19,7 @@ module Legacy end # GET schools/1/recipient_lists/1/edit - def edit - end + def edit; end # POST schools/1/recipient_lists def create diff --git a/app/controllers/legacy/recipients_controller.rb b/app/controllers/legacy/recipients_controller.rb index 15cd0655..ed38920b 100644 --- a/app/controllers/legacy/recipients_controller.rb +++ b/app/controllers/legacy/recipients_controller.rb @@ -3,7 +3,7 @@ module Legacy before_action :authenticate_user! before_action :set_school before_action :verify_admin - before_action :set_recipient, only: [:show, :edit, :update, :destroy] + before_action :set_recipient, only: %i[show edit update destroy] # GET /recipients # GET /recipients.json @@ -13,8 +13,7 @@ module Legacy # GET /recipients/1 # GET /recipients/1.json - def show - end + def show; end # GET /recipients/new def new @@ -22,8 +21,7 @@ module Legacy end # GET /recipients/1/edit - def edit - end + def edit; end # POST /recipients # POST /recipients.json @@ -32,7 +30,10 @@ module Legacy respond_to do |format| if @recipient.save - format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' } + format.html do + redirect_to legacy_school_legacy_recipient_path(@school, @recipient), + notice: 'Recipient was successfully created.' + end format.json { render :show, status: :created, location: @recipient } else format.html { render :new } @@ -45,7 +46,7 @@ module Legacy render and return if request.get? Recipient.import(@school, params[:file]) - redirect_to @school, notice: "Recipients imported." + redirect_to @school, notice: 'Recipients imported.' end # PATCH/PUT /recipients/1 @@ -53,7 +54,10 @@ module Legacy def update respond_to do |format| if @recipient.update(recipient_params) - format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' } + format.html do + redirect_to legacy_school_legacy_recipient_path(@school, @recipient), + notice: 'Recipient was successfully updated.' + end format.json { render :show, status: :ok, location: @recipient } else format.html { render :edit } @@ -86,7 +90,8 @@ module Legacy # Never trust parameters from the scary internet, only allow the white list through. def recipient_params - params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id) + params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, + :income, :opted_out, :school_id) end end end diff --git a/app/controllers/legacy/schedules_controller.rb b/app/controllers/legacy/schedules_controller.rb index 10931695..7ce14b85 100644 --- a/app/controllers/legacy/schedules_controller.rb +++ b/app/controllers/legacy/schedules_controller.rb @@ -3,12 +3,11 @@ module Legacy before_action :authenticate_user!, except: [:show] before_action :set_school before_action :verify_admin - before_action :set_schedule, only: [:show, :edit, :update, :destroy] - before_action :set_time, only: [:create, :update] + before_action :set_schedule, only: %i[show edit update destroy] + before_action :set_time, only: %i[create update] # GET schools/1/schedules/1 - def show - end + def show; end # GET schools/1/schedules/new def new @@ -16,8 +15,7 @@ module Legacy end # GET schools/1/schedules/1/edit - def edit - end + def edit; end # POST schools/1/schedules def create @@ -59,13 +57,14 @@ module Legacy # Only allow a trusted parameter "white list" through. def schedule_params - params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id) + params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, + :time, :active, :random, :recipient_list_id, :question_list_id) end def set_time return unless schedule_params.include?(:time) + params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER) end - end end diff --git a/app/controllers/legacy/schools_controller.rb b/app/controllers/legacy/schools_controller.rb index 05e4b83a..bc2c4c87 100644 --- a/app/controllers/legacy/schools_controller.rb +++ b/app/controllers/legacy/schools_controller.rb @@ -1,8 +1,8 @@ module Legacy class SchoolsController < Legacy::ApplicationController before_action :authenticate_user!, except: [:show] - before_action :set_school, only: [:admin, :show, :edit, :update, :destroy] - before_action :verify_admin, except: [:show, :create, :new] + before_action :set_school, only: %i[admin show edit update destroy] + before_action :verify_admin, except: %i[show create new] # GET /schools/1 # GET /schools/1.json @@ -13,7 +13,7 @@ module Legacy @years = [2017, 2018, 2019] @year = (params[:year] || @years.last).to_i - if @district.name == "Boston" + if @district.name == 'Boston' @categories = Legacy::Category.joins(:questions) @school_categories = SchoolCategory.where(school: @school).where(category: @categories).in(@year).to_a else @@ -29,8 +29,7 @@ module Legacy @school_categories = @school_categories.select { |sc| sc.year.to_i == @year } end - def admin - end + def admin; end # GET /schools/new def new @@ -38,8 +37,7 @@ module Legacy end # GET /schools/1/edit - def edit - end + def edit; end # POST /schools # POST /schools.json @@ -92,6 +90,5 @@ module Legacy def school_params params.require(:school).permit(:name, :district_id) end - end end diff --git a/app/controllers/legacy/welcome_controller.rb b/app/controllers/legacy/welcome_controller.rb index c064eecd..7e020471 100644 --- a/app/controllers/legacy/welcome_controller.rb +++ b/app/controllers/legacy/welcome_controller.rb @@ -1,10 +1,8 @@ module Legacy class WelcomeController < Legacy::ApplicationController - def index @districts = Legacy::District.all.alphabetic @schools = Legacy::School.all.alphabetic end - end end diff --git a/app/controllers/overview_controller.rb b/app/controllers/overview_controller.rb index 2c72f748..31a37e5e 100644 --- a/app/controllers/overview_controller.rb +++ b/app/controllers/overview_controller.rb @@ -1,5 +1,4 @@ class OverviewController < SqmApplicationController - def index @variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure)) @category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category: category) } diff --git a/app/controllers/sqm_application_controller.rb b/app/controllers/sqm_application_controller.rb index fc6d983f..bdbd63d8 100644 --- a/app/controllers/sqm_application_controller.rb +++ b/app/controllers/sqm_application_controller.rb @@ -27,7 +27,8 @@ class SqmApplicationController < ApplicationController end def authenticate(username, password) - return true if username == "boston" + return true if username == 'boston' + authenticate_or_request_with_http_basic do |u, p| u == username && p == password end diff --git a/app/helpers/gauge_helper.rb b/app/helpers/gauge_helper.rb index 1c37d842..afcdd4cb 100644 --- a/app/helpers/gauge_helper.rb +++ b/app/helpers/gauge_helper.rb @@ -21,8 +21,8 @@ module GaugeHelper def viewbox x = arc_center.x - (outer_radius + stroke_width) y = arc_center.y - (outer_radius + stroke_width) - key_benchmark_indicator_gutter - width = 2*(outer_radius + stroke_width) - height = outer_radius + 2*stroke_width + key_benchmark_indicator_gutter + width = 2 * (outer_radius + stroke_width) + height = outer_radius + 2 * stroke_width + key_benchmark_indicator_gutter Rect.new(x, y, width, height) end @@ -35,11 +35,13 @@ module GaugeHelper end def indicator_right_corner - Point.new(key_benchmark_indicator_gutter/Math.sqrt(3), arc_center.y - outer_radius - key_benchmark_indicator_gutter) + Point.new(key_benchmark_indicator_gutter / Math.sqrt(3), + arc_center.y - outer_radius - key_benchmark_indicator_gutter) end def indicator_left_corner - Point.new(-key_benchmark_indicator_gutter/Math.sqrt(3), arc_center.y - outer_radius - key_benchmark_indicator_gutter) + Point.new(-key_benchmark_indicator_gutter / Math.sqrt(3), + arc_center.y - outer_radius - key_benchmark_indicator_gutter) end def arc_radius(radius) @@ -74,7 +76,8 @@ module GaugeHelper def draw_arc(radius:, percentage:, clockwise:) sweep_flag = clockwise ? 1 : 0 - "A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius: radius, percentage: percentage))}" + "A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius: radius, + percentage: percentage))}" end def draw_line_to(point:) @@ -82,8 +85,8 @@ module GaugeHelper end def benchmark_line_point(radius, angle) - x = "#{radius * Math.cos(angle)}" - y = "#{radius * Math.sin(angle) + arc_center.y}" + x = (radius * Math.cos(angle)).to_s + y = (radius * Math.sin(angle) + arc_center.y).to_s Point.new(x, y) end diff --git a/app/helpers/header_helper.rb b/app/helpers/header_helper.rb index 5e5e43c5..391c4b67 100644 --- a/app/helpers/header_helper.rb +++ b/app/helpers/header_helper.rb @@ -1,5 +1,4 @@ module HeaderHelper - def link_to_overview(district:, school:, academic_year:) "/districts/#{district.slug}/schools/#{school.slug}/overview?year=#{academic_year.range}" end @@ -9,18 +8,20 @@ module HeaderHelper end def district_url_for(district:, academic_year:) - overview_link(district_slug: district.slug, school_slug: district.schools.alphabetic.first.slug, academic_year_range: academic_year.range, uri_path: request.fullpath) + overview_link(district_slug: district.slug, school_slug: district.schools.alphabetic.first.slug, + academic_year_range: academic_year.range, uri_path: request.fullpath) end def school_url_for(school:, academic_year:) - overview_link(district_slug: school.district.slug, school_slug: school.slug, academic_year_range: academic_year.range, uri_path: request.fullpath) + overview_link(district_slug: school.district.slug, school_slug: school.slug, + academic_year_range: academic_year.range, uri_path: request.fullpath) end def school_mapper(school) { name: school.name, district_id: school.district_id, - url: district_school_overview_index_path(school.district, school, {year: AcademicYear.first.range}) + url: district_school_overview_index_path(school.district, school, { year: AcademicYear.first.range }) } end @@ -31,14 +32,14 @@ module HeaderHelper private def overview_link(district_slug:, school_slug:, academic_year_range:, uri_path:) - if uri_path.include?("overview") + if uri_path.include?('overview') return "/districts/#{district_slug}/schools/#{school_slug}/overview?year=#{academic_year_range}" end + "/districts/#{district_slug}/schools/#{school_slug}/browse/teachers-and-leadership?year=#{academic_year_range}" end def active?(path:) request.fullpath.include? path end - end diff --git a/app/helpers/schedules_helper.rb b/app/helpers/schedules_helper.rb index d2794569..50b8593b 100644 --- a/app/helpers/schedules_helper.rb +++ b/app/helpers/schedules_helper.rb @@ -1,5 +1,4 @@ module SchedulesHelper - def options_for_frequency_hours [ ['Once A Day', 24], @@ -10,9 +9,9 @@ module SchedulesHelper end def options_for_time - words = ['AM', 'PM'].map do |time| + words = %w[AM PM].map do |time| [12, *(1..11)].map do |hour| - ['00', '30'].map do |minute| + %w[00 30].map do |minute| "#{hour}:#{minute} #{time}" end end diff --git a/app/helpers/variance_helper.rb b/app/helpers/variance_helper.rb index ba6175ac..7d96b6a0 100644 --- a/app/helpers/variance_helper.rb +++ b/app/helpers/variance_helper.rb @@ -37,11 +37,11 @@ module VarianceHelper end def zones - %w(warning watch growth approval ideal) + %w[warning watch growth approval ideal] end def zone_width_percentage - 100.0/zones.size + 100.0 / zones.size end def availability_indicator_percentage @@ -51,5 +51,4 @@ module VarianceHelper def partial_data_indicator_size 16 end - end diff --git a/app/lib/seeder.rb b/app/lib/seeder.rb index d8a3d18c..40aaacc7 100644 --- a/app/lib/seeder.rb +++ b/app/lib/seeder.rb @@ -7,7 +7,7 @@ class Seeder end end - def seed_districts_and_schools csv_file + def seed_districts_and_schools(csv_file) dese_ids = [] CSV.parse(File.read(csv_file), headers: true) do |row| district_name = row['District'].strip @@ -29,7 +29,7 @@ class Seeder School.where.not(dese_id: dese_ids).destroy_all end - def seed_sqm_framework csv_file + def seed_sqm_framework(csv_file) CSV.parse(File.read(csv_file), headers: true) do |row| category_id = row['Category ID'].strip category = Category.find_or_create_by!(category_id: category_id) @@ -38,9 +38,10 @@ class Seeder '2' => 'school-culture', '3' => 'resources', '4' => 'academic-learning', - '5' => 'community-and-wellbeing', + '5' => 'community-and-wellbeing' } - category.update! name: row['Category'].strip, description: row['Category Description'].strip, short_description: row['Category Short Description'], slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id) + category.update! name: row['Category'].strip, description: row['Category Description'].strip, + short_description: row['Category Short Description'], slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id) subcategory_id = row['Subcategory ID'].strip subcategory = Subcategory.find_or_create_by! subcategory_id: subcategory_id, category: category @@ -55,26 +56,28 @@ class Seeder measure_description = row['Measure Description'].try(:strip) next if row['Source'] == 'No source' + measure = Measure.find_or_create_by! measure_id: measure_id, subcategory: subcategory measure.name = measure_name measure.description = measure_description - - if ['Teachers', 'Students'].include? row['Source'] - measure.watch_low_benchmark = watch_low if watch_low - measure.growth_low_benchmark = growth_low if growth_low - measure.approval_low_benchmark = approval_low if approval_low - measure.ideal_low_benchmark = ideal_low if ideal_low - end measure.save! data_item_id = row['Survey Item ID'].strip - if ['Teachers', 'Students'].include? row['Source'] + if %w[Teachers Students].include? row['Source'] survey_item = SurveyItem.find_or_create_by! survey_item_id: data_item_id, measure: measure + survey_item.watch_low_benchmark = watch_low if watch_low + survey_item.growth_low_benchmark = growth_low if growth_low + survey_item.approval_low_benchmark = approval_low if approval_low + survey_item.ideal_low_benchmark = ideal_low if ideal_low survey_item.update! prompt: row['Question/item (20-21)'].strip end if row['Source'] == 'Admin Data' admin_data_item = AdminDataItem.find_or_create_by! admin_data_item_id: data_item_id, measure: measure + admin_data_item.watch_low_benchmark = watch_low if watch_low + admin_data_item.growth_low_benchmark = growth_low if growth_low + admin_data_item.approval_low_benchmark = approval_low if approval_low + admin_data_item.ideal_low_benchmark = ideal_low if ideal_low admin_data_item.update! description: row['Question/item (20-21)'].strip end end diff --git a/app/models/academic_year.rb b/app/models/academic_year.rb index cf3aa583..99a8f449 100644 --- a/app/models/academic_year.rb +++ b/app/models/academic_year.rb @@ -1,5 +1,4 @@ class AcademicYear < ActiveRecord::Base - def self.find_by_date(date) if date.month > 6 ay_range_start = date.year @@ -10,5 +9,4 @@ class AcademicYear < ActiveRecord::Base end AcademicYear.find_by_range("#{ay_range_start}-#{ay_range_end.to_s[2, 3]}") end - end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 75fe3837..fc09e269 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,4 +1,4 @@ -# TODO move this to legacy, probably? +# TODO: move this to legacy, probably? class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/category.rb b/app/models/category.rb index 73b4e400..3b3d34b6 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -2,7 +2,7 @@ class Category < ActiveRecord::Base include FriendlyId friendly_id :name, use: [:slugged] - scope :sorted, ->() { order(:sort_index) } + scope :sorted, -> { order(:sort_index) } has_many :subcategories has_many :measures, through: :subcategories diff --git a/app/models/legacy/attempt.rb b/app/models/legacy/attempt.rb index c6849a9e..5371fb0a 100644 --- a/app/models/legacy/attempt.rb +++ b/app/models/legacy/attempt.rb @@ -2,7 +2,6 @@ require 'twilio-ruby' module Legacy class Attempt < ApplicationRecord - belongs_to :schedule belongs_to :recipient belongs_to :recipient_schedule @@ -12,16 +11,16 @@ module Legacy after_save :update_school_categories after_commit :update_counts - scope :for_question, -> (question) { where(question_id: question.id) } - scope :for_recipient, -> (recipient) { where(recipient_id: recipient.id) } - scope :for_student, -> (student) { where(student_id: student.id) } - scope :for_category, -> (category) { joins(:question).merge(Question.for_category(category)) } - scope :for_school, -> (school) { joins(:recipient).merge(Legacy::Recipient.for_school(school)) } + scope :for_question, ->(question) { where(question_id: question.id) } + scope :for_recipient, ->(recipient) { where(recipient_id: recipient.id) } + scope :for_student, ->(student) { where(student_id: student.id) } + scope :for_category, ->(category) { joins(:question).merge(Question.for_category(category)) } + scope :for_school, ->(school) { joins(:recipient).merge(Legacy::Recipient.for_school(school)) } scope :with_answer, -> { where('answer_index is not null or open_response_id is not null') } scope :with_no_answer, -> { where('answer_index is null and open_response_id is null') } scope :not_yet_responded, -> { where(responded_at: nil) } scope :last_sent, -> { order(sent_at: :desc) } - scope :created_in, -> (year) { where('extract(year from legacy_attempts.created_at) = ?', year) } + scope :created_in, ->(year) { where('extract(year from legacy_attempts.created_at) = ?', year) } def messages child_specific = student.present? ? " (for #{student.name})" : '' @@ -53,6 +52,7 @@ module Legacy def response return 'No Answer Yet' if answer_index.blank? + question.options[answer_index_with_reverse - 1] end @@ -63,20 +63,20 @@ module Legacy responded_at: responded_at ) - if recipient_schedule.queued_question_ids.present? - recipient_schedule.update(next_attempt_at: Time.new) - end + recipient_schedule.update(next_attempt_at: Time.new) if recipient_schedule.queued_question_ids.present? end def answer_index_with_reverse return 6 - answer_index if question.reverse? - return answer_index + + answer_index end private def update_school_categories return if ENV['BULK_PROCESS'] + school_category = SchoolCategory.for(recipient.school, question.category).first if school_category.nil? school_category = SchoolCategory.create(school: recipient.school, category: question.category) @@ -86,8 +86,8 @@ module Legacy def update_counts return if ENV['BULK_PROCESS'] + recipient.update_counts end - end end diff --git a/app/models/legacy/category.rb b/app/models/legacy/category.rb index e7b9264d..f916f5b9 100644 --- a/app/models/legacy/category.rb +++ b/app/models/legacy/category.rb @@ -1,6 +1,5 @@ module Legacy class Category < ApplicationRecord - has_many :questions belongs_to :parent_category, class_name: 'Legacy::Category', foreign_key: :parent_category_id has_many :child_categories, class_name: 'Legacy::Category', foreign_key: :parent_category_id @@ -8,11 +7,11 @@ module Legacy validates :name, presence: true - scope :for_parent, -> (category = nil) { where(parent_category_id: category.try(:id)) } - scope :likert, -> { where("benchmark is null") } + scope :for_parent, ->(category = nil) { where(parent_category_id: category.try(:id)) } + scope :likert, -> { where('benchmark is null') } include FriendlyId - friendly_id :name, :use => [:slugged] + friendly_id :name, use: [:slugged] def path p = self @@ -30,23 +29,24 @@ module Legacy end def self.root_identifiers - [ - "teachers-and-the-teaching-environment", - "school-culture", - "resources", - "academic-learning", - "community-and-wellbeing", - "pilot-family-questions" + %w[ + teachers-and-the-teaching-environment + school-culture + resources + academic-learning + community-and-wellbeing + pilot-family-questions ] end def self.root - Category.where(parent_category: nil).select { |c| self.root_identifiers.index(c.slug) } + Category.where(parent_category: nil).select { |c| root_identifiers.index(c.slug) } end def custom_zones return [] if zones.nil? - zones.split(",").map(&:to_f) + + zones.split(',').map(&:to_f) end def zone_widths @@ -57,18 +57,17 @@ module Legacy end widths[4] = widths[4] + (5 - widths.sum) - return widths + widths end def sync_child_zones likert_child_categories = child_categories.likert return unless likert_child_categories.present? + total_zones = [0, 0, 0, 0, 0] valid_child_categories = 0 likert_child_categories.each do |cc| - if cc.zones.nil? - cc.sync_child_zones - end + cc.sync_child_zones if cc.zones.nil? if cc.zones.nil? puts "NO ZONES: #{name} -> #{cc.name}" @@ -87,9 +86,8 @@ module Legacy if valid_child_categories > 0 average_zones = total_zones.map { |zone| zone / valid_child_categories } puts "TOTAL: #{name} | #{total_zones} | #{valid_child_categories} | #{average_zones} | #{zone_widths}" - update(zones: average_zones.join(",")) + update(zones: average_zones.join(',')) end end - end end diff --git a/app/models/legacy/question.rb b/app/models/legacy/question.rb index 0ec09b9e..7916d0ad 100644 --- a/app/models/legacy/question.rb +++ b/app/models/legacy/question.rb @@ -22,10 +22,10 @@ module Legacy validates :option4, presence: true validates :option5, presence: true - scope :for_category, -> (category) { where(category: category) } - scope :created_in, -> (year) { where("extract(year from #{self.table_name}.created_at) = ?", year) } + scope :for_category, ->(category) { where(category: category) } + scope :created_in, ->(year) { where("extract(year from #{table_name}.created_at) = ?", year) } - enum target_group: [:unknown, :for_students, :for_teachers, :for_parents] + enum target_group: %i[unknown for_students for_teachers for_parents] def source target_group.gsub('for_', '') @@ -37,6 +37,7 @@ module Legacy def options_with_reverse return options.reverse if reverse? + options end @@ -48,7 +49,9 @@ module Legacy school_responses = attempts.for_school(school).with_answer.order(id: :asc) return unless school_responses.present? - response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index_with_reverse } + response_answer_total = school_responses.inject(0) do |total, response| + total + response.answer_index_with_reverse + end histogram = school_responses.group_by(&:answer_index_with_reverse) most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0] @@ -66,7 +69,7 @@ module Legacy end def normalized_text - text.gsub("[science/math/English/social studies]", "") + text.gsub('[science/math/English/social studies]', '') end end end diff --git a/app/models/legacy/question_list.rb b/app/models/legacy/question_list.rb index ef2df464..6a2582ec 100644 --- a/app/models/legacy/question_list.rb +++ b/app/models/legacy/question_list.rb @@ -1,10 +1,10 @@ module Legacy class QuestionList < ApplicationRecord - validates :name, presence: true validates :question_ids, presence: true attr_accessor :question_id_array + before_validation :convert_question_id_array after_initialize :set_question_id_array @@ -16,13 +16,14 @@ module Legacy def convert_question_id_array return if question_id_array.blank? + self.question_ids = question_id_array.reject { |id| id.to_s.empty? }.join(',') end def set_question_id_array return if question_ids.blank? + self.question_id_array = question_ids.split(',').map(&:to_i) end - end end diff --git a/app/models/legacy/recipient.rb b/app/models/legacy/recipient.rb index 6f8366ae..0ad1854e 100644 --- a/app/models/legacy/recipient.rb +++ b/app/models/legacy/recipient.rb @@ -12,8 +12,8 @@ module Legacy validates :name, presence: true - scope :for_school, -> (school) { where(school: school) } - scope :created_in, -> (year) { where('extract(year from recipients.created_at) = ?', year) } + scope :for_school, ->(school) { where(school: school) } + scope :created_in, ->(year) { where('extract(year from recipients.created_at) = ?', year) } before_destroy :sync_lists @@ -43,10 +43,10 @@ module Legacy def sync_lists school.recipient_lists.each do |recipient_list| next if recipient_list.recipient_id_array.index(id).nil? + updated_ids = recipient_list.recipient_id_array - [id] recipient_list.update(recipient_id_array: updated_ids) end end - end end diff --git a/app/models/legacy/recipient_list.rb b/app/models/legacy/recipient_list.rb index d3835477..fca266c7 100644 --- a/app/models/legacy/recipient_list.rb +++ b/app/models/legacy/recipient_list.rb @@ -7,6 +7,7 @@ module Legacy validates :name, presence: true attr_accessor :recipient_id_array + before_validation :convert_recipient_id_array after_initialize :set_recipient_id_array @@ -20,16 +21,19 @@ module Legacy def convert_recipient_id_array return if recipient_id_array.blank? || (recipient_ids_was != recipient_ids) + self.recipient_ids = recipient_id_array.reject { |id| id.to_s.empty? }.join(',') end def set_recipient_id_array return if recipient_id_array.present? + self.recipient_id_array = (recipient_ids || '').split(',').map(&:to_i) end def sync_recipient_schedules return unless recipient_ids_before_last_save.present? && recipient_ids_before_last_save != recipient_ids + old_ids = recipient_ids_before_last_save.split(/,/) new_ids = recipient_ids.split(/,/) (old_ids - new_ids).each do |deleted_recipient| @@ -44,6 +48,5 @@ module Legacy end end end - end end diff --git a/app/models/legacy/recipient_schedule.rb b/app/models/legacy/recipient_schedule.rb index c205ef26..df823d4b 100644 --- a/app/models/legacy/recipient_schedule.rb +++ b/app/models/legacy/recipient_schedule.rb @@ -1,6 +1,5 @@ module Legacy class RecipientSchedule < ApplicationRecord - belongs_to :recipient belongs_to :schedule has_many :attempts @@ -10,25 +9,29 @@ module Legacy validates :next_attempt_at, presence: true scope :ready, -> { where('next_attempt_at <= ?', Time.new) } - scope :for_recipient, -> (recipient_or_recipient_id) { - id = recipient_or_recipient_id.is_a?(Recipient) ? - recipient_or_recipient_id.id : + scope :for_recipient, lambda { |recipient_or_recipient_id| + id = if recipient_or_recipient_id.is_a?(Recipient) + recipient_or_recipient_id.id + else recipient_or_recipient_id + end where(recipient_id: id) } - scope :for_schedule, -> (schedule_or_schedule_id) { - id = schedule_or_schedule_id.is_a?(Schedule) ? - schedule_or_schedule_id.id : + scope :for_schedule, lambda { |schedule_or_schedule_id| + id = if schedule_or_schedule_id.is_a?(Schedule) + schedule_or_schedule_id.id + else schedule_or_schedule_id + end where(schedule_id: id) } def next_question - if queued_question_ids.present? - next_question_id = queued_question_ids.split(/,/).first - else - next_question_id = upcoming_question_ids.split(/,/).first - end + next_question_id = if queued_question_ids.present? + queued_question_ids.split(/,/).first + else + upcoming_question_ids.split(/,/).first + end Question.where(id: next_question_id).first end @@ -48,16 +51,12 @@ module Legacy return if recipient.opted_out? return if question.nil? - if !question.for_recipient_students? - return attempt_question(question: question) - end + return attempt_question(question: question) unless question.for_recipient_students? missing_students = [] recipient_attempts = attempts.for_recipient(recipient).for_question(question) recipient.students.each do |student| - if recipient_attempts.for_student(student).empty? - missing_students << student - end + missing_students << student if recipient_attempts.for_student(student).empty? end attempt = recipient.attempts.create( @@ -74,7 +73,7 @@ module Legacy if question.present? question_id = [question.id.to_s] - upcoming = upcoming - question_id + upcoming -= question_id if missing_students.length > 1 queued += question_id else @@ -91,19 +90,18 @@ module Legacy next_attempt_at: next_valid_attempt_time ) end - return attempt + attempt end def attempt_question(send_message: true, question: next_question) return if recipient.opted_out? + unanswered_attempt = recipient.attempts.not_yet_responded.last return if question.nil? && unanswered_attempt.nil? if unanswered_attempt.nil? - if question.for_recipient_students? - return attempt_question_for_recipient_students(question: question) - end + return attempt_question_for_recipient_students(question: question) if question.for_recipient_students? attempt = recipient.attempts.create( schedule: schedule, @@ -119,7 +117,7 @@ module Legacy if question.present? question_id = [question.id.to_s] - upcoming = upcoming - question_id + upcoming -= question_id if unanswered_attempt.nil? attempted += question_id queued -= question_id @@ -136,13 +134,13 @@ module Legacy next_attempt_at: next_valid_attempt_time ) end - return (unanswered_attempt || attempt) + (unanswered_attempt || attempt) end def next_valid_attempt_time local_time = (next_attempt_at + (60 * 60 * schedule.frequency_hours)).in_time_zone('Eastern Time (US & Canada)') local_time += 1.day while local_time.on_weekend? - return local_time + local_time end def self.create_for_recipient(recipient_or_recipient_id, schedule, next_attempt_at = nil) @@ -154,9 +152,11 @@ module Legacy question_ids = schedule.question_list.question_ids.split(/,/) question_ids = question_ids.shuffle if schedule.random? - recipient_id = recipient_or_recipient_id.is_a?(Recipient) ? - recipient_or_recipient_id.id : + recipient_id = if recipient_or_recipient_id.is_a?(Recipient) + recipient_or_recipient_id.id + else recipient_or_recipient_id + end schedule.recipient_schedules.create( recipient_id: recipient_id, @@ -164,6 +164,5 @@ module Legacy next_attempt_at: next_attempt_at ) end - end end diff --git a/app/models/legacy/schedule.rb b/app/models/legacy/schedule.rb index fb5ac34a..698424a1 100644 --- a/app/models/legacy/schedule.rb +++ b/app/models/legacy/schedule.rb @@ -12,14 +12,15 @@ module Legacy before_validation :set_start_date after_create :create_recipient_schedules - scope :active, -> { - where(active: true).where("start_date <= ? and end_date > ?", Date.today, Date.today) + scope :active, lambda { + where(active: true).where('start_date <= ? and end_date > ?', Date.today, Date.today) } private def set_start_date return if start_date.present? + self.start_date = Date.today end @@ -28,6 +29,5 @@ module Legacy RecipientSchedule.create_for_recipient(recipient, self) end end - end end diff --git a/app/models/legacy/school_question.rb b/app/models/legacy/school_question.rb index 3fbbdb38..cecd18bd 100644 --- a/app/models/legacy/school_question.rb +++ b/app/models/legacy/school_question.rb @@ -1,6 +1,5 @@ module Legacy class SchoolQuestion < ApplicationRecord - belongs_to :school belongs_to :question belongs_to :school_category @@ -9,17 +8,17 @@ module Legacy validates_associated :question validates_associated :school_category - scope :for, -> (school, question) { where(school_id: school.id, question_id: question.id) } - scope :in, -> (year) { where(year: year) } + scope :for, ->(school, question) { where(school_id: school.id, question_id: question.id) } + scope :in, ->(year) { where(year: year) } def sync_attempts - attempt_data = Attempt. - joins(:question). - created_in(school_category.year). - for_question(question). - for_school(school). - select('count(attempts.answer_index) as response_count'). - select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] + attempt_data = Attempt + .joins(:question) + .created_in(school_category.year) + .for_question(question) + .for_school(school) + .select('count(attempts.answer_index) as response_count') + .select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] available_responders = school.available_responders_for(question) @@ -30,6 +29,5 @@ module Legacy response_total: attempt_data.answer_index_total ) end - end end diff --git a/app/models/legacy/user_school.rb b/app/models/legacy/user_school.rb index 003191ce..6c5f8c79 100644 --- a/app/models/legacy/user_school.rb +++ b/app/models/legacy/user_school.rb @@ -1,9 +1,7 @@ module Legacy class UserSchool < ApplicationRecord - belongs_to :user belongs_to :school belongs_to :district - end end diff --git a/app/models/measure.rb b/app/models/measure.rb index d8bddbe5..762ffde3 100644 --- a/app/models/measure.rb +++ b/app/models/measure.rb @@ -22,15 +22,15 @@ class Measure < ActiveRecord::Base end def includes_teacher_survey_items? - teacher_survey_items.any? + @includes_teacher_survey_items ||= teacher_survey_items.any? end def includes_student_survey_items? - student_survey_items.any? + @includes_student_survey_items ||= student_survey_items.any? end def includes_admin_data_items? - admin_data_items.any? + @includes_admin_data_items ||= admin_data_items.any? end def sources @@ -40,4 +40,45 @@ class Measure < ActiveRecord::Base sources << :teacher_surveys if includes_teacher_survey_items? sources end + + def warning_low_benchmark + return @warning_low_benchmark unless @warning_low_benchmark.nil? + + @warning_low_benchmark = benchmark(:warning_low_benchmark) + end + + def watch_low_benchmark + return @watch_low_benchmark unless @watch_low_benchmark.nil? + + @watch_low_benchmark = benchmark(:watch_low_benchmark) + end + + def growth_low_benchmark + return @growth_low_benchmark unless @growth_low_benchmark.nil? + + @growth_low_benchmark = benchmark(:growth_low_benchmark) + end + + def approval_low_benchmark + return @approval_low_benchmark unless @approval_low_benchmark.nil? + + @approval_low_benchmark = benchmark(:approval_low_benchmark) + end + + def ideal_low_benchmark + return @ideal_low_benchmark unless @ideal_low_benchmark.nil? + + @ideal_low_benchmark = benchmark(:ideal_low_benchmark) + end + + private + + def benchmark(name) + averages = [] + averages << student_survey_items.first.send(name) if includes_student_survey_items? + averages << teacher_survey_items.first.send(name) if includes_teacher_survey_items? + (averages << admin_data_items.map(&name)).flatten! if includes_admin_data_items? + + averages.average + end end diff --git a/app/models/survey_item_response.rb b/app/models/survey_item_response.rb index 1dfbaf49..de62a336 100644 --- a/app/models/survey_item_response.rb +++ b/app/models/survey_item_response.rb @@ -7,7 +7,9 @@ class SurveyItemResponse < ActiveRecord::Base belongs_to :survey_item def self.score_for_subcategory(subcategory:, school:, academic_year:) - measures = subcategory.measures.select { |measure| sufficient_data?(measure: measure, school: school, academic_year: academic_year) } + measures = subcategory.measures.select do |measure| + sufficient_data?(measure: measure, school: school, academic_year: academic_year) + end SurveyItemResponse.for_measures(measures) .where(academic_year: academic_year, school: school) @@ -27,9 +29,7 @@ class SurveyItemResponse < ActiveRecord::Base SurveyItemResponse.student_responses_for_measure(measure) end - unless survey_item_responses.nil? - score_for_measure = survey_item_responses.average(:likert_score) - end + score_for_measure = survey_item_responses.average(:likert_score) unless survey_item_responses.nil? Score.new(score_for_measure, meets_teacher_threshold, meets_student_threshold) end @@ -40,17 +40,20 @@ class SurveyItemResponse < ActiveRecord::Base meets_teacher_threshold || meets_student_threshold end - private - scope :for_measure, ->(measure) { joins(:survey_item).where('survey_items.measure_id': measure.id) } scope :for_measures, ->(measures) { joins(:survey_item).where('survey_items.measure_id': measures.map(&:id)) } - scope :teacher_responses_for_measure, ->(measure) { for_measure(measure).where("survey_items.survey_item_id LIKE 't-%'") } - scope :student_responses_for_measure, ->(measure) { for_measure(measure).where("survey_items.survey_item_id LIKE 's-%'") } - + scope :teacher_responses_for_measure, lambda { |measure| + for_measure(measure).where("survey_items.survey_item_id LIKE 't-%'") + } + scope :student_responses_for_measure, lambda { |measure| + for_measure(measure).where("survey_items.survey_item_id LIKE 's-%'") + } def self.student_sufficient_data?(measure:, school:, academic_year:) if measure.includes_student_survey_items? - student_survey_item_responses = SurveyItemResponse.student_responses_for_measure(measure).where(academic_year: academic_year, school: school) + student_survey_item_responses = SurveyItemResponse.student_responses_for_measure(measure).where( + academic_year: academic_year, school: school + ) average_number_of_survey_item_responses = student_survey_item_responses.count / measure.student_survey_items.count meets_student_threshold = average_number_of_survey_item_responses >= STUDENT_RESPONSE_THRESHOLD @@ -60,7 +63,9 @@ class SurveyItemResponse < ActiveRecord::Base def self.teacher_sufficient_data?(measure:, school:, academic_year:) if measure.includes_teacher_survey_items? - teacher_survey_item_responses = SurveyItemResponse.teacher_responses_for_measure(measure).where(academic_year: academic_year, school: school) + teacher_survey_item_responses = SurveyItemResponse.teacher_responses_for_measure(measure).where( + academic_year: academic_year, school: school + ) average_number_of_survey_item_responses = teacher_survey_item_responses.count / measure.teacher_survey_items.count meets_teacher_threshold = average_number_of_survey_item_responses >= TEACHER_RESPONSE_THRESHOLD diff --git a/app/presenters/admin_data_presenter.rb b/app/presenters/admin_data_presenter.rb index 7ca1cc25..add6dacf 100644 --- a/app/presenters/admin_data_presenter.rb +++ b/app/presenters/admin_data_presenter.rb @@ -5,7 +5,7 @@ class AdminDataPresenter < DataItemPresenter end def title - "School admin data" + 'School admin data' end def id @@ -17,6 +17,6 @@ class AdminDataPresenter < DataItemPresenter end def reason_for_insufficiency - "limited availability" + 'limited availability' end end diff --git a/app/presenters/gauge_presenter.rb b/app/presenters/gauge_presenter.rb index d6fa7eaa..87298315 100644 --- a/app/presenters/gauge_presenter.rb +++ b/app/presenters/gauge_presenter.rb @@ -28,6 +28,7 @@ class GaugePresenter def percentage_for(number) return nil if number.nil? + scale_minimum = @scale.warning_zone.low_benchmark scale_maximum = @scale.ideal_zone.high_benchmark diff --git a/app/presenters/measure_presenter.rb b/app/presenters/measure_presenter.rb index dc31e35c..1c7bd2a2 100644 --- a/app/presenters/measure_presenter.rb +++ b/app/presenters/measure_presenter.rb @@ -26,10 +26,19 @@ class MeasurePresenter end def data_item_presenters - Array.new.tap do |array| - array << StudentSurveyPresenter.new(measure_id: @measure.measure_id, survey_items: @measure.student_survey_items, has_sufficient_data: score_for_measure.meets_student_threshold?) if @measure.student_survey_items.any? - array << TeacherSurveyPresenter.new(measure_id: @measure.measure_id, survey_items: @measure.teacher_survey_items, has_sufficient_data: score_for_measure.meets_teacher_threshold?) if @measure.teacher_survey_items.any? - array << AdminDataPresenter.new(measure_id: @measure.measure_id, admin_data_items: @measure.admin_data_items) if @measure.admin_data_items.any? + [].tap do |array| + if @measure.student_survey_items.any? + array << StudentSurveyPresenter.new(measure_id: @measure.measure_id, survey_items: @measure.student_survey_items, + has_sufficient_data: score_for_measure.meets_student_threshold?) + end + if @measure.teacher_survey_items.any? + array << TeacherSurveyPresenter.new(measure_id: @measure.measure_id, survey_items: @measure.teacher_survey_items, + has_sufficient_data: score_for_measure.meets_teacher_threshold?) + end + if @measure.admin_data_items.any? + array << AdminDataPresenter.new(measure_id: @measure.measure_id, + admin_data_items: @measure.admin_data_items) + end end end @@ -44,7 +53,7 @@ class MeasurePresenter watch_low_benchmark: @measure.watch_low_benchmark, growth_low_benchmark: @measure.growth_low_benchmark, approval_low_benchmark: @measure.approval_low_benchmark, - ideal_low_benchmark: @measure.ideal_low_benchmark, + ideal_low_benchmark: @measure.ideal_low_benchmark ) end end diff --git a/app/presenters/scale.rb b/app/presenters/scale.rb index 760c4488..f5aa674d 100644 --- a/app/presenters/scale.rb +++ b/app/presenters/scale.rb @@ -30,7 +30,7 @@ class Scale end def insufficient_data - Zone.new(0,@warning_low_benchmark,:insufficient_data) + Zone.new(0, @warning_low_benchmark, :insufficient_data) end def zone_for_score(score) diff --git a/app/presenters/student_survey_presenter.rb b/app/presenters/student_survey_presenter.rb index 3fc86ddb..66426467 100644 --- a/app/presenters/student_survey_presenter.rb +++ b/app/presenters/student_survey_presenter.rb @@ -5,7 +5,7 @@ class StudentSurveyPresenter < DataItemPresenter end def title - "Student survey" + 'Student survey' end def id @@ -17,6 +17,6 @@ class StudentSurveyPresenter < DataItemPresenter end def reason_for_insufficiency - "low response rate" + 'low response rate' end end diff --git a/app/presenters/subcategory_presenter.rb b/app/presenters/subcategory_presenter.rb index 9750c85f..af86ef87 100644 --- a/app/presenters/subcategory_presenter.rb +++ b/app/presenters/subcategory_presenter.rb @@ -31,7 +31,9 @@ class SubcategoryPresenter end def measure_presenters - @subcategory.measures.sort_by(&:measure_id).map { |measure| MeasurePresenter.new(measure: measure, academic_year: @academic_year, school: @school) } + @subcategory.measures.sort_by(&:measure_id).map do |measure| + MeasurePresenter.new(measure: measure, academic_year: @academic_year, school: @school) + end end private diff --git a/app/presenters/teacher_survey_presenter.rb b/app/presenters/teacher_survey_presenter.rb index 126ed5ec..73bb49bf 100644 --- a/app/presenters/teacher_survey_presenter.rb +++ b/app/presenters/teacher_survey_presenter.rb @@ -5,7 +5,7 @@ class TeacherSurveyPresenter < DataItemPresenter end def title - "Teacher survey" + 'Teacher survey' end def id @@ -17,6 +17,6 @@ class TeacherSurveyPresenter < DataItemPresenter end def reason_for_insufficiency - "low response rate" + 'low response rate' end end diff --git a/app/presenters/variance_chart_row_presenter.rb b/app/presenters/variance_chart_row_presenter.rb index 516f4e10..4eaea895 100644 --- a/app/presenters/variance_chart_row_presenter.rb +++ b/app/presenters/variance_chart_row_presenter.rb @@ -59,7 +59,7 @@ class VarianceChartRowPresenter end def partial_data_sources - Array.new.tap do |sources| + [].tap do |sources| sources << 'teacher survey results' if @measure.includes_teacher_survey_items? && !@meets_teacher_threshold sources << 'student survey results' if @measure.includes_student_survey_items? && !@meets_student_threshold sources << 'administrative data' if @measure.includes_admin_data_items? diff --git a/app/services/survey_responses_data_loader.rb b/app/services/survey_responses_data_loader.rb index 8803b864..d913303c 100644 --- a/app/services/survey_responses_data_loader.rb +++ b/app/services/survey_responses_data_loader.rb @@ -1,14 +1,13 @@ require 'csv' class SurveyResponsesDataLoader - def self.load_data(filepath:) File.open(filepath) do |file| headers = file.first survey_item_ids = CSV.parse(headers, headers: true).headers - .filter { |header| header.present? } - .filter { |header| header.start_with? 't-' or header.start_with? 's-' } + .filter { |header| header.present? } + .filter { |header| header.start_with? 't-' or header.start_with? 's-' } survey_items = SurveyItem.where(survey_item_id: survey_item_ids) file.lazy.each_slice(1000) do |lines| @@ -58,11 +57,11 @@ end module StringMonkeyPatches def integer? - self.to_i.to_s == self + to_i.to_s == self end def valid_likert_score? - self.integer? and self.to_i.between? 1, 5 + integer? and to_i.between? 1, 5 end end diff --git a/app/views/legacy/questions/show.json.jbuilder b/app/views/legacy/questions/show.json.jbuilder index 1ae40088..1f31025a 100644 --- a/app/views/legacy/questions/show.json.jbuilder +++ b/app/views/legacy/questions/show.json.jbuilder @@ -1 +1,2 @@ -json.extract! @question, :id, :text, :option1, :option2, :option3, :option4, :option5, :category_id, :created_at, :updated_at +json.extract! @question, :id, :text, :option1, :option2, :option3, :option4, :option5, :category_id, :created_at, + :updated_at diff --git a/app/views/legacy/recipients/index.json.jbuilder b/app/views/legacy/recipients/index.json.jbuilder index 7f924b2c..7ccff6d0 100644 --- a/app/views/legacy/recipients/index.json.jbuilder +++ b/app/views/legacy/recipients/index.json.jbuilder @@ -1,4 +1,5 @@ json.array!(@recipients) do |recipient| - json.extract! recipient, :id, :name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id + json.extract! recipient, :id, :name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, + :opted_out, :school_id json.url recipient_url(recipient, format: :json) end diff --git a/app/views/legacy/recipients/show.json.jbuilder b/app/views/legacy/recipients/show.json.jbuilder index 473c6508..c8834349 100644 --- a/app/views/legacy/recipients/show.json.jbuilder +++ b/app/views/legacy/recipients/show.json.jbuilder @@ -1 +1,2 @@ -json.extract! @recipient, :id, :name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id, :created_at, :updated_at +json.extract! @recipient, :id, :name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, + :opted_out, :school_id, :created_at, :updated_at diff --git a/app/views/legacy/school/schedules/index.json.jbuilder b/app/views/legacy/school/schedules/index.json.jbuilder index ea91e50d..8bd5ada4 100644 --- a/app/views/legacy/school/schedules/index.json.jbuilder +++ b/app/views/legacy/school/schedules/index.json.jbuilder @@ -1,4 +1,5 @@ json.array!(@school_schedules) do |school_schedule| - json.extract! school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id + json.extract! school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, + :active, :random, :recipient_list_id, :question_list_id json.url school_schedule_url(school_schedule, format: :json) end diff --git a/app/views/legacy/school/schedules/show.json.jbuilder b/app/views/legacy/school/schedules/show.json.jbuilder index 66be49e4..3ac1be13 100644 --- a/app/views/legacy/school/schedules/show.json.jbuilder +++ b/app/views/legacy/school/schedules/show.json.jbuilder @@ -1 +1,2 @@ -json.extract! @school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id, :created_at, :updated_at +json.extract! @school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, + :active, :random, :recipient_list_id, :question_list_id, :created_at, :updated_at diff --git a/bin/bundle b/bin/bundle index 374a0a1f..3e2d3dbe 100755 --- a/bin/bundle +++ b/bin/bundle @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do module_function @@ -18,36 +18,36 @@ m = Module.new do end def env_var_version - ENV["BUNDLER_VERSION"] + ENV['BUNDLER_VERSION'] end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN - bundler_version = a - end + bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 + + bundler_version = Regexp.last_match(1) update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV['BUNDLE_GEMFILE'] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../../Gemfile", __FILE__) + File.expand_path('../Gemfile', __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -55,15 +55,17 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end def bundler_requirement @bundler_requirement ||= env_var_version || cli_arg_version || - bundler_requirement_for(lockfile_version) + bundler_requirement_for(lockfile_version) end def bundler_requirement_for(version) @@ -73,28 +75,32 @@ m = Module.new do requirement = bundler_gem_version.approximate_recommendation - return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0') - requirement += ".a" if bundler_gem_version.prerelease? + requirement += '.a' if bundler_gem_version.prerelease? requirement end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile activate_bundler end def activate_bundler gem_error = activation_error_handling do - gem "bundler", bundler_requirement + gem 'bundler', bundler_requirement end return if gem_error.nil? + require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' + end + if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + return end - return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" exit 42 end @@ -109,6 +115,4 @@ end m.load_bundler! -if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") -end +load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script? diff --git a/bin/rails b/bin/rails index 21d3e02d..3846d279 100755 --- a/bin/rails +++ b/bin/rails @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) +load File.expand_path('spring', __dir__) APP_PATH = File.expand_path('../config/application', __dir__) -require_relative "../config/boot" -require "rails/commands" +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake index 7327f471..31bcf935 100755 --- a/bin/rake +++ b/bin/rake @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) -require_relative "../config/boot" -require "rake" +load File.expand_path('spring', __dir__) +require_relative '../config/boot' +require 'rake' Rake.application.run diff --git a/bin/rspec b/bin/rspec index a6c78521..58d85dd9 100755 --- a/bin/rspec +++ b/bin/rspec @@ -8,11 +8,11 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ @@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("rspec-core", "rspec") +load Gem.bin_path('rspec-core', 'rspec') diff --git a/bin/setup b/bin/setup index 57923026..a8e630c6 100755 --- a/bin/setup +++ b/bin/setup @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require "fileutils" +require 'fileutils' # path to your application root. APP_ROOT = File.expand_path('..', __dir__) diff --git a/bin/spring b/bin/spring index b4147e84..9ab95392 100755 --- a/bin/spring +++ b/bin/spring @@ -1,13 +1,13 @@ #!/usr/bin/env ruby -if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) - gem "bundler" - require "bundler" +if !defined?(Spring) && [nil, 'development', 'test'].include?(ENV['RAILS_ENV']) + gem 'bundler' + require 'bundler' # Load Spring without loading other gems in the Gemfile, for speed. - Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring| + Bundler.locked_gems&.specs&.find { |spec| spec.name == 'spring' }&.tap do |spring| Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path - gem "spring", spring.version - require "spring/binstub" + gem 'spring', spring.version + require 'spring/binstub' rescue Gem::LoadError # Ignore when Spring is not installed. end diff --git a/bin/update b/bin/update index a8e4462f..32326c74 100755 --- a/bin/update +++ b/bin/update @@ -4,7 +4,7 @@ require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") diff --git a/bin/yarn b/bin/yarn index 9fab2c35..43d5aa6d 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,17 +1,17 @@ #!/usr/bin/env ruby APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do - yarn = ENV["PATH"].split(File::PATH_SEPARATOR). - select { |dir| File.expand_path(dir) != __dir__ }. - product(["yarn", "yarn.cmd", "yarn.ps1"]). - map { |dir, file| File.expand_path(file, dir) }. - find { |file| File.executable?(file) } + yarn = ENV['PATH'].split(File::PATH_SEPARATOR) + .select { |dir| File.expand_path(dir) != __dir__ } + .product(['yarn', 'yarn.cmd', 'yarn.ps1']) + .map { |dir, file| File.expand_path(file, dir) } + .find { |file| File.executable?(file) } if yarn exec yarn, *ARGV else - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' exit 1 end end diff --git a/config/environments/production.rb b/config/environments/production.rb index f0f59d90..1e1b5e1b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -51,7 +51,7 @@ Rails.application.configure do config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -80,7 +80,7 @@ Rails.application.configure do # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/config/initializers/array_monkey_patches.rb b/config/initializers/array_monkey_patches.rb index a160670b..465b716e 100644 --- a/config/initializers/array_monkey_patches.rb +++ b/config/initializers/array_monkey_patches.rb @@ -1,6 +1,6 @@ module ArrayMonkeyPatches def average - self.sum.to_f / self.size + sum.to_f / size end end diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb index f064f1e5..e960c524 100644 --- a/config/initializers/friendly_id.rb +++ b/config/initializers/friendly_id.rb @@ -16,8 +16,8 @@ FriendlyId.defaults do |config| # undesirable to allow as slugs. Edit this list as needed for your app. config.use :reserved - config.reserved_words = %w(new edit index session login logout users admin - stylesheets assets javascripts images) + config.reserved_words = %w[new edit index session login logout users admin + stylesheets assets javascripts images] # ## Friendly Finders # diff --git a/config/puma.rb b/config/puma.rb index 5ed44377..fd029342 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,20 +4,20 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index a680b19b..f7651fb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,7 +23,7 @@ Rails.application.routes.draw do end resources :districts do - resources :schools, only: [:index, :show] do + resources :schools, only: %i[index show] do resources :overview, only: [:index] resources :categories, only: [:show], path: 'browse' end @@ -31,10 +31,10 @@ Rails.application.routes.draw do devise_for :users, class_name: 'Legacy::User' as :user do - get 'users', :to => 'legacy/users#show', :as => :user_root # Rails 3 + get 'users', to: 'legacy/users#show', as: :user_root # Rails 3 end # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html get '/welcome', to: 'home#index' - root to: "legacy/welcome#index" + root to: 'legacy/welcome#index' end diff --git a/config/spring.rb b/config/spring.rb index db5bf130..8f6432bf 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ Spring.watch( - ".ruby-version", - ".rbenv-vars", - "tmp/restart.txt", - "tmp/caching-dev.txt" + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt' ) diff --git a/db/migrate/20170224181252_devise_create_users.rb b/db/migrate/20170224181252_devise_create_users.rb index f577233a..7e40272f 100644 --- a/db/migrate/20170224181252_devise_create_users.rb +++ b/db/migrate/20170224181252_devise_create_users.rb @@ -2,8 +2,8 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.0] def change create_table :users do |t| ## Database authenticatable - t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token @@ -30,7 +30,6 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.0] # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - t.timestamps null: false end diff --git a/db/migrate/20210917074250_add_slug_to_district.rb b/db/migrate/20210917074250_add_slug_to_district.rb index db0923a6..b3b4c62d 100644 --- a/db/migrate/20210917074250_add_slug_to_district.rb +++ b/db/migrate/20210917074250_add_slug_to_district.rb @@ -2,11 +2,10 @@ class AddSlugToDistrict < ActiveRecord::Migration[5.0] def up add_column :districts, :slug, :string add_index :districts, :slug, unique: true - District.all.each {|district| district.update(slug: district.slug ||= district.name.parameterize) } + District.all.each { |district| district.update(slug: district.slug ||= district.name.parameterize) } end def down remove_column :districts, :slug end - end diff --git a/db/migrate/20211029195454_remove_null_constraints_from_measure_benchmarks.rb b/db/migrate/20211029195454_remove_null_constraints_from_measure_benchmarks.rb index ddfcad18..81400401 100644 --- a/db/migrate/20211029195454_remove_null_constraints_from_measure_benchmarks.rb +++ b/db/migrate/20211029195454_remove_null_constraints_from_measure_benchmarks.rb @@ -8,7 +8,6 @@ class RemoveNullConstraintsFromMeasureBenchmarks < ActiveRecord::Migration[6.1] end end - def down change_table :measures do |t| t.change :watch_low_benchmark, :float, null: false diff --git a/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb b/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb index e33edde4..d1397810 100644 --- a/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb +++ b/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb @@ -1,6 +1,6 @@ class UpdateForeignKeyBetweenSurveyItemResponseAndSchool < ActiveRecord::Migration[6.1] def change - ActiveRecord::Base.connection.execute("DELETE FROM survey_item_responses") + ActiveRecord::Base.connection.execute('DELETE FROM survey_item_responses') remove_foreign_key :survey_item_responses, :legacy_schools, column: :school_id add_foreign_key :survey_item_responses, :schools diff --git a/db/migrate/20211119223051_make_school_dese_id_unique.rb b/db/migrate/20211119223051_make_school_dese_id_unique.rb index 633baa15..83ac4d64 100644 --- a/db/migrate/20211119223051_make_school_dese_id_unique.rb +++ b/db/migrate/20211119223051_make_school_dese_id_unique.rb @@ -1,6 +1,6 @@ class MakeSchoolDeseIdUnique < ActiveRecord::Migration[6.1] def change - ActiveRecord::Base.connection.execute("UPDATE schools SET dese_id = id") + ActiveRecord::Base.connection.execute('UPDATE schools SET dese_id = id') add_index :schools, :dese_id, unique: true end end diff --git a/db/migrate/20211217142634_add_benchmarks_to_survey_items.rb b/db/migrate/20211217142634_add_benchmarks_to_survey_items.rb new file mode 100644 index 00000000..3828d772 --- /dev/null +++ b/db/migrate/20211217142634_add_benchmarks_to_survey_items.rb @@ -0,0 +1,8 @@ +class AddBenchmarksToSurveyItems < ActiveRecord::Migration[6.1] + def change + add_column :survey_items, :watch_low_benchmark, :float + add_column :survey_items, :growth_low_benchmark, :float + add_column :survey_items, :approval_low_benchmark, :float + add_column :survey_items, :ideal_low_benchmark, :float + end +end diff --git a/db/migrate/20211217163827_add_benchmarks_to_admin_data_items.rb b/db/migrate/20211217163827_add_benchmarks_to_admin_data_items.rb new file mode 100644 index 00000000..262928e6 --- /dev/null +++ b/db/migrate/20211217163827_add_benchmarks_to_admin_data_items.rb @@ -0,0 +1,8 @@ +class AddBenchmarksToAdminDataItems < ActiveRecord::Migration[6.1] + def change + add_column :admin_data_items, :watch_low_benchmark, :float + add_column :admin_data_items, :growth_low_benchmark, :float + add_column :admin_data_items, :approval_low_benchmark, :float + add_column :admin_data_items, :ideal_low_benchmark, :float + end +end diff --git a/db/migrate/20211217164449_remove_benchmarks_from_measures.rb b/db/migrate/20211217164449_remove_benchmarks_from_measures.rb new file mode 100644 index 00000000..b64becca --- /dev/null +++ b/db/migrate/20211217164449_remove_benchmarks_from_measures.rb @@ -0,0 +1,8 @@ +class RemoveBenchmarksFromMeasures < ActiveRecord::Migration[6.1] + def change + remove_column :measures, :watch_low_benchmark, :float + remove_column :measures, :growth_low_benchmark, :float + remove_column :measures, :approval_low_benchmark, :float + remove_column :measures, :ideal_low_benchmark, :float + end +end diff --git a/db/schema.rb b/db/schema.rb index 37d0d8ca..885e503a 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: 2021_12_10_142652) do +ActiveRecord::Schema.define(version: 2021_12_17_164449) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -27,6 +27,10 @@ ActiveRecord::Schema.define(version: 2021_12_10_142652) do t.string "description" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.float "watch_low_benchmark" + t.float "growth_low_benchmark" + t.float "approval_low_benchmark" + t.float "ideal_low_benchmark" end create_table "categories", id: :serial, force: :cascade do |t| @@ -260,10 +264,6 @@ ActiveRecord::Schema.define(version: 2021_12_10_142652) do create_table "measures", id: :serial, force: :cascade do |t| t.string "measure_id", null: false t.string "name" - t.float "watch_low_benchmark" - t.float "growth_low_benchmark" - t.float "approval_low_benchmark" - t.float "ideal_low_benchmark" t.integer "subcategory_id", null: false t.text "description" t.datetime "created_at", precision: 6, null: false @@ -313,6 +313,10 @@ ActiveRecord::Schema.define(version: 2021_12_10_142652) do t.string "prompt" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.float "watch_low_benchmark" + t.float "growth_low_benchmark" + t.float "approval_low_benchmark" + t.float "ideal_low_benchmark" t.index ["measure_id"], name: "index_survey_items_on_measure_id" t.index ["survey_item_id"], name: "index_survey_items_on_survey_item_id" end diff --git a/doc/architectural_decision_records/1.md b/doc/architectural_decision_records/1.md new file mode 100644 index 00000000..557b2b34 --- /dev/null +++ b/doc/architectural_decision_records/1.md @@ -0,0 +1,31 @@ +# Decision record 1 + +# Add zone boundaries to Items and change how benchmarks are calculated for Measures, and subcategories + +## Status + +Implemented + +## Context + +Story: https://www.pivotaltracker.com/n/projects/2529781/stories/179844090 +Add new zone boundaries for Survey and Admin Data items. Measure zone boundaries become a weighted average of Survey and Admin Data items. + +At the moment the measure table is has warning, watch, growth, approval, and ideal low benchmarks seeded from the source of truth. This change means the measure table will no longer be populated with that information. Instead, student and teacher survey items and admin data items will be seeded with benchmark information. Measure.rb will instead have methods for calculating the benchmarks. + + +## Decision + +What is the change that we're proposing and/or doing? +Do we move benchmarks to admin data items and survey items directly or do we only populate admin data items with benchmarks and leave benchmarks on measures the way they are? + +I've made the decision to move the benchmarks to the item level because it places the seed information on the correct model. Now that we know benchmarks belong to items, not measures, the data in the database and the corresponding models should reflect that fact. + + +## Consequences + +What becomes easier or more difficult to do because of this change? + +Also, instead of just getting the data we need from each measure directly, we must cycle through admin and survey items to calculate the benchmark. + +This will also slow down the test suite because we must now create survey items or admin data items so the tests pass correctly. diff --git a/doc/architectural_decision_records/adr_template.md b/doc/architectural_decision_records/adr_template.md new file mode 100644 index 00000000..c17fe027 --- /dev/null +++ b/doc/architectural_decision_records/adr_template.md @@ -0,0 +1,24 @@ +# Decision record template by Michael Nygard + +This is the template in [Documenting architecture decisions - Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions). +You can use [adr-tools](https://github.com/npryce/adr-tools) for managing the ADR files. + +In each ADR file, write these sections: + +# Title + +## Status + +What is the status, such as proposed, accepted, rejected, deprecated, superseded, etc.? + +## Context + +What is the issue that we're seeing that is motivating this decision or change? + +## Decision + +What is the change that we're proposing and/or doing? + +## Consequences + +What becomes easier or more difficult to do because of this change? diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 53ab9769..5570772c 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -1,6 +1,5 @@ # PSQL: /Applications/Postgres.app/Contents/Versions/9.6/bin/psql -h localhost - # aws s3 presign s3://irrationaldesign/beta-data-080719a.dump # sudo heroku pg:backups:restore 'https://irrationaldesign.s3.amazonaws.com/beta-data-080719a.dump?AWSAccessKeyId=AKIAIDGE3EMQEWUQZUJA&Signature=KrabUOeggEd5wrjLQ4bvgd9eZGU%3D&Expires=1565267251' DATABASE_URL -a mciea-beta @@ -36,7 +35,7 @@ require 'csv' namespace :data do @year = 2019 - desc "load survey responses" + desc 'load survey responses' task load_survey_responses: :environment do Dir.glob(Rails.root.join('data', 'survey_responses', '*.csv')).each do |filepath| puts "=====================> Loading data from csv at path: #{filepath}" @@ -45,30 +44,28 @@ namespace :data do puts "=====================> Completed loading #{SurveyItemResponse.count} survey responses" end - desc "Load in all data" + desc 'Load in all data' task load: :environment do # return if School.count > 0 - Rake::Task["data:load_categories"].invoke - Rake::Task["data:load_questions"].invoke - Rake::Task["db:seed"].invoke - Rake::Task["data:load_responses"].invoke - Rake::Task["data:load_nonlikert_values"].invoke + Rake::Task['data:load_categories'].invoke + Rake::Task['data:load_questions'].invoke + Rake::Task['db:seed'].invoke + Rake::Task['data:load_responses'].invoke + Rake::Task['data:load_nonlikert_values'].invoke end desc 'Check question / category data against existing data' task check_questions: :environment do csv_string = File.read(File.expand_path("../../../data/MeasureKey#{@year}.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv = CSV.parse(csv_string, headers: true) t = Time.new - csv.each_with_index do |question, index| + csv.each_with_index do |question, _index| existing_question = Question.created_in(@year).find_by_external_id(question['qid']) if existing_question.blank? - puts "NOT FOUND: #{question['qid']} -> #{question["Question Text"]}" + puts "NOT FOUND: #{question['qid']} -> #{question['Question Text']}" else - if Question.where(external_id: question['qid']).count > 1 - puts "MULTIPLE FOUND: #{question['qid']}" - end + puts "MULTIPLE FOUND: #{question['qid']}" if Question.where(external_id: question['qid']).count > 1 question_text = question['Question Text'].gsub(/[[:space:]]/, ' ').strip if existing_question.text != question_text @@ -92,10 +89,10 @@ namespace :data do desc 'Sync questions / category data against existing data' task sync_questions: :environment do csv_string = File.read(File.expand_path("../../../data/MeasureKey#{@year}.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv = CSV.parse(csv_string, headers: true) t = Time.new - csv.each_with_index do |question, index| + csv.each_with_index do |question, _index| existing_question = Question.created_in(@year).find_by_external_id(question['qid']) if existing_question.blank? categories = Category.where(name: question['Category Name'].titleize) @@ -114,7 +111,7 @@ namespace :data do option4: question['R4'], option5: question['R5'], target_group: question['qid'].starts_with?('s') ? 'for_students' : 'for_teachers', - reverse: question['Reverse'] == "1" + reverse: question['Reverse'] == '1' ) end else @@ -145,7 +142,7 @@ namespace :data do desc 'Load in category data' task load_categories: :environment do - measures = JSON.parse(File.read(File.expand_path('../../../data/measures.json', __FILE__))) + measures = JSON.parse(File.read(File.expand_path('../../data/measures.json', __dir__))) measures.each_with_index do |measure, index| category = Category.create_with( blurb: measure['blurb'], @@ -169,14 +166,14 @@ namespace :data do external_id: subinfo_key ).find_or_create_by(name: subsubinfo['title']) - if subsubinfo['nonlikert'].present? - subsubinfo['nonlikert'].each do |nonlikert_info| - puts("NONLIKERT FOUND: #{nonlikert_info['title']}") - nonlikert = subsubcategory.child_categories.create_with( - benchmark_description: nonlikert_info['benchmark_explanation'], - benchmark: nonlikert_info['benchmark'] - ).find_or_create_by(name: nonlikert_info['title']) - end + next unless subsubinfo['nonlikert'].present? + + subsubinfo['nonlikert'].each do |nonlikert_info| + puts("NONLIKERT FOUND: #{nonlikert_info['title']}") + nonlikert = subsubcategory.child_categories.create_with( + benchmark_description: nonlikert_info['benchmark_explanation'], + benchmark: nonlikert_info['benchmark'] + ).find_or_create_by(name: nonlikert_info['title']) end end end @@ -190,18 +187,18 @@ namespace :data do 'teacher' ] - questions = JSON.parse(File.read(File.expand_path('../../../data/questions.json', __FILE__))) + questions = JSON.parse(File.read(File.expand_path('../../data/questions.json', __dir__))) questions.each do |question| category = nil question['category'].split('-').each do |external_id| categories = category.present? ? category.child_categories : Category category = categories.where(external_id: external_id).first - if category.nil? - puts 'NOTHING' - puts external_id - puts categories.inspect - category = categories.create(name: question['Category Name'], external_id: external_id) - end + next unless category.nil? + + puts 'NOTHING' + puts external_id + puts categories.inspect + category = categories.create(name: question['Category Name'], external_id: external_id) end question_text = question['text'].gsub(/[[:space:]]/, ' ').strip if question_text.index('.* teacher').nil? @@ -213,7 +210,7 @@ namespace :data do option4: question['answers'][3], option5: question['answers'][4], for_recipient_students: question['child'].present?, - reverse: question['Reverse'] == "1" + reverse: question['Reverse'] == '1' ) else variations.each do |variation| @@ -225,7 +222,7 @@ namespace :data do option4: question['answers'][3], option5: question['answers'][4], for_recipient_students: question['child'].present?, - reverse: question['Reverse'] == "1" + reverse: question['Reverse'] == '1' ) end end @@ -240,21 +237,23 @@ namespace :data do ] csv_string = File.read(File.expand_path("../../../data/MeasureKey#{@year}.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv = CSV.parse(csv_string, headers: true) t = Time.new - csv.each_with_index do |question, index| + csv.each_with_index do |question, _index| category = nil question['Category19'].split('-').each do |external_id_raw| external_id = external_id_raw.gsub(/[[:space:]]/, ' ').strip categories = category.present? ? category.child_categories : Category category = categories.where(external_id: external_id).first - if category.nil? - puts 'NOTHING' - puts "#{question['Category']} -- #{external_id}" - puts categories.map { |c| "#{c.name} - |#{c.external_id}| == |#{external_id}|: - #{external_id == c.external_id}"}.join(" ---- ") - category = categories.create(name: question['Category Name'], external_id: external_id) - end + next unless category.nil? + + puts 'NOTHING' + puts "#{question['Category']} -- #{external_id}" + puts categories.map { |c| + "#{c.name} - |#{c.external_id}| == |#{external_id}|: - #{external_id == c.external_id}" + }.join(' ---- ') + category = categories.create(name: question['Category Name'], external_id: external_id) end question_text = question['Question Text'].gsub(/[[:space:]]/, ' ').strip if question_text.index('.* teacher').nil? @@ -265,9 +264,9 @@ namespace :data do option3: question['R3'], option4: question['R4'], option5: question['R5'], - for_recipient_students: question['Level'] == "Students", + for_recipient_students: question['Level'] == 'Students', external_id: question['qid'], - reverse: question['Reverse'] == "1" + reverse: question['Reverse'] == '1' ) else variations.each do |variation| @@ -278,9 +277,9 @@ namespace :data do option3: question['R3'], option4: question['R4'], option5: question['R5'], - for_recipient_students: question['Level'] == "Students", + for_recipient_students: question['Level'] == 'Students', external_id: question['qid'], - reverse: question['Reverse'] == "1" + reverse: question['Reverse'] == '1' ) end end @@ -310,17 +309,17 @@ namespace :data do missing_questions = {} bad_answers = {} - timeToRun = 120000 * 60 + timeToRun = 120_000 * 60 startIndex = 0 - stopIndex = 1000000 + stopIndex = 1_000_000 startTime = Time.new # ['teacher_responses'].each do |file| - ['student_responses', 'teacher_responses'].each do |file| + %w[student_responses teacher_responses].each do |file| recipients = file.split('_')[0] target_group = Question.target_groups["for_#{recipients}s"] csv_string = File.read(File.expand_path("../../../data/#{file}_#{@year}.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv = CSV.parse(csv_string, headers: true) puts("LOADING CSV: #{csv.length} ROWS") t = Time.new @@ -338,16 +337,16 @@ namespace :data do end district_name = row['Q111'].strip - if district_name.blank? || district_name == "NA" + if district_name.blank? || district_name == 'NA' puts "DISTRICT NOT FOUND: #{district_name}" next end # district_name = row['To begin, please select your district.'] if district_name.nil? district = District.find_or_create_by(name: district_name, state_id: 1) - school_name = row["SchoolName"].strip + school_name = row['SchoolName'].strip - if school_name.blank? || school_name == "NA" + if school_name.blank? || school_name == 'NA' puts "BLANK SCHOOL NAME: #{district.name} - #{index}" next end @@ -356,38 +355,36 @@ namespace :data do if school.nil? next if unknown_schools[school_name] + puts "DATAERROR: Unable to find school: #{school_name} - #{index}" unknown_schools[school_name] = true next end - respondent_id = "#{recipients}-#{index}-#{row["ResponseId"].strip}" + respondent_id = "#{recipients}-#{index}-#{row['ResponseId'].strip}" recipient_id = respondent_map["#{school.id}-#{@year}-#{respondent_id}"] - if recipient_id.present? - recipient = school.recipients.where(id: recipient_id).first - end + recipient = school.recipients.where(id: recipient_id).first if recipient_id.present? if recipient.nil? begin recipient = school.recipients.create( name: "Survey Respondent Id: #{respondent_id}" ) - rescue + rescue StandardError puts "DATAERROR: INDEX: #{index} ERROR AT #{index} - #{district.name} - #{school_name} #{school}: #{respondent_id}" end respondent_map["#{school.id}-#{respondent_id}"] = recipient.id end recipient_list = school.recipient_lists.find_by_name("#{recipients.titleize} List") - if recipient_list.nil? - recipient_list = school.recipient_lists.create(name: "#{recipients.titleize} List") - end + recipient_list = school.recipient_lists.create(name: "#{recipients.titleize} List") if recipient_list.nil? recipient_list.recipient_id_array << recipient.id recipient_list.save! row.each do |key, value| t1 = Time.new - next if value.nil? or key.nil? or value.to_s == "-99" + next if value.nil? or key.nil? or value.to_s == '-99' + key = key.gsub(/[[:space:]]/, ' ').gsub(/\./, '-').strip.gsub(/\s+/, ' ') key = key.gsub(/-4-5/, '').gsub(/-6-12/, '') value = value.gsub(/[[:space:]]/, ' ').strip.downcase @@ -400,23 +397,26 @@ namespace :data do if question.nil? next if missing_questions[key] + puts "DATAERROR: Unable to find question: #{key}" missing_questions[key] = true next - else - question.update_attributes(target_group: target_group) if question.unknown? + elsif question.unknown? + question.update_attributes(target_group: target_group) end - if (value.to_i.blank?) + if value.to_i.blank? answer_index = question.option_index(value) answer_dictionary.each do |k, v| break if answer_index.present? + answer_index = question.option_index(value.gsub(k.to_s, v.to_s)) answer_index = question.option_index(value.gsub(v.to_s, k.to_s)) if answer_index.nil? end if answer_index.nil? next if bad_answers[key] + puts "DATAERROR: Unable to find answer: #{key} = #{value.downcase.strip} - #{question.options.inspect}" bad_answers[key] = true next @@ -429,7 +429,11 @@ namespace :data do # answer_index = 6 - answer_index if question.reverse? - responded_at = Date.strptime(row['recordedDate'], '%Y-%m-%d %H:%M:%S') rescue Date.today + responded_at = begin + Date.strptime(row['recordedDate'], '%Y-%m-%d %H:%M:%S') + rescue StandardError + Date.today + end begin recipient.attempts.create(question: question, answer_index: answer_index, responded_at: responded_at) rescue Exception => e @@ -448,65 +452,64 @@ namespace :data do desc 'Load in nonlikert values for each school' task load_nonlikert_values: :environment do - csv_string = File.read(File.expand_path("../../../data/MCIEA_18-19AdminData_Final.csv", __FILE__)) + csv_string = File.read(File.expand_path('../../data/MCIEA_18-19AdminData_Final.csv', __dir__)) # csv_string = File.read(File.expand_path("../../../data/MCIEA_16-17_SGP.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv = CSV.parse(csv_string, headers: true) puts("LOADING NONLIKERT CSV: #{csv.length} ROWS") errors = [] - csv.each_with_index do |row, index| - next if row["Likert_Value"].blank? + csv.each_with_index do |row, _index| + next if row['Likert_Value'].blank? + base = Category - category_ids = row["Category"].split("-") + category_ids = row['Category'].split('-') category_ids.each do |category_id| category_id = category_id.downcase if category_id.downcase =~ /i/ base = base.find_by_external_id(category_id) if base.nil? - row["reason"] = "Unable to find category_id #{category_id} for category #{row["Category"]}" + row['reason'] = "Unable to find category_id #{category_id} for category #{row['Category']}" errors << row next end base = base.child_categories end - nonlikert_category = base.where(name: row["NonLikert Title"]).first + nonlikert_category = base.where(name: row['NonLikert Title']).first if nonlikert_category.nil? - row["reason"] = "Unable to find nonlikert category: #{row["NonLikert Title"]} in #{}" + row['reason'] = "Unable to find nonlikert category: #{row['NonLikert Title']} in " errors << row next - else - if (benchmark = row["Benchmark"]).present? - nonlikert_category.update(benchmark: benchmark) - end + elsif (benchmark = row['Benchmark']).present? + nonlikert_category.update(benchmark: benchmark) end - district = District.where(name: row["District"], state_id: 1).first + district = District.where(name: row['District'], state_id: 1).first if district.blank? - row["reason"] = "DISTRICT NOT FOUND: #{row["District"]}" + row['reason'] = "DISTRICT NOT FOUND: #{row['District']}" errors << row next end - school = district.schools.where(name: row["School"]).first + school = district.schools.where(name: row['School']).first if school.blank? - row["reason"] = "SCHOOL NOT FOUND: #{row["School"]} (#{district.name})" + row['reason'] = "SCHOOL NOT FOUND: #{row['School']} (#{district.name})" errors << row next end - school_category = school.school_categories.find_or_create_by(category: nonlikert_category, year: "#{@year}") + school_category = school.school_categories.find_or_create_by(category: nonlikert_category, year: @year.to_s) if school_category.blank? - row["reason"] = "SCHOOL CATEGORY NOT FOUND: #{school.name} (#{district.name}) #{nonlikert_category.name}" + row['reason'] = "SCHOOL CATEGORY NOT FOUND: #{school.name} (#{district.name}) #{nonlikert_category.name}" errors << row next end - zscore = (([-2,[row["Likert_Value"].to_f-3,2].min].max * 10).to_i).to_f / 10.0 + zscore = ([-2, [row['Likert_Value'].to_f - 3, 2].min].max * 10).to_i.to_f / 10.0 school_category.update( - nonlikert: row["NL_Value"], + nonlikert: row['NL_Value'], zscore: zscore.to_f, - year: "#{@year}", + year: @year.to_s, valid_child_count: 1 ) @@ -514,40 +517,41 @@ namespace :data do end errors.each do |error| - puts "#{error["reason"]}: #{error["NonLikert Title"]} -> #{error["Likert_Value"]}" + puts "#{error['reason']}: #{error['NonLikert Title']} -> #{error['Likert_Value']}" end - puts "COUNT: #{SchoolCategory.where(attempt_count: 0, answer_index_total: 0).where("nonlikert is not null and zscore is null").count}" + puts "COUNT: #{SchoolCategory.where(attempt_count: 0, + answer_index_total: 0).where('nonlikert is not null and zscore is null').count}" end desc 'Load in custom zones for each category' task load_custom_zones: :environment do ENV['BULK_PROCESS'] = 'true' - csv_string = File.read(File.expand_path("../../../data/Benchmarks2016-2017.csv", __FILE__)) - csv = CSV.parse(csv_string, :headers => true) + csv_string = File.read(File.expand_path('../../data/Benchmarks2016-2017.csv', __dir__)) + csv = CSV.parse(csv_string, headers: true) - csv.each_with_index do |row, index| - next if row["Warning High"].blank? + csv.each_with_index do |row, _index| + next if row['Warning High'].blank? - category = Category.find_by_name(row["Subcategory"]) + category = Category.find_by_name(row['Subcategory']) if category.nil? - puts "Unable to find category #{row["Subcategory"]}" + puts "Unable to find category #{row['Subcategory']}" next end custom_zones = [ - row["Warning High"], - row["Watch High"], - row["Growth High"], - row["Approval High"], + row['Warning High'], + row['Watch High'], + row['Growth High'], + row['Approval High'], 5 ] - puts "#{category.name} -> #{custom_zones.join(",")}" + puts "#{category.name} -> #{custom_zones.join(',')}" - category.update(zones: custom_zones.join(",")) + category.update(zones: custom_zones.join(',')) end ENV.delete('BULK_PROCESS') @@ -559,7 +563,8 @@ namespace :data do task move_likert_to_submeasures: :environment do Question.all.each do |q| category = q.category - next unless category.name.index("Scale").nil? + next unless category.name.index('Scale').nil? + new_category_name = "#{category.name} Scale" new_category = category.child_categories.where(name: new_category_name).first if new_category.nil? @@ -592,19 +597,19 @@ namespace :data do new_school_questions = [] category.questions.created_in(@year).each do |question| school = school_category.school - next if school.district.name != "Boston" + next if school.district.name != 'Boston' school_question = school_category.school_questions.for(school, question).first if school_question.present? school_questions << school_question else - attempt_data = Attempt. - joins(:question). - created_in(school_category.year). - for_question(question). - for_school(school). - select('count(attempts.answer_index) as response_count'). - select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] + attempt_data = Attempt + .joins(:question) + .created_in(school_category.year) + .for_question(question) + .for_school(school) + .select('count(attempts.answer_index) as response_count') + .select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] available_responders = school.available_responders_for(question) @@ -625,7 +630,6 @@ namespace :data do SchoolQuestion.import new_school_questions end - end end end @@ -634,17 +638,14 @@ namespace :data do School.all.each do |school| Category.all.each do |category| school_category = SchoolCategory.for(school, category).in(@year).first - if school_category.nil? - school_category = school.school_categories.create(category: category, year: @year) - end + school_category = school.school_categories.create(category: category, year: @year) if school_category.nil? school_category.sync_aggregated_responses end end end end -# - +# # require 'csv' # student_counts_string = File.read(File.expand_path("data/bps_student_counts.csv")) @@ -691,8 +692,6 @@ end # # - - # min_response_rate = 0.3 # level = 1 # # categories = Category.joins(:questions).uniq.all @@ -796,7 +795,6 @@ end # # puts "TOTAL: #{total}" - # [ # "next-wave-full-circle" # ].each do |slug| diff --git a/lib/tasks/dupes.rake b/lib/tasks/dupes.rake index baf98993..2dea4add 100644 --- a/lib/tasks/dupes.rake +++ b/lib/tasks/dupes.rake @@ -7,7 +7,7 @@ namespace :dupes do # | Dist1 | Jefferson High | lincoln-high | created_at | updated_at | task record_csv: :environment do csv_string = CSV.generate do |csv| - csv << [ 'District Name', 'School Name', 'School Slug', 'Creation Time', 'Updated Time' ] + csv << ['District Name', 'School Name', 'School Slug', 'Creation Time', 'Updated Time'] School.all.order(:district_id, :name, :created_at).each do |school| schools = School.where name: school.name, district: school.district @@ -23,21 +23,21 @@ namespace :dupes do task dedup_schools: :environment do School.all.each do |school| schools = School.where(name: school.name, district: school.district).order(:created_at) - if schools.length > 1 - school_to_keep = schools.first - schools.each do |school_to_destroy| - next if school_to_destroy == school_to_keep + next unless schools.length > 1 - school_to_keep.update(qualtrics_code: school_to_destroy.qualtrics_code) + school_to_keep = schools.first + schools.each do |school_to_destroy| + next if school_to_destroy == school_to_keep - SurveyItemResponse.where(school: school_to_destroy).each do |response| - success = response.update(school: school_to_keep) - puts "Attempted to update survey item response with id #{response.id} to point to school with id #{school_to_keep.id}. Successful? #{success}" - puts response.reload.school_id - end + school_to_keep.update(qualtrics_code: school_to_destroy.qualtrics_code) - school_to_destroy.destroy + SurveyItemResponse.where(school: school_to_destroy).each do |response| + success = response.update(school: school_to_keep) + puts "Attempted to update survey item response with id #{response.id} to point to school with id #{school_to_keep.id}. Successful? #{success}" + puts response.reload.school_id end + + school_to_destroy.destroy end end end diff --git a/lib/tasks/survey.rake b/lib/tasks/survey.rake index f8bbf372..c2dfaa7e 100644 --- a/lib/tasks/survey.rake +++ b/lib/tasks/survey.rake @@ -1,12 +1,10 @@ namespace :survey do - desc 'Text all recipients ready for an attempt' - task :attempt_questions => :environment do + task attempt_questions: :environment do Legacy::Schedule.active.each do |schedule| schedule.recipient_schedules.ready.each do |recipient_schedule| recipient_schedule.attempt_question end end end - end diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index bdfaaa3f..8d01c559 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -4,14 +4,14 @@ describe CategoriesController, type: :controller do include BasicAuthHelper let(:school) { create(:school) } let(:district) { create(:district) } - let!(:categories) { + let!(:categories) do [create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)] - } + end it 'fetches categories sorted by sort_index' do login_as district category = categories.first - get :show, params: { id: category.to_param, school_id: school.to_param, district_id: district.to_param } - expect(assigns(:categories).map(&:name)).to eql ['First', 'Second'] + get :show, params: { id: category.to_param, school_id: school.to_param, district_id: district.to_param } + expect(assigns(:categories).map(&:name)).to eql %w[First Second] end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 6912521a..f1027225 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe HomeController, type: :controller do - let!(:categories) { + let!(:categories) do [create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)] - } + end it 'fetches categories sorted by sort_index' do get :index - expect(assigns(:categories).map(&:name)).to eql ['First', 'Second'] + expect(assigns(:categories).map(&:name)).to eql %w[First Second] end end diff --git a/spec/controllers/legacy/attempts_controller_spec.rb b/spec/controllers/legacy/attempts_controller_spec.rb index 499d6d24..fa6597f8 100644 --- a/spec/controllers/legacy/attempts_controller_spec.rb +++ b/spec/controllers/legacy/attempts_controller_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' module Legacy RSpec.describe AttemptsController, type: :controller do - let(:valid_session) { {} } let!(:recipients) { create_recipients(school, 2) } @@ -16,13 +15,19 @@ module Legacy QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) end - let(:schedule) { Schedule.create(name: 'Test Schedule', question_list: question_list, recipient_list: recipient_list) } + let(:schedule) do + Schedule.create(name: 'Test Schedule', question_list: question_list, recipient_list: recipient_list) + end let(:school) { Legacy::School.create!(name: 'School') } - let(:recipient_schedule) { RecipientSchedule.create(recipient: recipients.first, schedule: schedule, next_attempt_at: Time.now) } - let(:recipient_schedule2) { RecipientSchedule.create(recipient: recipients.last, schedule: schedule, next_attempt_at: Time.now) } + let(:recipient_schedule) do + RecipientSchedule.create(recipient: recipients.first, schedule: schedule, next_attempt_at: Time.now) + end + let(:recipient_schedule2) do + RecipientSchedule.create(recipient: recipients.last, schedule: schedule, next_attempt_at: Time.now) + end - let!(:first_attempt) { + let!(:first_attempt) do Attempt.create( schedule: schedule, recipient: recipients.first, @@ -30,8 +35,8 @@ module Legacy question: questions.first, sent_at: Time.new ) - } - let!(:attempt) { + end + let!(:attempt) do Attempt.create( schedule: schedule, recipient: recipients.first, @@ -39,8 +44,8 @@ module Legacy question: questions.first, sent_at: Time.new ) - } - let!(:attempt2) { + end + let!(:attempt2) do Attempt.create( schedule: schedule, recipient: recipients.last, @@ -48,13 +53,14 @@ module Legacy question: questions.first, sent_at: Time.new ) - } + end - describe "POST #twilio" do - context "with valid params" do - let(:twilio_attributes) { - { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '3', 'NumMedia' => '0' } - } + describe 'POST #twilio' do + context 'with valid params' do + let(:twilio_attributes) do + { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', + 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '3', 'NumMedia' => '0' } + end before :each do post :twilio, params: twilio_attributes @@ -64,7 +70,7 @@ module Legacy expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(1) end - it "updates the last attempt by recipient phone number" do + it 'updates the last attempt by recipient phone number' do attempt.reload expect(attempt.answer_index).to eq(3) expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml) @@ -75,14 +81,15 @@ module Legacy expect(first_attempt.responded_at).to be_nil end - it "sends back a message" do + it 'sends back a message' do expect(response.body).to eq "We've registered your response of \"Option 0:3 C\". You are the first person to respond to this question. Once more people have responded you will be able to see all responses at: http://test.host/schools/school/categories/test-category" end - context "with second response" do - let(:twilio_attributes2) { - { 'MessageSid' => 'fwefwefewfewfasfsdfdf', 'AccountSid' => 'wefwegdbvcbrtnrn', 'MessagingServiceSid' => 'dfvdfvegbdfb', 'From' => '+1111111111', 'To' => '2223334444', 'Body' => '4', 'NumMedia' => '0' } - } + context 'with second response' do + let(:twilio_attributes2) do + { 'MessageSid' => 'fwefwefewfewfasfsdfdf', 'AccountSid' => 'wefwegdbvcbrtnrn', + 'MessagingServiceSid' => 'dfvdfvegbdfb', 'From' => '+1111111111', 'To' => '2223334444', 'Body' => '4', 'NumMedia' => '0' } + end before :each do post :twilio, params: twilio_attributes2 @@ -92,26 +99,27 @@ module Legacy expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(2) end - it "updates the attempt from the second recipient" do + it 'updates the attempt from the second recipient' do attempt2.reload expect(attempt2.answer_index).to eq(4) expect(attempt2.twilio_details).to eq(twilio_attributes2.with_indifferent_access.to_yaml) expect(attempt2.responded_at).to be_present end - it "sends back a message" do + it 'sends back a message' do expect(response.body).to eq "We've registered your response of \"Option 0:3 D\". 2 people have responded to this question so far. To see all responses visit: http://test.host/schools/school/categories/test-category" end end end - ['stOp', 'cANcel', 'QuIt', 'no'].each do |command| + %w[stOp cANcel QuIt no].each do |command| context "with #{command} command" do - let(:twilio_attributes) { - { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } - } + let(:twilio_attributes) do + { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', + 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } + end - it "updates the last attempt by recipient phone number" do + it 'updates the last attempt by recipient phone number' do post :twilio, params: twilio_attributes attempt.reload expect(attempt.answer_index).to be_nil @@ -119,24 +127,25 @@ module Legacy expect(attempt.recipient).to be_opted_out end - it "sends back a message" do + it 'sends back a message' do post :twilio, params: twilio_attributes expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.') end end end - ['staRt', 'reSUme', 'rEstaRt', 'Yes', 'go'].each do |command| + %w[staRt reSUme rEstaRt Yes go].each do |command| context "with #{command} command" do before :each do attempt.recipient.update(opted_out: true) end - let(:twilio_attributes) { - { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } - } + let(:twilio_attributes) do + { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', + 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } + end - it "updates the last attempt by recipient phone number" do + it 'updates the last attempt by recipient phone number' do expect(attempt.recipient).to be_opted_out post :twilio, params: twilio_attributes attempt.reload @@ -145,7 +154,7 @@ module Legacy expect(attempt.recipient).to_not be_opted_out end - it "sends back a message" do + it 'sends back a message' do post :twilio, params: twilio_attributes expect(response.body).to eq('Thank you, you will now begin receiving messages again.') end @@ -154,11 +163,12 @@ module Legacy ['skip', 'i dont know', "i don't know", 'next'].each do |command| context "with #{command} command" do - let(:twilio_skip_attributes) { - { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } - } + let(:twilio_skip_attributes) do + { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', + 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' } + end - it "updates the last attempt by recipient phone number" do + it 'updates the last attempt by recipient phone number' do post :twilio, params: twilio_skip_attributes attempt.reload expect(attempt.answer_index).to be_nil @@ -172,7 +182,7 @@ module Legacy expect(school_attempts.not_yet_responded.count).to eq(2) end - it "sends back a message" do + it 'sends back a message' do post :twilio, params: twilio_skip_attributes expect(response.body).to eq('Thank you, this question has been skipped.') end @@ -180,23 +190,23 @@ module Legacy end end - describe "POST #twilio with response to repeated question" do - context "with valid params" do - - let!(:recent_first_attempt) { + describe 'POST #twilio with response to repeated question' do + context 'with valid params' do + let!(:recent_first_attempt) do first_attempt.update(sent_at: Time.new) return first_attempt - } + end - let(:twilio_attributes) { - { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '2', 'NumMedia' => '0' } - } + let(:twilio_attributes) do + { 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', + 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '2', 'NumMedia' => '0' } + end before :each do post :twilio, params: twilio_attributes end - it "updates the first attempt (that now has the most recent sent_at)" do + it 'updates the first attempt (that now has the most recent sent_at)' do recent_first_attempt.reload expect(recent_first_attempt.answer_index).to eq(2) expect(recent_first_attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml) diff --git a/spec/controllers/legacy/categories_controller_spec.rb b/spec/controllers/legacy/categories_controller_spec.rb index ec595884..ec72cea8 100644 --- a/spec/controllers/legacy/categories_controller_spec.rb +++ b/spec/controllers/legacy/categories_controller_spec.rb @@ -20,37 +20,36 @@ require 'rails_helper' module Legacy RSpec.describe Legacy::CategoriesController, type: :controller do - # This should return the minimal set of attributes required to create a valid # Category. As you add validations to Category, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { name: 'Category', external_id: 'A' } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { name: '' } - } + end - let(:district) { + let(:district) do Legacy::District.create! name: 'District' - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # CategoriesController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all categories as @categories" do + describe 'GET #index' do + it 'assigns all categories as @categories' do category = Legacy::Category.create! valid_attributes get :index, params: {}, session: valid_session expect(assigns(:categories)).to eq([category]) end end - describe "GET #show" do - it "assigns the requested school and category as @school and @category" do + describe 'GET #show' do + it 'assigns the requested school and category as @school and @category' do school = Legacy::School.create! name: 'School', district: district category = Legacy::Category.create! valid_attributes get :show, params: { school_id: school.id, id: category.to_param }, session: valid_session @@ -58,89 +57,89 @@ module Legacy expect(assigns(:school)).to eq(school) end - it "redirects to root_path if school is not provided" do + it 'redirects to root_path if school is not provided' do category = Legacy::Category.create! valid_attributes get :show, params: { id: category.to_param }, session: valid_session expect(response).to redirect_to(root_path) end end - describe "GET #new" do - it "assigns a new category as @category" do + describe 'GET #new' do + it 'assigns a new category as @category' do get :new, params: {}, session: valid_session expect(assigns(:category)).to be_a_new(Legacy::Category) end end - describe "GET #edit" do - it "assigns the requested category as @category" do + describe 'GET #edit' do + it 'assigns the requested category as @category' do category = Legacy::Category.create! valid_attributes get :edit, params: { id: category.to_param }, session: valid_session expect(assigns(:category)).to eq(category) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Category" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Category' do + expect do post :create, params: { category: valid_attributes }, session: valid_session - }.to change(Legacy::Category, :count).by(1) + end.to change(Legacy::Category, :count).by(1) end - it "assigns a newly created category as @category" do + it 'assigns a newly created category as @category' do post :create, params: { category: valid_attributes }, session: valid_session expect(assigns(:category)).to be_a(Legacy::Category) expect(assigns(:category)).to be_persisted end - it "redirects to the created category" do + it 'redirects to the created category' do post :create, params: { category: valid_attributes }, session: valid_session expect(response).to redirect_to(Legacy::Category.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved category as @category" do + context 'with invalid params' do + it 'assigns a newly created but unsaved category as @category' do post :create, params: { category: invalid_attributes }, session: valid_session expect(assigns(:category)).to be_a_new(Legacy::Category) end it "re-renders the 'new' template" do post :create, params: { category: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { name: 'Category 2' } - } + end - it "updates the requested category" do + it 'updates the requested category' do category = Legacy::Category.create! valid_attributes put :update, params: { id: category.to_param, category: new_attributes }, session: valid_session category.reload expect(category.name).to eq('Category 2') end - it "assigns the requested category as @category" do + it 'assigns the requested category as @category' do category = Legacy::Category.create! valid_attributes put :update, params: { id: category.to_param, category: valid_attributes }, session: valid_session expect(assigns(:category)).to eq(category) end - it "redirects to the category" do + it 'redirects to the category' do category = Legacy::Category.create! valid_attributes put :update, params: { id: category.to_param, category: valid_attributes }, session: valid_session expect(response).to redirect_to(category) end end - context "with invalid params" do - it "assigns the category as @category" do + context 'with invalid params' do + it 'assigns the category as @category' do category = Legacy::Category.create! valid_attributes put :update, params: { id: category.to_param, category: invalid_attributes }, session: valid_session expect(assigns(:category)).to eq(category) @@ -149,25 +148,24 @@ module Legacy it "re-renders the 'edit' template" do category = Legacy::Category.create! valid_attributes put :update, params: { id: category.to_param, category: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested category" do + describe 'DELETE #destroy' do + it 'destroys the requested category' do category = Legacy::Category.create! valid_attributes - expect { + expect do delete :destroy, params: { id: category.to_param }, session: valid_session - }.to change(Legacy::Category, :count).by(-1) + end.to change(Legacy::Category, :count).by(-1) end - it "redirects to the categories list" do + it 'redirects to the categories list' do category = Legacy::Category.create! valid_attributes delete :destroy, params: { id: category.to_param }, session: valid_session expect(response).to redirect_to(legacy_categories_url) end end - end end diff --git a/spec/controllers/legacy/districts_controller_spec.rb b/spec/controllers/legacy/districts_controller_spec.rb index b9f8fe1a..0d0e22af 100644 --- a/spec/controllers/legacy/districts_controller_spec.rb +++ b/spec/controllers/legacy/districts_controller_spec.rb @@ -2,114 +2,113 @@ require 'rails_helper' module Legacy RSpec.describe DistrictsController, type: :controller do - # This should return the minimal set of attributes required to create a valid # District. As you add validations to District, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { name: 'Milford' } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { name: '' } - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # DistrictsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all districts as @districts" do + describe 'GET #index' do + it 'assigns all districts as @districts' do get :index, params: {}, session: valid_session expect(assigns(:districts)).to eq(District.all.alphabetic) end end - describe "GET #show" do - it "assigns the requested district as @district" do + describe 'GET #show' do + it 'assigns the requested district as @district' do district = District.create! valid_attributes get :show, params: { id: district.to_param }, session: valid_session expect(assigns(:district)).to eq(district) end end - describe "GET #new" do - it "assigns a new district as @district" do + describe 'GET #new' do + it 'assigns a new district as @district' do get :new, params: {}, session: valid_session expect(assigns(:district)).to be_a_new(District) end end - describe "GET #edit" do - it "assigns the requested district as @district" do + describe 'GET #edit' do + it 'assigns the requested district as @district' do district = District.create! valid_attributes get :edit, params: { id: district.to_param }, session: valid_session expect(assigns(:district)).to eq(district) end end - describe "POST #create" do - context "with valid params" do - it "creates a new District" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new District' do + expect do post :create, params: { district: valid_attributes }, session: valid_session - }.to change(District, :count).by(1) + end.to change(District, :count).by(1) end - it "assigns a newly created district as @district" do + it 'assigns a newly created district as @district' do post :create, params: { district: valid_attributes }, session: valid_session expect(assigns(:district)).to be_a(District) expect(assigns(:district)).to be_persisted end - it "redirects to the created district" do + it 'redirects to the created district' do post :create, params: { district: valid_attributes }, session: valid_session expect(response).to redirect_to(District.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved district as @district" do + context 'with invalid params' do + it 'assigns a newly created but unsaved district as @district' do post :create, params: { district: invalid_attributes }, session: valid_session expect(assigns(:district)).to be_a_new(District) end it "re-renders the 'new' template" do post :create, params: { district: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { name: 'New District' } - } + end - it "updates the requested district" do + it 'updates the requested district' do district = District.create! valid_attributes put :update, params: { id: district.to_param, district: new_attributes }, session: valid_session district.reload expect(district.name).to eq('New District') end - it "assigns the requested district as @district" do + it 'assigns the requested district as @district' do district = District.create! valid_attributes put :update, params: { id: district.to_param, district: valid_attributes }, session: valid_session expect(assigns(:district)).to eq(district) end - it "redirects to the district" do + it 'redirects to the district' do district = District.create! valid_attributes put :update, params: { id: district.to_param, district: valid_attributes }, session: valid_session expect(response).to redirect_to(district) end end - context "with invalid params" do - it "assigns the district as @district" do + context 'with invalid params' do + it 'assigns the district as @district' do district = District.create! valid_attributes put :update, params: { id: district.to_param, district: invalid_attributes }, session: valid_session expect(assigns(:district)).to eq(district) @@ -118,25 +117,24 @@ module Legacy it "re-renders the 'edit' template" do district = District.create! valid_attributes put :update, params: { id: district.to_param, district: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested district" do + describe 'DELETE #destroy' do + it 'destroys the requested district' do district = District.create! valid_attributes - expect { + expect do delete :destroy, params: { id: district.to_param }, session: valid_session - }.to change(District, :count).by(-1) + end.to change(District, :count).by(-1) end - it "redirects to the districts list" do + it 'redirects to the districts list' do district = District.create! valid_attributes delete :destroy, params: { id: district.to_param }, session: valid_session expect(response).to redirect_to(districts_url) end end - end end diff --git a/spec/controllers/legacy/question_lists_controller_spec.rb b/spec/controllers/legacy/question_lists_controller_spec.rb index d8a8cc45..4210973f 100644 --- a/spec/controllers/legacy/question_lists_controller_spec.rb +++ b/spec/controllers/legacy/question_lists_controller_spec.rb @@ -20,115 +20,114 @@ require 'rails_helper' module Legacy RSpec.describe QuestionListsController, type: :controller do - # This should return the minimal set of attributes required to create a valid # QuestionList. As you add validations to QuestionList, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { name: 'Questions for Parents', question_id_array: ['', '1', '2', '3'] } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { question_id_array: [''] } - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # QuestionListsController. Be sure to keep this updated too. let(:valid_session) { {} } - describe "GET #index" do - it "assigns all question_lists as @question_lists" do + describe 'GET #index' do + it 'assigns all question_lists as @question_lists' do question_list = QuestionList.create! valid_attributes get :index, params: {}, session: valid_session expect(assigns(:question_lists)).to eq([question_list]) end end - describe "GET #show" do - it "assigns the requested question_list as @question_list" do + describe 'GET #show' do + it 'assigns the requested question_list as @question_list' do question_list = QuestionList.create! valid_attributes get :show, params: { id: question_list.to_param }, session: valid_session expect(assigns(:question_list)).to eq(question_list) end end - describe "GET #new" do - it "assigns a new question_list as @question_list" do + describe 'GET #new' do + it 'assigns a new question_list as @question_list' do get :new, params: {}, session: valid_session expect(assigns(:question_list)).to be_a_new(QuestionList) end end - describe "GET #edit" do - it "assigns the requested question_list as @question_list" do + describe 'GET #edit' do + it 'assigns the requested question_list as @question_list' do question_list = QuestionList.create! valid_attributes get :edit, params: { id: question_list.to_param }, session: valid_session expect(assigns(:question_list)).to eq(question_list) end end - describe "POST #create" do - context "with valid params" do - it "creates a new QuestionList" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new QuestionList' do + expect do post :create, params: { question_list: valid_attributes }, session: valid_session - }.to change(QuestionList, :count).by(1) + end.to change(QuestionList, :count).by(1) end - it "assigns a newly created question_list as @question_list" do + it 'assigns a newly created question_list as @question_list' do post :create, params: { question_list: valid_attributes }, session: valid_session expect(assigns(:question_list)).to be_a(QuestionList) expect(assigns(:question_list)).to be_persisted end - it "redirects to the created question_list" do + it 'redirects to the created question_list' do post :create, params: { question_list: valid_attributes }, session: valid_session expect(response).to redirect_to(QuestionList.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved question_list as @question_list" do + context 'with invalid params' do + it 'assigns a newly created but unsaved question_list as @question_list' do post :create, params: { question_list: invalid_attributes }, session: valid_session expect(assigns(:question_list)).to be_a_new(QuestionList) end it "re-renders the 'new' template" do post :create, params: { question_list: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { question_id_array: ['', '2', '3'] } - } + end - it "updates the requested question_list" do + it 'updates the requested question_list' do question_list = QuestionList.create! valid_attributes put :update, params: { id: question_list.to_param, question_list: new_attributes }, session: valid_session question_list.reload expect(question_list.question_ids).to eq('2,3') end - it "assigns the requested question_list as @question_list" do + it 'assigns the requested question_list as @question_list' do question_list = QuestionList.create! valid_attributes put :update, params: { id: question_list.to_param, question_list: valid_attributes }, session: valid_session expect(assigns(:question_list)).to eq(question_list) end - it "redirects to the question_list" do + it 'redirects to the question_list' do question_list = QuestionList.create! valid_attributes put :update, params: { id: question_list.to_param, question_list: valid_attributes }, session: valid_session expect(response).to redirect_to(question_list) end end - context "with invalid params" do - it "assigns the question_list as @question_list" do + context 'with invalid params' do + it 'assigns the question_list as @question_list' do question_list = QuestionList.create! valid_attributes put :update, params: { id: question_list.to_param, question_list: invalid_attributes }, session: valid_session expect(assigns(:question_list)).to eq(question_list) @@ -137,25 +136,24 @@ module Legacy it "re-renders the 'edit' template" do question_list = QuestionList.create! valid_attributes put :update, params: { id: question_list.to_param, question_list: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested question_list" do + describe 'DELETE #destroy' do + it 'destroys the requested question_list' do question_list = QuestionList.create! valid_attributes - expect { + expect do delete :destroy, params: { id: question_list.to_param }, session: valid_session - }.to change(QuestionList, :count).by(-1) + end.to change(QuestionList, :count).by(-1) end - it "redirects to the question_lists list" do + it 'redirects to the question_lists list' do question_list = QuestionList.create! valid_attributes delete :destroy, params: { id: question_list.to_param }, session: valid_session expect(response).to redirect_to(legacy_question_lists_url) end end - end end diff --git a/spec/controllers/legacy/questions_controller_spec.rb b/spec/controllers/legacy/questions_controller_spec.rb index 19910d67..ef0d5140 100644 --- a/spec/controllers/legacy/questions_controller_spec.rb +++ b/spec/controllers/legacy/questions_controller_spec.rb @@ -20,13 +20,12 @@ require 'rails_helper' module Legacy RSpec.describe QuestionsController, type: :controller do - # This should return the minimal set of attributes required to create a valid # Question. As you add validations to Question, be sure to # adjust the attributes here as well. let!(:user) { User.create(email: 'test@test.com', password: '123456') } - let (:category) { Legacy::Category.create!(name: 'Category') } - let(:valid_attributes) { + let(:category) { Legacy::Category.create!(name: 'Category') } + let(:valid_attributes) do { text: 'Question', option1: 'option1', @@ -36,11 +35,11 @@ module Legacy option5: 'option5', category_id: category.id } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { text: '' } - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in @@ -51,16 +50,16 @@ module Legacy sign_in user end - describe "GET #index" do - it "assigns all questions as @questions" do + describe 'GET #index' do + it 'assigns all questions as @questions' do question = Question.create! valid_attributes get :index, params: {}, session: valid_session expect(assigns(:questions)).to eq([question]) end end - describe "GET #show" do - it "assigns the requested question as @question" do + describe 'GET #show' do + it 'assigns the requested question as @question' do school = School.create!(name: 'School') question = Question.create! valid_attributes get :show, params: { school_id: school.id, id: question.to_param }, session: valid_session @@ -69,82 +68,82 @@ module Legacy end end - describe "GET #new" do - it "assigns a new question as @question" do + describe 'GET #new' do + it 'assigns a new question as @question' do get :new, params: {}, session: valid_session expect(assigns(:question)).to be_a_new(Question) end end - describe "GET #edit" do - it "assigns the requested question as @question" do + describe 'GET #edit' do + it 'assigns the requested question as @question' do question = Question.create! valid_attributes get :edit, params: { id: question.to_param }, session: valid_session expect(assigns(:question)).to eq(question) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Question" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Question' do + expect do post :create, params: { question: valid_attributes }, session: valid_session - }.to change(Question, :count).by(1) + end.to change(Question, :count).by(1) end - it "assigns a newly created question as @question" do + it 'assigns a newly created question as @question' do post :create, params: { question: valid_attributes }, session: valid_session expect(assigns(:question)).to be_a(Question) expect(assigns(:question)).to be_persisted end - it "redirects to the created question" do + it 'redirects to the created question' do post :create, params: { question: valid_attributes }, session: valid_session expect(response).to redirect_to(Question.last) end end - context "with invalid params" do - it "assigns a newly created but unsaved question as @question" do + context 'with invalid params' do + it 'assigns a newly created but unsaved question as @question' do post :create, params: { question: invalid_attributes }, session: valid_session expect(assigns(:question)).to be_a_new(Question) end it "re-renders the 'new' template" do post :create, params: { question: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { text: 'Question2' } - } + end - it "updates the requested question" do + it 'updates the requested question' do question = Question.create! valid_attributes put :update, params: { id: question.to_param, question: new_attributes }, session: valid_session question.reload expect(question.text).to eq('Question2') end - it "assigns the requested question as @question" do + it 'assigns the requested question as @question' do question = Question.create! valid_attributes put :update, params: { id: question.to_param, question: valid_attributes }, session: valid_session expect(assigns(:question)).to eq(question) end - it "redirects to the question" do + it 'redirects to the question' do question = Question.create! valid_attributes put :update, params: { id: question.to_param, question: valid_attributes }, session: valid_session expect(response).to redirect_to(question) end end - context "with invalid params" do - it "assigns the question as @question" do + context 'with invalid params' do + it 'assigns the question as @question' do question = Question.create! valid_attributes put :update, params: { id: question.to_param, question: invalid_attributes }, session: valid_session expect(assigns(:question)).to eq(question) @@ -153,25 +152,24 @@ module Legacy it "re-renders the 'edit' template" do question = Question.create! valid_attributes put :update, params: { id: question.to_param, question: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested question" do + describe 'DELETE #destroy' do + it 'destroys the requested question' do question = Question.create! valid_attributes - expect { + expect do delete :destroy, params: { id: question.to_param }, session: valid_session - }.to change(Question, :count).by(-1) + end.to change(Question, :count).by(-1) end - it "redirects to the questions list" do + it 'redirects to the questions list' do question = Question.create! valid_attributes delete :destroy, params: { id: question.to_param }, session: valid_session expect(response).to redirect_to(legacy_questions_url) end end - end end diff --git a/spec/controllers/legacy/recipient_lists_controller_spec.rb b/spec/controllers/legacy/recipient_lists_controller_spec.rb index 3b163934..f6161704 100644 --- a/spec/controllers/legacy/recipient_lists_controller_spec.rb +++ b/spec/controllers/legacy/recipient_lists_controller_spec.rb @@ -20,25 +20,24 @@ require 'rails_helper' module Legacy RSpec.describe RecipientListsController, type: :controller do - let!(:user) { User.create(email: 'test@test.com', password: '123456') } let(:school) { School.create!(name: 'School') } # This should return the minimal set of attributes required to create a valid # RecipientList. As you add validations to RecipientList, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { school_id: school.id, recipient_id_array: ['', '1', '2', '3'], name: 'Parents', description: 'List of parents.' } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { school_id: school.id, name: '' } - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in @@ -50,46 +49,47 @@ module Legacy sign_in user end - describe "GET #index" do - it "assigns all recipient_lists as @recipient_lists" do + describe 'GET #index' do + it 'assigns all recipient_lists as @recipient_lists' do recipient_list = RecipientList.create! valid_attributes get :index, params: { school_id: school.to_param }, session: valid_session expect(assigns(:recipient_lists)).to eq([recipient_list]) end end - describe "GET #show" do - it "assigns the requested recipient_list as @recipient_list" do + describe 'GET #show' do + it 'assigns the requested recipient_list as @recipient_list' do recipient_list = RecipientList.create! valid_attributes get :show, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session expect(assigns(:recipient_list)).to eq(recipient_list) end end - describe "GET #new" do - it "assigns a new recipient_list as @recipient_list" do + describe 'GET #new' do + it 'assigns a new recipient_list as @recipient_list' do get :new, params: { school_id: school.to_param }, session: valid_session expect(assigns(:recipient_list)).to be_a_new(RecipientList) end end - describe "GET #edit" do - it "assigns the requested recipient_list as @recipient_list" do + describe 'GET #edit' do + it 'assigns the requested recipient_list as @recipient_list' do recipient_list = RecipientList.create! valid_attributes get :edit, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session expect(assigns(:recipient_list)).to eq(recipient_list) end end - describe "POST #create" do - context "with valid params" do - it "creates a new RecipientList" do - expect { - post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session - }.to change(RecipientList, :count).by(1) + describe 'POST #create' do + context 'with valid params' do + it 'creates a new RecipientList' do + expect do + post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, + session: valid_session + end.to change(RecipientList, :count).by(1) end - it "assigns a newly created recipient_list as @recipient_list" do + it 'assigns a newly created recipient_list as @recipient_list' do post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session expect(assigns(:recipient_list)).to be_a(RecipientList) expect(assigns(:recipient_list)).to be_persisted @@ -100,80 +100,86 @@ module Legacy expect(assigns(:recipient_list).recipient_ids).to eq('1,2,3') end - it "redirects to the created recipient_list" do + it 'redirects to the created recipient_list' do post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session expect(response).to redirect_to(legacy_school_legacy_recipient_list_path(school, RecipientList.last)) end end - context "with invalid params" do - it "assigns a newly created but unsaved recipient_list as @recipient_list" do - post :create, params: { school_id: school.to_param, recipient_list: invalid_attributes }, session: valid_session + context 'with invalid params' do + it 'assigns a newly created but unsaved recipient_list as @recipient_list' do + post :create, params: { school_id: school.to_param, recipient_list: invalid_attributes }, + session: valid_session expect(assigns(:recipient_list)).to be_a_new(RecipientList) end it "re-renders the 'new' template" do - post :create, params: { school_id: school.to_param, recipient_list: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + post :create, params: { school_id: school.to_param, recipient_list: invalid_attributes }, + session: valid_session + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { recipient_id_array: ['', '3', '4', '5'] } - } + end - it "updates the requested recipient_list" do + it 'updates the requested recipient_list' do recipient_list = RecipientList.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: new_attributes }, session: valid_session + put :update, + params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: new_attributes }, session: valid_session recipient_list.reload expect(recipient_list.recipient_ids).to eq('3,4,5') end - it "assigns the requested recipient_list as @recipient_list" do + it 'assigns the requested recipient_list as @recipient_list' do recipient_list = RecipientList.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session + put :update, + params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session expect(assigns(:recipient_list)).to eq(recipient_list) end - it "redirects to the recipient_list" do + it 'redirects to the recipient_list' do recipient_list = RecipientList.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session + put :update, + params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session expect(response).to redirect_to(legacy_school_legacy_recipient_list_url(school, recipient_list)) end end - context "with invalid params" do - it "assigns the recipient_list as @recipient_list" do + context 'with invalid params' do + it 'assigns the recipient_list as @recipient_list' do recipient_list = RecipientList.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session + put :update, + params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session expect(assigns(:recipient_list)).to eq(recipient_list) end it "re-renders the 'edit' template" do recipient_list = RecipientList.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + put :update, + params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested recipient_list" do + describe 'DELETE #destroy' do + it 'destroys the requested recipient_list' do recipient_list = RecipientList.create! valid_attributes - expect { + expect do delete :destroy, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session - }.to change(RecipientList, :count).by(-1) + end.to change(RecipientList, :count).by(-1) end - it "redirects to the recipient_lists list" do + it 'redirects to the recipient_lists list' do recipient_list = RecipientList.create! valid_attributes delete :destroy, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session expect(response).to redirect_to(school) end end - end end diff --git a/spec/controllers/legacy/recipients_controller_spec.rb b/spec/controllers/legacy/recipients_controller_spec.rb index 05bcb086..eeee8762 100644 --- a/spec/controllers/legacy/recipients_controller_spec.rb +++ b/spec/controllers/legacy/recipients_controller_spec.rb @@ -20,20 +20,19 @@ require 'rails_helper' module Legacy RSpec.describe RecipientsController, type: :controller do - let!(:user) { User.create(email: 'test@test.com', password: '123456') } let(:school) { School.create!(name: 'School') } # This should return the minimal set of attributes required to create a valid # Recipient. As you add validations to Recipient, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { name: 'Recipient Name', phone: '111-222-3333', school_id: school.id } - } + end let(:invalid_attributes) { { name: '', phone: '111-222-3333' } } @@ -47,126 +46,130 @@ module Legacy sign_in user end - describe "GET #index" do - it "assigns all recipients as @recipients" do + describe 'GET #index' do + it 'assigns all recipients as @recipients' do recipient = Recipient.create! valid_attributes get :index, params: { school_id: school.to_param }, session: valid_session expect(assigns(:recipients)).to eq([recipient]) end end - describe "GET #show" do - it "assigns the requested recipient as @recipient" do + describe 'GET #show' do + it 'assigns the requested recipient as @recipient' do recipient = Recipient.create! valid_attributes get :show, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session expect(assigns(:recipient)).to eq(recipient) end end - describe "GET #new" do - it "assigns a new recipient as @recipient" do + describe 'GET #new' do + it 'assigns a new recipient as @recipient' do get :new, params: { school_id: school.id }, session: valid_session expect(assigns(:recipient)).to be_a_new(Recipient) end end - describe "GET #edit" do - it "assigns the requested recipient as @recipient" do + describe 'GET #edit' do + it 'assigns the requested recipient as @recipient' do recipient = Recipient.create! valid_attributes get :edit, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session expect(assigns(:recipient)).to eq(recipient) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Recipient" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Recipient' do + expect do post :create, params: { school_id: school.to_param, recipient: valid_attributes }, session: valid_session - }.to change(Recipient, :count).by(1) + end.to change(Recipient, :count).by(1) end - it "assigns a newly created recipient as @recipient" do + it 'assigns a newly created recipient as @recipient' do post :create, params: { school_id: school.to_param, recipient: valid_attributes }, session: valid_session expect(assigns(:recipient)).to be_a(Recipient) expect(assigns(:recipient)).to be_persisted end - it "redirects to the created recipient" do + it 'redirects to the created recipient' do post :create, params: { school_id: school.to_param, recipient: valid_attributes }, session: valid_session expect(response).to redirect_to(legacy_school_legacy_recipient_path(school, Recipient.last)) end end - context "with invalid params" do - it "assigns a newly created but unsaved recipient as @recipient" do + context 'with invalid params' do + it 'assigns a newly created but unsaved recipient as @recipient' do post :create, params: { school_id: school.to_param, recipient: invalid_attributes }, session: valid_session expect(assigns(:recipient)).to be_a_new(Recipient) end it "re-renders the 'new' template" do post :create, params: { school_id: school.to_param, recipient: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { name: 'New Name' } - } + end - it "updates the requested recipient" do + it 'updates the requested recipient' do recipient = Recipient.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: new_attributes }, session: valid_session + put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: new_attributes }, + session: valid_session recipient.reload expect(recipient.name).to eq('New Name') expect(recipient.phone).to eq('111-222-3333') end - it "assigns the requested recipient as @recipient" do + it 'assigns the requested recipient as @recipient' do recipient = Recipient.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, session: valid_session + put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, + session: valid_session expect(assigns(:recipient)).to eq(recipient) end - it "redirects to the recipient" do + it 'redirects to the recipient' do recipient = Recipient.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, session: valid_session + put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, + session: valid_session expect(response).to redirect_to(legacy_school_legacy_recipient_url(school, recipient)) end end - context "with invalid params" do - it "assigns the recipient as @recipient" do + context 'with invalid params' do + it 'assigns the recipient as @recipient' do recipient = Recipient.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, session: valid_session + put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, + session: valid_session expect(assigns(:recipient)).to eq(recipient) end it "re-renders the 'edit' template" do recipient = Recipient.create! valid_attributes - put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, + session: valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested recipient" do + describe 'DELETE #destroy' do + it 'destroys the requested recipient' do recipient = Recipient.create! valid_attributes - expect { + expect do delete :destroy, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session - }.to change(Recipient, :count).by(-1) + end.to change(Recipient, :count).by(-1) end - it "redirects to the recipients list" do + it 'redirects to the recipients list' do recipient = Recipient.create! valid_attributes delete :destroy, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session expect(response).to redirect_to(school) end end - end end diff --git a/spec/controllers/legacy/schedules_controller_spec.rb b/spec/controllers/legacy/schedules_controller_spec.rb index 0df1892e..deba8ff1 100644 --- a/spec/controllers/legacy/schedules_controller_spec.rb +++ b/spec/controllers/legacy/schedules_controller_spec.rb @@ -20,7 +20,6 @@ require 'rails_helper' module Legacy RSpec.describe SchedulesController, type: :controller do - let!(:user) { User.create(email: 'test@test.com', password: '123456') } let!(:school) { School.create!(name: 'School') } @@ -37,7 +36,7 @@ module Legacy # This should return the minimal set of attributes required to create a valid # Schedule. As you add validations to Schedule, be sure to # adjust the attributes here as well. - let(:valid_attributes) { + let(:valid_attributes) do { school_id: school.id, recipient_list_id: recipient_list.id, @@ -46,11 +45,11 @@ module Legacy description: 'Schedule for parent questions', time: (8 * 60) } - } + end - let(:invalid_attributes) { + let(:invalid_attributes) do { name: '' } - } + end # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in @@ -62,38 +61,38 @@ module Legacy sign_in user end - describe "GET #show" do - it "assigns the requested schedule as @schedule" do + describe 'GET #show' do + it 'assigns the requested schedule as @schedule' do schedule = Schedule.create! valid_attributes get :show, params: { school_id: school.id, id: schedule.to_param }, session: valid_session expect(assigns(:schedule)).to eq(schedule) end end - describe "GET #new" do - it "assigns a new schedule as @schedule" do + describe 'GET #new' do + it 'assigns a new schedule as @schedule' do get :new, params: { school_id: school.id }, session: valid_session expect(assigns(:schedule)).to be_a_new(Schedule) end end - describe "GET #edit" do - it "assigns the requested schedule as @schedule" do + describe 'GET #edit' do + it 'assigns the requested schedule as @schedule' do schedule = Schedule.create! valid_attributes get :edit, params: { school_id: school.id, id: schedule.to_param }, session: valid_session expect(assigns(:schedule)).to eq(schedule) end end - describe "POST #create" do - context "with valid params" do - it "creates a new Schedule" do - expect { + describe 'POST #create' do + context 'with valid params' do + it 'creates a new Schedule' do + expect do post :create, params: { school_id: school.id, schedule: valid_attributes }, session: valid_session - }.to change(Schedule, :count).by(1) + end.to change(Schedule, :count).by(1) end - it "assigns a newly created schedule as @schedule" do + it 'assigns a newly created schedule as @schedule' do post :create, params: { school_id: school.id, schedule: valid_attributes }, session: valid_session expect(assigns(:schedule)).to be_a(Schedule) expect(assigns(:schedule)).to be_persisted @@ -105,80 +104,84 @@ module Legacy expect(assigns(:schedule).time).to eq(60 * 12) end - it "redirects to the created schedule" do + it 'redirects to the created schedule' do post :create, params: { school_id: school.id, schedule: valid_attributes }, session: valid_session expect(response).to redirect_to([school, Schedule.last]) end end - context "with invalid params" do - it "assigns a newly created but unsaved schedule as @schedule" do + context 'with invalid params' do + it 'assigns a newly created but unsaved schedule as @schedule' do post :create, params: { school_id: school.id, schedule: invalid_attributes }, session: valid_session expect(assigns(:schedule)).to be_a_new(Schedule) end it "re-renders the 'new' template" do post :create, params: { school_id: school.id, schedule: invalid_attributes }, session: valid_session - expect(response).to render_template("new") + expect(response).to render_template('new') end end end - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { + describe 'PUT #update' do + context 'with valid params' do + let(:new_attributes) do { name: 'New Name' } - } + end - it "updates the requested schedule" do + it 'updates the requested schedule' do schedule = Schedule.create! valid_attributes - put :update, params: { school_id: school.id, id: schedule.to_param, schedule: new_attributes }, session: valid_session + put :update, params: { school_id: school.id, id: schedule.to_param, schedule: new_attributes }, + session: valid_session schedule.reload expect(schedule.name).to eq('New Name') end - it "assigns the requested schedule as @schedule" do + it 'assigns the requested schedule as @schedule' do schedule = Schedule.create! valid_attributes - put :update, params: { school_id: school.id, id: schedule.to_param, schedule: valid_attributes }, session: valid_session + put :update, params: { school_id: school.id, id: schedule.to_param, schedule: valid_attributes }, + session: valid_session expect(assigns(:schedule)).to eq(schedule) end - it "redirects to the schedule" do + it 'redirects to the schedule' do schedule = Schedule.create! valid_attributes - put :update, params: { school_id: school.id, id: schedule.to_param, schedule: valid_attributes }, session: valid_session + put :update, params: { school_id: school.id, id: schedule.to_param, schedule: valid_attributes }, + session: valid_session expect(response).to redirect_to([school, schedule]) end end - context "with invalid params" do - it "assigns the schedule as @schedule" do + context 'with invalid params' do + it 'assigns the schedule as @schedule' do schedule = Schedule.create! valid_attributes - put :update, params: { school_id: school.id, id: schedule.to_param, schedule: invalid_attributes }, session: valid_session + put :update, params: { school_id: school.id, id: schedule.to_param, schedule: invalid_attributes }, + session: valid_session expect(assigns(:schedule)).to eq(schedule) end it "re-renders the 'edit' template" do schedule = Schedule.create! valid_attributes - put :update, params: { school_id: school.id, id: schedule.to_param, schedule: invalid_attributes }, session: valid_session - expect(response).to render_template("edit") + put :update, params: { school_id: school.id, id: schedule.to_param, schedule: invalid_attributes }, + session: valid_session + expect(response).to render_template('edit') end end end - describe "DELETE #destroy" do - it "destroys the requested schedule" do + describe 'DELETE #destroy' do + it 'destroys the requested schedule' do schedule = Schedule.create! valid_attributes - expect { + expect do delete :destroy, params: { school_id: school.id, id: schedule.to_param }, session: valid_session - }.to change(Schedule, :count).by(-1) + end.to change(Schedule, :count).by(-1) end - it "redirects to the schedules list" do + it 'redirects to the schedules list' do schedule = Schedule.create! valid_attributes delete :destroy, params: { school_id: school.id, id: schedule.to_param }, session: valid_session expect(response).to redirect_to(school) end end - end end diff --git a/spec/controllers/legacy/schools_controller_spec.rb b/spec/controllers/legacy/schools_controller_spec.rb index 38278ae9..c078ac29 100644 --- a/spec/controllers/legacy/schools_controller_spec.rb +++ b/spec/controllers/legacy/schools_controller_spec.rb @@ -20,7 +20,6 @@ require 'rails_helper' module Legacy RSpec.describe SchoolsController, type: :controller do - let(:district) { District.create! name: 'District' } let!(:school) { School.create! name: 'school', district: district } let!(:user) { User.create(email: 'test@example.com', password: '123456') } @@ -29,157 +28,156 @@ module Legacy # This should return the minimal set of attributes required to create a valid # School. As you add validations to School, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - {name: 'School', district: district} - } - - let(:invalid_attributes) { - {name: ''} - } - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # SchoolsController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe "GET #show" do - it "assigns the requested school as @school" do - get :show, params: {id: school.to_param}, session: valid_session - expect(assigns(:school)).to eq(school) + let(:valid_attributes) do + { name: 'School', district: district } end - end - describe "GET #new" do - it "assigns a new school as @school" do - sign_in user - get :new, params: {} - expect(assigns(:school)).to be_a_new(School) + let(:invalid_attributes) do + { name: '' } end - end - describe "GET #edit" do - it "assigns the requested school as @school" do - sign_in user - school = School.create! valid_attributes - get :edit, params: {id: school.to_param} - expect(assigns(:school)).to eq(school) - end - end + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # SchoolsController. Be sure to keep this updated too. + let(:valid_session) { {} } - describe "GET #admin" do - it "assigns the requested school as @school" do - sign_in user - get :admin, params: {school_id: school.to_param} - expect(assigns(:school)).to eq(school) - end - - it "redirects if not logged in" do - get :admin, params: {school_id: school.to_param} - expect(response).to redirect_to(new_user_session_path) + describe 'GET #show' do + it 'assigns the requested school as @school' do + get :show, params: { id: school.to_param }, session: valid_session + expect(assigns(:school)).to eq(school) + end end - xit "redirects if user is not associated with school" do - another_user = User.create(email: 'test2@test.com', password: '123456') - sign_in another_user - - get :admin, params: {school_id: school.to_param} - expect(response).to redirect_to(root_path) + describe 'GET #new' do + it 'assigns a new school as @school' do + sign_in user + get :new, params: {} + expect(assigns(:school)).to be_a_new(School) + end end - end - describe "POST #create" do - before :each do - sign_in user + describe 'GET #edit' do + it 'assigns the requested school as @school' do + sign_in user + school = School.create! valid_attributes + get :edit, params: { id: school.to_param } + expect(assigns(:school)).to eq(school) + end end - context "with valid params" do - it "creates a new School" do - expect { - post :create, params: {school: valid_attributes} - }.to change(School, :count).by(1) + describe 'GET #admin' do + it 'assigns the requested school as @school' do + sign_in user + get :admin, params: { school_id: school.to_param } + expect(assigns(:school)).to eq(school) end - it "assigns a newly created school as @school" do - post :create, params: {school: valid_attributes} - expect(assigns(:school)).to be_a(School) - expect(assigns(:school)).to be_persisted + it 'redirects if not logged in' do + get :admin, params: { school_id: school.to_param } + expect(response).to redirect_to(new_user_session_path) end - it "redirects to the created school" do - post :create, params: {school: valid_attributes} - expect(response).to redirect_to(School.last) + xit 'redirects if user is not associated with school' do + another_user = User.create(email: 'test2@test.com', password: '123456') + sign_in another_user + + get :admin, params: { school_id: school.to_param } + expect(response).to redirect_to(root_path) end end - context "with invalid params" do - it "assigns a newly created but unsaved school as @school" do - post :create, params: {school: invalid_attributes} - expect(assigns(:school)).to be_a_new(School) + describe 'POST #create' do + before :each do + sign_in user end - it "re-renders the 'new' template" do - post :create, params: {school: invalid_attributes} - expect(response).to render_template("new") + context 'with valid params' do + it 'creates a new School' do + expect do + post :create, params: { school: valid_attributes } + end.to change(School, :count).by(1) + end + + it 'assigns a newly created school as @school' do + post :create, params: { school: valid_attributes } + expect(assigns(:school)).to be_a(School) + expect(assigns(:school)).to be_persisted + end + + it 'redirects to the created school' do + post :create, params: { school: valid_attributes } + expect(response).to redirect_to(School.last) + end end - end - end - describe "PUT #update" do - before :each do - sign_in user - end + context 'with invalid params' do + it 'assigns a newly created but unsaved school as @school' do + post :create, params: { school: invalid_attributes } + expect(assigns(:school)).to be_a_new(School) + end - context "with valid params" do - let(:new_attributes) { - {name: 'New School'} - } - - it "updates the requested school" do - put :update, params: {id: school.to_param, school: new_attributes} - school.reload - expect(school.name).to eq('New School') + it "re-renders the 'new' template" do + post :create, params: { school: invalid_attributes } + expect(response).to render_template('new') + end end + end - it "assigns the requested school as @school" do - put :update, params: {id: school.to_param, school: valid_attributes} - expect(assigns(:school)).to eq(school) + describe 'PUT #update' do + before :each do + sign_in user end - it "redirects to the school" do - put :update, params: {id: school.to_param, school: valid_attributes} - expect(response).to redirect_to(school) + context 'with valid params' do + let(:new_attributes) do + { name: 'New School' } + end + + it 'updates the requested school' do + put :update, params: { id: school.to_param, school: new_attributes } + school.reload + expect(school.name).to eq('New School') + end + + it 'assigns the requested school as @school' do + put :update, params: { id: school.to_param, school: valid_attributes } + expect(assigns(:school)).to eq(school) + end + + it 'redirects to the school' do + put :update, params: { id: school.to_param, school: valid_attributes } + expect(response).to redirect_to(school) + end end - end - context "with invalid params" do - it "assigns the school as @school" do - put :update, params: {id: school.to_param, school: invalid_attributes} - expect(assigns(:school)).to eq(school) - end + context 'with invalid params' do + it 'assigns the school as @school' do + put :update, params: { id: school.to_param, school: invalid_attributes } + expect(assigns(:school)).to eq(school) + end - it "re-renders the 'edit' template" do - put :update, params: {id: school.to_param, school: invalid_attributes} - expect(response).to render_template("edit") + it "re-renders the 'edit' template" do + put :update, params: { id: school.to_param, school: invalid_attributes } + expect(response).to render_template('edit') + end end end - end - describe "DELETE #destroy" do - before :each do - sign_in user - end + describe 'DELETE #destroy' do + before :each do + sign_in user + end - it "destroys the requested school" do - expect { - delete :destroy, params: {id: school.to_param} - }.to change(School, :count).by(-1) - end + it 'destroys the requested school' do + expect do + delete :destroy, params: { id: school.to_param } + end.to change(School, :count).by(-1) + end - it "redirects to the schools list" do - delete :destroy, params: {id: school.to_param} - expect(response).to redirect_to(legacy_schools_url) + it 'redirects to the schools list' do + delete :destroy, params: { id: school.to_param } + expect(response).to redirect_to(legacy_schools_url) + end end end - - end end diff --git a/spec/controllers/legacy/welcome_controller_spec.rb b/spec/controllers/legacy/welcome_controller_spec.rb index e0a17cd7..661f077a 100644 --- a/spec/controllers/legacy/welcome_controller_spec.rb +++ b/spec/controllers/legacy/welcome_controller_spec.rb @@ -2,12 +2,10 @@ require 'rails_helper' module Legacy RSpec.describe WelcomeController, type: :controller do - - describe "GET #index" do - it "works" do + describe 'GET #index' do + it 'works' do get :index end end - end end diff --git a/spec/controllers/overview_controller_spec.rb b/spec/controllers/overview_controller_spec.rb index 051cf2ed..27bb939f 100644 --- a/spec/controllers/overview_controller_spec.rb +++ b/spec/controllers/overview_controller_spec.rb @@ -4,13 +4,13 @@ describe OverviewController, type: :controller do include BasicAuthHelper let(:school) { create(:school) } let(:district) { create(:district) } - let!(:categories) { + let!(:categories) do [create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)] - } + end it 'fetches categories sorted by sort_index' do login_as district get :index, params: { school_id: school.to_param, district_id: district.to_param } - expect(assigns(:category_presenters).map(&:name)).to eql ['First', 'Second'] + expect(assigns(:category_presenters).map(&:name)).to eql %w[First Second] end end diff --git a/spec/factories.rb b/spec/factories.rb index 491040a8..7afc1ef1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,5 +1,4 @@ FactoryBot.define do - factory :district do name { "#{rand} District" } slug { name.parameterize } @@ -20,15 +19,15 @@ FactoryBot.define do factory :category, class: 'Category' do name { "A #{rand} category" } category_id { rand.to_s } - description { "A description of a category" } + description { 'A description of a category' } slug { name.parameterize } sort_index { 1 } end factory :subcategory do - name { "A subcategory" } + name { 'A subcategory' } subcategory_id { rand.to_s } - description { "A description of a subcategory" } + description { 'A description of a subcategory' } category factory :subcategory_with_measures do @@ -36,7 +35,7 @@ FactoryBot.define do measures_count { 2 } end after(:create) do |subcategory, evaluator| - create_list(:measure, evaluator.measures_count, subcategory: subcategory). each do |measure| + create_list(:measure, evaluator.measures_count, subcategory: subcategory).each do |measure| survey_item = create(:teacher_survey_item, measure: measure) create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item) end @@ -47,25 +46,33 @@ FactoryBot.define do factory :measure do measure_id { rand.to_s } name { 'A Measure' } - watch_low_benchmark { 2.0 } - growth_low_benchmark { 3.0 } - approval_low_benchmark { 4.0 } - ideal_low_benchmark { 4.5 } subcategory + # trait :with_student_survey_items do + # after(:create) do |measure| + # measure.survey_items << build_list(:student_survey_item, 2) + # end + # end end factory :survey_item do prompt { 'What do YOU think?' } measure factory :teacher_survey_item do - survey_item_id { "t-#{rand.to_s}" } + survey_item_id { "t-#{rand}" } + watch_low_benchmark { 2.0 } + growth_low_benchmark { 3.0 } + approval_low_benchmark { 4.0 } + ideal_low_benchmark { 4.5 } end factory :student_survey_item do - survey_item_id { "s-#{rand.to_s}" } + survey_item_id { "s-#{rand}" } + watch_low_benchmark { 2.0 } + growth_low_benchmark { 3.0 } + approval_low_benchmark { 4.0 } + ideal_low_benchmark { 4.5 } end end - factory :survey_item_response do likert_score { 3 } response_id { rand.to_s } diff --git a/spec/lib/seeder_spec.rb b/spec/lib/seeder_spec.rb index d8dcacf4..250633c0 100644 --- a/spec/lib/seeder_spec.rb +++ b/spec/lib/seeder_spec.rb @@ -8,19 +8,19 @@ describe Seeder do before { AcademicYear.delete_all } it 'seeds new academic years' do - expect { + expect do seeder.seed_academic_years '2020-21', '2021-22', '2022-23' - }.to change { AcademicYear.count }.by(3) - expect(AcademicYear.all.map(&:range)).to eq ['2020-21', '2021-22', '2022-23'] + end.to change { AcademicYear.count }.by(3) + expect(AcademicYear.all.map(&:range)).to eq %w[2020-21 2021-22 2022-23] end context 'when partial data already exists' do before { create(:academic_year, range: '2020-21') } it 'only creates new data' do - expect { + expect do seeder.seed_academic_years '2020-21', '2021-22' - }.to change { AcademicYear.count }.by(1) + end.to change { AcademicYear.count }.by(1) end end end @@ -32,30 +32,35 @@ describe Seeder do end it 'seeds new districts and schools' do - expect { + expect do seeder.seed_districts_and_schools sample_districts_and_schools_csv - }.to change { District.count }.by(2) - .and change { School.count }.by(2) + end.to change { District.count }.by(2) + .and change { School.count }.by(2) end context 'when partial data already exists' do let!(:existing_district) { create(:district, name: 'Boston') } - let!(:removed_school) { create(:school, name: 'John Oldes Academy', dese_id: 12345, district: existing_district) } + let!(:removed_school) do + create(:school, name: 'John Oldes Academy', dese_id: 12_345, district: existing_district) + end let!(:removed_survey_item_response) { create(:survey_item_response, school: removed_school) } - let!(:existing_school) { create(:school, name: 'Sam Adams Elementary School', dese_id: 350302, slug: 'some-slug-for-sam-adams', district: existing_district) } + let!(:existing_school) do + create(:school, name: 'Sam Adams Elementary School', dese_id: 350_302, slug: 'some-slug-for-sam-adams', + district: existing_district) + end it 'only creates new districts and schools' do - expect { + expect do seeder.seed_districts_and_schools sample_districts_and_schools_csv - }.to change { District.count }.by(1) - .and change { School.count }.by(0) # +1 for new school, -1 for old school + end.to change { District.count }.by(1) + .and change { School.count }.by(0) # +1 for new school, -1 for old school new_district = District.find_by_name 'Attleboro' expect(new_district.qualtrics_code).to eq 1 expect(new_district.slug).to eq 'attleboro' new_school = School.find_by_name 'Attleboro High School' - expect(new_school.dese_id).to eq 160505 + expect(new_school.dese_id).to eq 160_505 expect(new_school.qualtrics_code).to eq 1 expect(new_school.slug).to eq 'attleboro-high-school' end @@ -92,13 +97,17 @@ describe Seeder do end it 'creates new objects as necessary' do - expect { + expect do seeder.seed_sqm_framework sample_sqm_framework_csv - }.to change { Category.count }.by(4) - .and change { Subcategory.count }.by(15) - .and change { Measure.count }.by(31) - .and change { SurveyItem.count }.by(136) - .and change { AdminDataItem.count }.by(32) + end.to change { Category.count }.by(4) + .and change { Subcategory.count }.by(15) + .and change { Measure.count }.by(31) + .and change { + SurveyItem.count + }.by(136) + .and change { + AdminDataItem.count + }.by(32) end context 'updates records to match given data' do @@ -110,8 +119,8 @@ describe Seeder do teachers_leadership = Category.find_by_name 'Teachers & Leadership' expect(teachers_leadership.slug).to eq 'teachers-and-leadership' - expect(teachers_leadership.description).to eq "This is a category description." - expect(teachers_leadership.short_description).to eq "This is a category short description." + expect(teachers_leadership.description).to eq 'This is a category description.' + expect(teachers_leadership.short_description).to eq 'This is a category short description.' end it 'updates category sort index to match a predefined order' do @@ -124,31 +133,35 @@ describe Seeder do it 'updates subcategory data' do subcategory = Subcategory.find_by_name 'Safety' - expect(subcategory.description).to eq "This is a subcategory description." + expect(subcategory.description).to eq 'This is a subcategory description.' end it 'updates measure data' do measure = Measure.find_by_measure_id '2A-i' expect(measure.name).to eq 'Student Physical Safety' expect(measure.description).to eq 'This is a measure description.' - expect(measure.watch_low_benchmark).to eq 2.79 - expect(measure.growth_low_benchmark).to eq 3.3 - expect(measure.approval_low_benchmark).to eq 3.8 - expect(measure.ideal_low_benchmark).to eq 4.51 end - it 'does not overwrite the measure benchmarks with admin data benchmarks' do - measure = Measure.find_by_measure_id '1A-i' - expect(measure.approval_low_benchmark).to eq 3.5 + it 'does not overwrite the survey item benchmarks with admin data benchmarks' do + survey_item = SurveyItem.find_by_survey_item_id 't-prep-q1' + expect(survey_item.approval_low_benchmark).to eq 3.5 end it 'updates survey item data' do survey_item = SurveyItem.find_by_survey_item_id 's-phys-q1' expect(survey_item.prompt).to eq 'How often do you worry about violence at your school?' + expect(survey_item.watch_low_benchmark).to eq 2.79 + expect(survey_item.growth_low_benchmark).to eq 3.3 + expect(survey_item.approval_low_benchmark).to eq 3.8 + expect(survey_item.ideal_low_benchmark).to eq 4.51 end it 'updates admin data item data' do admin_data_item = AdminDataItem.find_by_admin_data_item_id 'a-phys-i1' + expect(admin_data_item.watch_low_benchmark).to eq 2.99 + expect(admin_data_item.growth_low_benchmark).to eq 3.5 + expect(admin_data_item.approval_low_benchmark).to eq 4 + expect(admin_data_item.ideal_low_benchmark).to eq 4.71 expect(admin_data_item.description).to eq 'Student to suspensions ratio' end end diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 70fad0d0..d2fd67b5 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -1,26 +1,26 @@ require 'rails_helper' module Legacy - describe "survey:attempt_questions" do - include_context "rake" + describe 'survey:attempt_questions' do + include_context 'rake' it 'should have environment as a prerequisite' do - expect(subject.prerequisites).to include("environment") + expect(subject.prerequisites).to include('environment') end - describe "basic flow" do - let(:now) { + describe 'basic flow' do + let(:now) do n = DateTime.now n += 1.day until n.on_weekday? return n - } + end let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) } - let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) } - let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) } + let(:recipient_schedules) { double('recipient schedules', ready: [ready_recipient_schedule]) } + let(:active_schedule) { double('active schedule', recipient_schedules: recipient_schedules) } - it "finds all active schedules" do - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + it 'finds all active schedules' do + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) Timecop.freeze(date) expect(ready_recipient_schedule).to receive(:attempt_question) @@ -29,10 +29,10 @@ module Legacy subject.invoke end - it "works only on weekdays" do + it 'works only on weekdays' do now = DateTime.now now += 1.day until now.on_weekend? - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) Timecop.freeze(date) expect(ready_recipient_schedule).to_not receive(:attempt_question) @@ -40,12 +40,12 @@ module Legacy end end - xdescribe "complex flow" do - let(:now) { + xdescribe 'complex flow' do + let(:now) do n = DateTime.now n += 1.day until n.on_weekday? return n - } + end let!(:school) { School.create!(name: 'School') } @@ -76,7 +76,7 @@ module Legacy before :each do now = DateTime.new now += 1.day until now.on_weekend? - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z")) + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT19:00:00%z')) Timecop.freeze(date) { subject.invoke } end @@ -87,7 +87,7 @@ module Legacy describe 'First attempt at specified time' do before :each do - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) Timecop.freeze(date) { subject.invoke } end @@ -193,7 +193,6 @@ module Legacy end describe 'Multiple Students In A Family' do - before :each do 3.times do |i| recipients[1].students.create(name: "Student#{i}") @@ -201,12 +200,12 @@ module Legacy end let(:students_recipient) { recipients[1] } - let(:students_recipient_schedule) { + let(:students_recipient_schedule) do students_recipient.recipient_schedules.for_schedule(schedule).first - } + end describe 'With A FOR_CHILD Question Is Asked' do - let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + let!(:date) { ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) } before :each do questions.first.update(for_recipient_students: true) @@ -224,7 +223,7 @@ module Legacy expect(students_recipient_schedule.queued_question_ids).to be_present queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/) expect(queued_question_ids.length).to eq(1) - expect(queued_question_ids.first).to eq("#{questions[0].id}") + expect(queued_question_ids.first).to eq(questions[0].id.to_s) end it 'should set the next_attempt_at to now when attempt is made on first student' do @@ -234,7 +233,9 @@ module Legacy it 'should set the next_attempt_at in the future when an attempts are made on each student' do students_recipient.attempts.last.save_response(answer_index: 3) - expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1) + expect { students_recipient_schedule.attempt_question }.to change { + students_recipient.attempts.count + }.by(1) expect(students_recipient_schedule.reload.queued_question_ids).to be_present attempt = students_recipient.attempts.last @@ -244,7 +245,9 @@ module Legacy attempt.save_response(answer_index: 4) expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day) - expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1) + expect { students_recipient_schedule.attempt_question }.to change { + students_recipient.attempts.count + }.by(1) expect(students_recipient_schedule.reload.queued_question_ids).to be_nil expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours)) @@ -266,7 +269,9 @@ module Legacy it 'resends the question about the same student if not responded to' do message_count = FakeSMS.messages.length - expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(0) + expect { students_recipient_schedule.attempt_question }.to change { + students_recipient.attempts.count + }.by(0) expect(FakeSMS.messages.length).to eq(message_count + 2) expect(FakeSMS.messages[message_count].body).to match(questions.first.text) expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/) @@ -276,7 +281,6 @@ module Legacy recipient_schedule = recipients[0].recipient_schedules.for_schedule(schedule).first expect(recipient_schedule.queued_question_ids).to be_nil end - end describe 'With A General Question Is Asked' do @@ -293,23 +297,21 @@ module Legacy expect(message.body).to_not match(/\(for .*\)/) end end - end end describe 'One Student In A Family' do - before :each do - recipients[1].students.create(name: "Only Student") + recipients[1].students.create(name: 'Only Student') end let(:students_recipient) { recipients[1] } - let(:students_recipient_schedule) { + let(:students_recipient_schedule) do students_recipient.recipient_schedules.for_schedule(schedule).first - } + end describe 'With A FOR_CHILD Question Is Asked' do - let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + let!(:date) { ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) } before :each do questions.first.update(for_recipient_students: true) @@ -330,11 +332,10 @@ module Legacy end describe 'Opted Out Recipient' do - before :each do recipients[1].update(opted_out: true) - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT20:00:00%z')) Timecop.freeze(date) { subject.invoke } end @@ -353,7 +354,6 @@ module Legacy end end end - end end end diff --git a/spec/models/legacy/attempt_spec.rb b/spec/models/legacy/attempt_spec.rb index edfa1c1c..665a4eb9 100644 --- a/spec/models/legacy/attempt_spec.rb +++ b/spec/models/legacy/attempt_spec.rb @@ -2,21 +2,22 @@ require 'rails_helper' module Legacy describe Attempt, type: :model do - let!(:school) { School.create!(name: 'School') } - let!(:recipient) { school.recipients.create(name: 'name', phone: "#{1}" * 9) } + let!(:recipient) { school.recipients.create(name: 'name', phone: '1' * 9) } let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}") + school.recipient_lists.create!(name: 'Parents', recipient_ids: recipient.id.to_s) end let!(:category) { Category.create(name: 'Category') } let!(:question) { create_questions(1, category).first } let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: "#{question.id}") + QuestionList.create!(name: 'Parent Questions', question_ids: question.id.to_s) end - let(:schedule) { Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) } + let(:schedule) do + Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) + end let(:recipient_schedule) do RecipientSchedule.create!( @@ -96,7 +97,7 @@ module Legacy expect(FakeSMS.messages.length).to eq(2) expect(FakeSMS.messages.first.to).to eq('111111111') - expect(FakeSMS.messages.first.body).to eq("Question 0:1") + expect(FakeSMS.messages.first.body).to eq('Question 0:1') expect(FakeSMS.messages.last.to).to eq('111111111') expect(FakeSMS.messages.last.body).to eq("Option 0:1 A: Reply 1\nOption 0:1 B: 2\nOption 0:1 C: 3\nOption 0:1 D: 4\nOption 0:1 E: 5") diff --git a/spec/models/legacy/district_spec.rb b/spec/models/legacy/district_spec.rb index f9d0d2b6..59e90b94 100644 --- a/spec/models/legacy/district_spec.rb +++ b/spec/models/legacy/district_spec.rb @@ -5,7 +5,7 @@ module Legacy let(:district1) { District.create(name: 'District one', state_id: 32) } let(:district2) { District.new(name: 'District two', state_id: 32) } - context "when saving or creating" do + context 'when saving or creating' do it 'should return a slug' do expect(district1.slug).to eq 'district-one' @@ -17,5 +17,4 @@ module Legacy end end end - end diff --git a/spec/models/legacy/question_spec.rb b/spec/models/legacy/question_spec.rb index ddf9130f..f907a23b 100644 --- a/spec/models/legacy/question_spec.rb +++ b/spec/models/legacy/question_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' module Legacy RSpec.describe Question, type: :model do - let!(:school1) { School.create!(name: 'School 1') } let!(:school2) { School.create!(name: 'School 2') } @@ -16,18 +15,33 @@ module Legacy let!(:category2questions) { create_questions(3, category2) } let(:question) { category1questions.first } - let!(:attempt1) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3) } - let!(:attempt2) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2) } + let!(:attempt1) do + Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3) + end + let!(:attempt2) do + Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2) + end let!(:attempt3) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[2]) } - let!(:attempt4) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3) } - let!(:attempt5) { Legacy::Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) } - let!(:attempt6) { Legacy::Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) } - let!(:attempt7) { Legacy::Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) } - let!(:attempt8) { Legacy::Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) } - let!(:attempt9) { Legacy::Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) } + let!(:attempt4) do + Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3) + end + let!(:attempt5) do + Legacy::Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) + end + let!(:attempt6) do + Legacy::Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) + end + let!(:attempt7) do + Legacy::Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) + end + let!(:attempt8) do + Legacy::Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) + end + let!(:attempt9) do + Legacy::Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) + end describe 'aggregated_responses_for_school' do - let(:aggregated_responses) { question.aggregated_responses_for_school(school1) } it 'aggregates all attempts with responses for the question for a given school' do @@ -48,8 +62,6 @@ module Legacy expect(aggregated_responses.question).to eq(question) expect(aggregated_responses.category).to eq(question.category) end - end - end end diff --git a/spec/models/legacy/recipient_list_spec.rb b/spec/models/legacy/recipient_list_spec.rb index d52d3894..1ef6e47c 100644 --- a/spec/models/legacy/recipient_list_spec.rb +++ b/spec/models/legacy/recipient_list_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' module Legacy describe RecipientList do - describe "Save" do - it "should convert the recipient_id_array into the recipient_ids attribute" do + describe 'Save' do + it 'should convert the recipient_id_array into the recipient_ids attribute' do recipient_list = RecipientList.create(name: 'Name', recipient_id_array: ['', '1', '2', '3']) expect(recipient_list).to be_a(RecipientList) expect(recipient_list).to be_persisted @@ -14,7 +14,7 @@ module Legacy end end - describe "when edited" do + describe 'when edited' do let!(:school) { School.create!(name: 'School') } let!(:recipients) { create_recipients(school, 3) } diff --git a/spec/models/legacy/recipient_spec.rb b/spec/models/legacy/recipient_spec.rb index 2db26a61..0b94eeec 100644 --- a/spec/models/legacy/recipient_spec.rb +++ b/spec/models/legacy/recipient_spec.rb @@ -2,21 +2,21 @@ require 'rails_helper' module Legacy describe Recipient do - describe "Import" do + describe 'Import' do let(:school) { School.create!(name: 'School') } let(:data) { "name,phone\rJared,111-222-333\rLauren,222-333-4444\rAbby,333-444-5555\r" } let(:file) { instance_double('File', path: 'path') } - xit "should parse file contents and return a result" do + xit 'should parse file contents and return a result' do expect(File).to receive(:open).with('path', universal_newline: false, headers: true) { StringIO.new(data) } Recipient.import(school, file) expect(Recipient.count).to eq(3) - expect(Recipient.all.map(&:name)).to eq(['Jared', 'Lauren', 'Abby']) + expect(Recipient.all.map(&:name)).to eq(%w[Jared Lauren Abby]) expect(Recipient.all.map(&:school).uniq).to eq([school]) end end - describe "When Deleted" do + describe 'When Deleted' do let!(:school) { School.create!(name: 'School') } let!(:recipients) { create_recipients(school, 3) } @@ -45,7 +45,6 @@ module Legacy end.to change { schedule.recipient_schedules.count }.from(3).to(2) expect(recipient_list.recipient_ids).to eq("#{recipients[0].id},#{recipients[2].id}") - end end end diff --git a/spec/models/legacy/schedule_spec.rb b/spec/models/legacy/schedule_spec.rb index c8d0d6a6..dca34c87 100644 --- a/spec/models/legacy/schedule_spec.rb +++ b/spec/models/legacy/schedule_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' module Legacy describe Schedule do - let!(:school) { School.create!(name: 'School') } let!(:recipients) { create_recipients(school, 3) } @@ -20,7 +19,7 @@ module Legacy QuestionList.create!(name: 'Questions', question_ids: questions.map(&:id).join(',')) end - let(:default_schedule_params) { + let(:default_schedule_params) do { school: school, recipient_list: recipient_list, @@ -31,7 +30,7 @@ module Legacy end_date: 11.months.from_now, active: true } - } + end let!(:active_schedule) do Schedule.create!(default_schedule_params) @@ -41,15 +40,15 @@ module Legacy Schedule.create!(default_schedule_params.merge!(name: 'Kids Schedule', recipient_list: kids_recipient_list)) end - let!(:old_schedule) { + let!(:old_schedule) do Schedule.create!(default_schedule_params.merge!(start_date: 13.month.ago, end_date: 1.months.ago)) - } + end - let!(:paused_schedule) { + let!(:paused_schedule) do Schedule.create!(default_schedule_params.merge!(active: false)) - } + end - describe "active" do + describe 'active' do it 'finds active schedules' do active = Schedule.active expect(active.length).to eq(2) @@ -59,6 +58,5 @@ module Legacy it 'creates a recipient_schedule for every recipient when created' do expect(active_schedule.recipient_schedules.length).to eq(3) end - end end diff --git a/spec/models/legacy/school_category_spec.rb b/spec/models/legacy/school_category_spec.rb index 9b2b8c6d..7a4024ce 100644 --- a/spec/models/legacy/school_category_spec.rb +++ b/spec/models/legacy/school_category_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' module Legacy RSpec.describe SchoolCategory, type: :model do - let!(:school1) { School.create!(name: 'School 1') } let!(:school2) { School.create!(name: 'School 2') } @@ -15,24 +14,38 @@ module Legacy let!(:category1questions) { create_questions(3, category1) } let!(:category2questions) { create_questions(3, category2) } - let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2) } + let!(:attempt1) do + Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2) + end let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1]) } - let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3) } - let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) } - let!(:attempt5) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) } - let!(:attempt6) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) } - let!(:attempt7) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) } - let!(:attempt8) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) } + let!(:attempt3) do + Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3) + end + let!(:attempt4) do + Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) + end + let!(:attempt5) do + Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) + end + let!(:attempt6) do + Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) + end + let!(:attempt7) do + Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) + end + let!(:attempt8) do + Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) + end let!(:school_category1) { SchoolCategory.for(school1, category1).first } describe 'aggregated_responses' do xit 'should provide the count and sum of all attempts' do expect(school_category1.aggregated_responses).to eq( - attempt_count: 5, - response_count: 4, - answer_index_total: 15 - ) + attempt_count: 5, + response_count: 4, + answer_index_total: 15 + ) end end @@ -43,16 +56,23 @@ module Legacy end describe 'sync_aggregated_responses' do - let!(:category3) { Category.create!(name: 'Category 3', parent_category: category1) } let!(:category3questions) { create_questions(3, category3) } - let!(:attempt7) { Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4) } - let!(:attempt8) { Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1) } + let!(:attempt7) do + Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4) + end + let!(:attempt8) do + Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1) + end let!(:attempt9) { Attempt.create!(question: category3questions[0], recipient: school1recipients[2]) } - let!(:attempt10) { Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5) } - let!(:attempt11) { Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5) } + let!(:attempt10) do + Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5) + end + let!(:attempt11) do + Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5) + end let!(:school_category3) { SchoolCategory.for(school1, category3).first } @@ -70,6 +90,5 @@ module Legacy expect(school_category1.answer_index_total).to eq(25) end end - end end diff --git a/spec/models/measure_spec.rb b/spec/models/measure_spec.rb new file mode 100644 index 00000000..25c9da43 --- /dev/null +++ b/spec/models/measure_spec.rb @@ -0,0 +1,153 @@ +require 'rails_helper' + +RSpec.describe Measure, type: :model do + let(:measure) { create(:measure) } + let(:admin_watch_low_benchmark) { 2.0 } + let(:admin_growth_low_benchmark) { 3.0 } + let(:admin_approval_low_benchmark) { 4.0 } + let(:admin_ideal_low_benchmark) { 5.0 } + + let(:student_watch_low_benchmark) { 1.5 } + let(:student_growth_low_benchmark) { 2.5 } + let(:student_approval_low_benchmark) { 3.5 } + let(:student_ideal_low_benchmark) { 4.5 } + + let(:teacher_watch_low_benchmark) { 1.2 } + let(:teacher_growth_low_benchmark) { 2.2 } + let(:teacher_approval_low_benchmark) { 3.2 } + let(:teacher_ideal_low_benchmark) { 4.2 } + + context 'when a measure includes only one admin data item' do + before do + create(:admin_data_item, measure: measure, + watch_low_benchmark: admin_watch_low_benchmark, + growth_low_benchmark: admin_growth_low_benchmark, + approval_low_benchmark: admin_approval_low_benchmark, + ideal_low_benchmark: admin_ideal_low_benchmark) + end + it 'returns a watch low benchmark equal to the admin data item watch low benchmark' do + expect(measure.watch_low_benchmark).to be 2.0 + end + end + + context 'when a measure includes only student survey items' do + before do + create(:student_survey_item, measure: measure, + watch_low_benchmark: student_watch_low_benchmark, + growth_low_benchmark: student_growth_low_benchmark, + approval_low_benchmark: student_approval_low_benchmark, + ideal_low_benchmark: student_ideal_low_benchmark) + end + it 'returns a watch low benchmark equal to the student survey item watch low benchmark ' do + expect(measure.watch_low_benchmark).to be 1.5 + end + end + + context 'when a measure includes only teacher survey items' do + before do + create(:teacher_survey_item, measure: measure, + watch_low_benchmark: teacher_watch_low_benchmark, + growth_low_benchmark: teacher_growth_low_benchmark, + approval_low_benchmark: teacher_approval_low_benchmark, + ideal_low_benchmark: teacher_ideal_low_benchmark) + end + it 'returns a watch low benchmark equal to the teacher survey item watch low benchmark ' do + expect(measure.watch_low_benchmark).to be 1.2 + end + end + + context 'when a measure includes admin data and student survey items' do + before do + create_list(:admin_data_item, 3, measure: measure, + watch_low_benchmark: admin_watch_low_benchmark, + growth_low_benchmark: admin_growth_low_benchmark, + approval_low_benchmark: admin_approval_low_benchmark, + ideal_low_benchmark: admin_ideal_low_benchmark) + + create(:student_survey_item, measure: measure, + watch_low_benchmark: student_watch_low_benchmark, + growth_low_benchmark: student_growth_low_benchmark, + approval_low_benchmark: student_approval_low_benchmark, + ideal_low_benchmark: student_ideal_low_benchmark) + end + + it 'returns the average of admin and student benchmarks where each admin data item has a weight of 1 and student survey items all together have a weight of 1' do + # (2*3 + 1.5)/4 + expect(measure.watch_low_benchmark).to be 1.875 + end + end + + context 'when a measure includes admin data and teacher survey items' do + before do + create_list(:admin_data_item, 3, measure: measure, + watch_low_benchmark: admin_watch_low_benchmark, + growth_low_benchmark: admin_growth_low_benchmark, + approval_low_benchmark: admin_approval_low_benchmark, + ideal_low_benchmark: admin_ideal_low_benchmark) + + create(:teacher_survey_item, measure: measure, + watch_low_benchmark: teacher_watch_low_benchmark, + growth_low_benchmark: teacher_growth_low_benchmark, + approval_low_benchmark: teacher_approval_low_benchmark, + ideal_low_benchmark: teacher_ideal_low_benchmark) + end + + it 'returns the average of admin and teacher benchmarks where each admin data item has a weight of 1 and teacher survey items all together have a weight of 1' do + # (2*3 + 1.2)/4 + expect(measure.watch_low_benchmark).to be 1.8 + end + end + + context 'when a measure includes student and teacher survey items' do + before do + create_list(:student_survey_item, 3, measure: measure, + watch_low_benchmark: student_watch_low_benchmark, + growth_low_benchmark: student_growth_low_benchmark, + approval_low_benchmark: student_approval_low_benchmark, + ideal_low_benchmark: student_ideal_low_benchmark) + + create_list(:teacher_survey_item, 3, measure: measure, + watch_low_benchmark: teacher_watch_low_benchmark, + growth_low_benchmark: teacher_growth_low_benchmark, + approval_low_benchmark: teacher_approval_low_benchmark, + ideal_low_benchmark: teacher_ideal_low_benchmark) + end + + it 'returns the average of student and teacher benchmarks where teacher survey items all together have a weight of 1 and all student survey items have a weight of 1' do + # (1.2+ 1.5)/2 + expect(measure.watch_low_benchmark).to be 1.35 + end + end + + context 'when a measure includes admin data and student and teacher survey items' do + before do + create_list(:admin_data_item, 3, measure: measure, + watch_low_benchmark: admin_watch_low_benchmark, + growth_low_benchmark: admin_growth_low_benchmark, + approval_low_benchmark: admin_approval_low_benchmark, + ideal_low_benchmark: admin_ideal_low_benchmark) + create_list(:student_survey_item, 3, measure: measure, + watch_low_benchmark: student_watch_low_benchmark, + growth_low_benchmark: student_growth_low_benchmark, + approval_low_benchmark: student_approval_low_benchmark, + ideal_low_benchmark: student_ideal_low_benchmark) + + create_list(:teacher_survey_item, 3, measure: measure, + watch_low_benchmark: teacher_watch_low_benchmark, + growth_low_benchmark: teacher_growth_low_benchmark, + approval_low_benchmark: teacher_approval_low_benchmark, + ideal_low_benchmark: teacher_ideal_low_benchmark) + end + + it 'returns the average of admin and teacher benchmarks where each admin data item has a weight of 1 and teacher survey items all together have a weight of 1, and student surveys have a weight of 1' do + # (2 * 3 + 1.2 + 1.5)/ 5 + expect(measure.watch_low_benchmark).to be_within(0.001).of 1.74 + # (3 * 3 + 2.2 + 2.5)/ 5 + expect(measure.growth_low_benchmark).to be_within(0.001).of 2.74 + # (4 * 3 + 3.2 + 3.5)/ 5 + expect(measure.approval_low_benchmark).to be_within(0.001).of 3.74 + # (5 * 3 + 4.2 + 4.5)/ 5 + expect(measure.ideal_low_benchmark).to be_within(0.001).of 4.74 + end + end +end diff --git a/spec/models/survey_item_response_spec.rb b/spec/models/survey_item_response_spec.rb index 7383ab31..3952c473 100644 --- a/spec/models/survey_item_response_spec.rb +++ b/spec/models/survey_item_response_spec.rb @@ -14,62 +14,81 @@ describe SurveyItemResponse, type: :model do context "and the number of responses for each of the measure's survey items meets the teacher threshold of 17" do before :each do - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 3) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item_2, academic_year: ay, school: school, likert_score: 4) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item_3, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 3) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item_2, academic_year: ay, school: school, likert_score: 4) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item_3, academic_year: ay, school: school, likert_score: 5) end it 'returns the average of the likert scores of the survey items' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to eq 4 + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to eq 4 end it 'affirms that the result meets the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be true end end context "and the average number of responses across the measure's survey items meets the teacher threshold of 17" do before :each do - create_list(:survey_item_response, 19, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 3) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, likert_score: 4) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, 19, survey_item: teacher_survey_item_1, academic_year: ay, school: school, + likert_score: 3) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, + likert_score: 4) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, + likert_score: 5) end it 'returns the average of the likert scores of the survey items' do average_score = 3.941 - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_within(0.001).of(average_score) + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_within(0.001).of(average_score) end end context "and none of the measure's survey items meets the teacher threshold of 17" do before :each do - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, likert_score: rand) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_1, academic_year: ay, school: school, + likert_score: rand) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, + likert_score: rand) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, + likert_score: rand) end it 'returns nil' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_nil + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_nil end it 'affirms that the result does not meet the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be false end end context "and the average number of responses across the measure's survey items does not meet the teacher threshold of 17" do before :each do - create_list(:survey_item_response, 18, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, likert_score: rand) + create_list(:survey_item_response, 18, survey_item: teacher_survey_item_1, academic_year: ay, school: school, + likert_score: rand) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_2, academic_year: ay, school: school, + likert_score: rand) + create_list(:survey_item_response, 16, survey_item: teacher_survey_item_3, academic_year: ay, school: school, + likert_score: rand) end it 'returns nil' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_nil + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_nil end it 'affirms that the result does not meet the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be false end end end @@ -81,62 +100,81 @@ describe SurveyItemResponse, type: :model do context "and the number of responses for each of the measure's survey items meets the student threshold of 196" do before :each do - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 3) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: 4) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_3, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 3) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: 4) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_3, academic_year: ay, school: school, likert_score: 5) end it 'returns the average of the likert scores of the survey items' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to eq 4 + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to eq 4 end it 'affirms that the result meets the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be true end end context "and the average number of responses across the measure's survey items meets the student threshold of 196" do before :each do - create_list(:survey_item_response, 200, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 3) - create_list(:survey_item_response, 195, survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: 4) - create_list(:survey_item_response, 193, survey_item: student_survey_item_3, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, 200, survey_item: student_survey_item_1, academic_year: ay, + school: school, likert_score: 3) + create_list(:survey_item_response, 195, survey_item: student_survey_item_2, academic_year: ay, + school: school, likert_score: 4) + create_list(:survey_item_response, 193, survey_item: student_survey_item_3, academic_year: ay, + school: school, likert_score: 5) end it 'returns the average of the likert scores of the survey items' do average_score = 3.988 - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_within(0.001).of(average_score) + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_within(0.001).of(average_score) end end context "and none of the measure's survey items meets the student threshold of 196" do before :each do - create_list(:survey_item_response, 195, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 195, survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 195, survey_item: student_survey_item_3, academic_year: ay, school: school, likert_score: rand) + create_list(:survey_item_response, 195, survey_item: student_survey_item_1, academic_year: ay, + school: school, likert_score: rand) + create_list(:survey_item_response, 195, survey_item: student_survey_item_2, academic_year: ay, + school: school, likert_score: rand) + create_list(:survey_item_response, 195, survey_item: student_survey_item_3, academic_year: ay, + school: school, likert_score: rand) end it 'returns nil' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_nil + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_nil end it 'affirms that the result does not meet the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be false end end context "and the average number of responses across the measure's survey items does not meet the student threshold of 196" do before :each do - create_list(:survey_item_response, 200, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: rand) - create_list(:survey_item_response, 191, survey_item: student_survey_item_3, academic_year: ay, school: school, likert_score: rand) + create_list(:survey_item_response, 200, survey_item: student_survey_item_1, academic_year: ay, + school: school, likert_score: rand) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_2, academic_year: ay, school: school, likert_score: rand) + create_list(:survey_item_response, 191, survey_item: student_survey_item_3, academic_year: ay, + school: school, likert_score: rand) end it 'returns nil' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_nil + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_nil end it 'affirms that the result does not meet the threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be false end end end @@ -147,65 +185,85 @@ describe SurveyItemResponse, type: :model do context 'and there is sufficient teacher data and sufficient student data' do before :each do - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 5) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 5) end it 'returns the average of the likert scores of the survey items' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to eq 5 + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to eq 5 end it 'affirms that the result does meet the thresholds' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be true - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be true end end context 'and there is sufficient teacher data and insufficient student data' do before :each do - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 5) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, + survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 1) end it 'returns the average of the likert scores of the teacher survey items' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to eq 5 + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to eq 5 end it 'affirms that the result meets the teacher threshold but not the student threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be true - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be false end end context 'and there is insufficient teacher data and sufficient student data' do before :each do - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, + survey_item: teacher_survey_item_1, academic_year: ay, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item_1, academic_year: ay, school: school, likert_score: 5) end it 'returns the average of the likert scores of the student survey items' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to eq 5 + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to eq 5 end it 'affirms that the result meets the student threshold but not the teacher threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be false - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be true + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be true end end context 'and there is insufficient teacher data and insufficient student data' do before :each do - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, survey_item: teacher_survey_item_1, academic_year: ay, school: school) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, survey_item: student_survey_item_1, academic_year: ay, school: school) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, + survey_item: teacher_survey_item_1, academic_year: ay, school: school) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, + survey_item: student_survey_item_1, academic_year: ay, school: school) end it 'returns nil' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).average).to be_nil + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).average).to be_nil end it 'affirms that the result does not meet either threshold' do - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_teacher_threshold?).to be false - expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: ay).meets_student_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_teacher_threshold?).to be false + expect(SurveyItemResponse.score_for_measure(measure: measure, school: school, + academic_year: ay).meets_student_threshold?).to be false end end end @@ -222,15 +280,21 @@ describe SurveyItemResponse, type: :model do let(:insufficient_student_survey_item) { create(:student_survey_item, measure: insufficient_measure) } before :each do - largest_threshold = [SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD].max - create_list(:survey_item_response, largest_threshold, survey_item: sufficient_teacher_survey_item, academic_year: ay, school: school, likert_score: 1) - create_list(:survey_item_response, largest_threshold, survey_item: sufficient_student_survey_item, academic_year: ay, school: school, likert_score: 4) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, survey_item: insufficient_teacher_survey_item, academic_year: ay, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, survey_item: insufficient_student_survey_item, academic_year: ay, school: school, likert_score: 1) + largest_threshold = [SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD].max + create_list(:survey_item_response, largest_threshold, survey_item: sufficient_teacher_survey_item, + academic_year: ay, school: school, likert_score: 1) + create_list(:survey_item_response, largest_threshold, survey_item: sufficient_student_survey_item, + academic_year: ay, school: school, likert_score: 4) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD - 1, + survey_item: insufficient_teacher_survey_item, academic_year: ay, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, + survey_item: insufficient_student_survey_item, academic_year: ay, school: school, likert_score: 1) end it 'returns the average score of all survey item responses for measures meeting their respective thresholds' do - expect(SurveyItemResponse.score_for_subcategory(subcategory: subcategory, school: school, academic_year: ay)).to eq 2.5 + expect(SurveyItemResponse.score_for_subcategory(subcategory: subcategory, school: school, + academic_year: ay)).to eq 2.5 end end end diff --git a/spec/presenters/category_presenter_spec.rb b/spec/presenters/category_presenter_spec.rb index 46032bfe..13280206 100644 --- a/spec/presenters/category_presenter_spec.rb +++ b/spec/presenters/category_presenter_spec.rb @@ -5,7 +5,8 @@ describe CategoryPresenter do subcategory1 = Subcategory.new(name: 'A subcategory', subcategory_id: '1') subcategory2 = Subcategory.new(name: 'Another subcategory', subcategory_id: '2') - category = Category.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category', short_description: 'A short description for some Category', category_id: '1') + category = Category.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], + description: 'A description for some Category', short_description: 'A short description for some Category', category_id: '1') return CategoryPresenter.new(category: category) end @@ -15,22 +16,22 @@ describe CategoryPresenter do end let(:school_culture_presenter) do - category = create(:category, name: "School Culture") + category = create(:category, name: 'School Culture') return CategoryPresenter.new(category: category) end let(:resources_presenter) do - category = create(:category, name: "Resources") + category = create(:category, name: 'Resources') return CategoryPresenter.new(category: category) end let(:academic_learning_presenter) do - category = create(:category, name: "Academic Learning") + category = create(:category, name: 'Academic Learning') return CategoryPresenter.new(category: category) end let(:community_and_wellbeing_presenter) do - category = create(:category, name: "Community & Wellbeing") + category = create(:category, name: 'Community & Wellbeing') return CategoryPresenter.new(category: category) end @@ -46,7 +47,10 @@ describe CategoryPresenter do end it 'maps subcategories to subcategory presenters' do - expect(category_presenter.subcategories(academic_year: AcademicYear.new, school: School.new).map(&:name)).to eq ['A subcategory', 'Another subcategory'] + expect(category_presenter.subcategories(academic_year: AcademicYear.new, + school: School.new).map(&:name)).to eq [ + 'A subcategory', 'Another subcategory' + ] end it 'returns the correct icon for the given category' do diff --git a/spec/presenters/gauge_presenter_spec.rb b/spec/presenters/gauge_presenter_spec.rb index 3d6db5ba..24fe9061 100644 --- a/spec/presenters/gauge_presenter_spec.rb +++ b/spec/presenters/gauge_presenter_spec.rb @@ -6,7 +6,7 @@ describe GaugePresenter do watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, - ideal_low_benchmark: 4.5, + ideal_low_benchmark: 4.5 ) end let(:score) { 3 } @@ -103,7 +103,7 @@ describe GaugePresenter do watch_low_benchmark: nil, growth_low_benchmark: nil, approval_low_benchmark: nil, - ideal_low_benchmark: nil, + ideal_low_benchmark: nil ) end let(:score) { nil } @@ -120,5 +120,4 @@ describe GaugePresenter do expect(gauge_presenter.score_percentage).to be_nil end end - end diff --git a/spec/presenters/measure_presenter_spec.rb b/spec/presenters/measure_presenter_spec.rb index 2fa0b2f1..d60ef666 100644 --- a/spec/presenters/measure_presenter_spec.rb +++ b/spec/presenters/measure_presenter_spec.rb @@ -19,8 +19,10 @@ describe MeasurePresenter do survey_item1 = create(:teacher_survey_item, measure: measure, prompt: 'A teacher survey item prompt') survey_item2 = create(:teacher_survey_item, measure: measure, prompt: 'Another teacher survey item prompt') - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, academic_year: academic_year, school: school, likert_score: 5) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, + academic_year: academic_year, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, + academic_year: academic_year, school: school, likert_score: 5) end it 'creates a gauge presenter that presents the average likert score' do @@ -32,7 +34,8 @@ describe MeasurePresenter do expect(measure_presenter.data_item_presenters.first.id).to eq 'teacher-survey-items-measure-id' expect(measure_presenter.data_item_presenters.first.title).to eq 'Teacher survey' expect(measure_presenter.data_item_presenters.first.data_item_accordion_id).to eq 'data-item-accordion-measure-id' - expect(measure_presenter.data_item_presenters.first.item_descriptions).to eq ["A teacher survey item prompt", "Another teacher survey item prompt"] + expect(measure_presenter.data_item_presenters.first.item_descriptions).to eq ['A teacher survey item prompt', + 'Another teacher survey item prompt'] end end @@ -51,13 +54,15 @@ describe MeasurePresenter do expect(first_data_item_presenter.id).to eq 'teacher-survey-items-measure-id' expect(first_data_item_presenter.title).to eq 'Teacher survey' expect(first_data_item_presenter.data_item_accordion_id).to eq 'data-item-accordion-measure-id' - expect(first_data_item_presenter.item_descriptions).to eq ["A teacher survey item prompt", "Another teacher survey item prompt"] + expect(first_data_item_presenter.item_descriptions).to eq ['A teacher survey item prompt', + 'Another teacher survey item prompt'] second_data_item_presenter = measure_presenter.data_item_presenters[1] expect(second_data_item_presenter.id).to eq 'admin-data-items-measure-id' expect(second_data_item_presenter.title).to eq 'School admin data' expect(second_data_item_presenter.data_item_accordion_id).to eq 'data-item-accordion-measure-id' - expect(second_data_item_presenter.item_descriptions).to eq ["An admin data item description", "Another admin data item description"] + expect(second_data_item_presenter.item_descriptions).to eq ['An admin data item description', + 'Another admin data item description'] end end @@ -66,13 +71,19 @@ describe MeasurePresenter do teacher_survey_item = create(:teacher_survey_item, measure: measure) student_survey_item = create(:student_survey_item, measure: measure) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item, academic_year: academic_year, school: school) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, survey_item: student_survey_item, academic_year: academic_year, school: school) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item, academic_year: academic_year, school: school) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD - 1, + survey_item: student_survey_item, academic_year: academic_year, school: school) end it 'tracks which parts of the data are sufficient' do - teacher_data_item_presenter = measure_presenter.data_item_presenters.find { |presenter| presenter.title == 'Teacher survey' } - student_data_item_presenter = measure_presenter.data_item_presenters.find { |presenter| presenter.title == 'Student survey' } + teacher_data_item_presenter = measure_presenter.data_item_presenters.find do |presenter| + presenter.title == 'Teacher survey' + end + student_data_item_presenter = measure_presenter.data_item_presenters.find do |presenter| + presenter.title == 'Student survey' + end expect(teacher_data_item_presenter.sufficient_data?).to be true expect(student_data_item_presenter.sufficient_data?).to be false end @@ -86,14 +97,18 @@ describe MeasurePresenter do end it 'tracks the reason for their insufficiency' do - teacher_data_item_presenter = measure_presenter.data_item_presenters.find { |presenter| presenter.title == 'Teacher survey' } - student_data_item_presenter = measure_presenter.data_item_presenters.find { |presenter| presenter.title == 'Student survey' } - admin_data_item_presenter = measure_presenter.data_item_presenters.find { |presenter| presenter.title == 'School admin data' } + teacher_data_item_presenter = measure_presenter.data_item_presenters.find do |presenter| + presenter.title == 'Teacher survey' + end + student_data_item_presenter = measure_presenter.data_item_presenters.find do |presenter| + presenter.title == 'Student survey' + end + admin_data_item_presenter = measure_presenter.data_item_presenters.find do |presenter| + presenter.title == 'School admin data' + end expect(teacher_data_item_presenter.reason_for_insufficiency).to eq 'low response rate' expect(student_data_item_presenter.reason_for_insufficiency).to eq 'low response rate' expect(admin_data_item_presenter.reason_for_insufficiency).to eq 'limited availability' end end - end - diff --git a/spec/presenters/scale_spec.rb b/spec/presenters/scale_spec.rb index af27b9dd..09052e20 100644 --- a/spec/presenters/scale_spec.rb +++ b/spec/presenters/scale_spec.rb @@ -2,9 +2,10 @@ require 'rails_helper' describe Scale do describe '#zone_for_score' do - let(:scale) { - Scale.new watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5 - } + let(:scale) do + Scale.new watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, + ideal_low_benchmark: 4.5 + end context 'when the score is 1.0' do it 'returns the warning zone' do diff --git a/spec/presenters/subcategory_card_presenter_spec.rb b/spec/presenters/subcategory_card_presenter_spec.rb index 7b27ac42..78d272b1 100644 --- a/spec/presenters/subcategory_card_presenter_spec.rb +++ b/spec/presenters/subcategory_card_presenter_spec.rb @@ -6,7 +6,7 @@ describe SubcategoryCardPresenter do watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, - ideal_low_benchmark: 4.5, + ideal_low_benchmark: 4.5 ) end @@ -16,11 +16,11 @@ describe SubcategoryCardPresenter do let(:score) { 1 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "warning-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'warning-harvey-ball' end it 'returns the color class of the zone' do - expect(subcategory_card_presenter.color).to eq "warning" + expect(subcategory_card_presenter.color).to eq 'warning' end end @@ -28,11 +28,11 @@ describe SubcategoryCardPresenter do let(:score) { 2 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "watch-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'watch-harvey-ball' end it 'returns the color class of the zone' do - expect(subcategory_card_presenter.color).to eq "watch" + expect(subcategory_card_presenter.color).to eq 'watch' end end @@ -40,11 +40,11 @@ describe SubcategoryCardPresenter do let(:score) { 3 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "growth-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'growth-harvey-ball' end it 'returns the color class of the zone' do - expect(subcategory_card_presenter.color).to eq "growth" + expect(subcategory_card_presenter.color).to eq 'growth' end end @@ -52,11 +52,11 @@ describe SubcategoryCardPresenter do let(:score) { 4 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "approval-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'approval-harvey-ball' end it 'returns the color class of the zone' do - expect(subcategory_card_presenter.color).to eq "approval" + expect(subcategory_card_presenter.color).to eq 'approval' end end @@ -64,11 +64,11 @@ describe SubcategoryCardPresenter do let(:score) { 5 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "ideal-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'ideal-harvey-ball' end it 'returns the color class of the zone' do - expect(subcategory_card_presenter.color).to eq "ideal" + expect(subcategory_card_presenter.color).to eq 'ideal' end end @@ -76,7 +76,7 @@ describe SubcategoryCardPresenter do let(:score) { 0 } it 'returns the icon that represents the zone' do - expect(subcategory_card_presenter.harvey_ball_icon).to eq "insufficient_data-harvey-ball" + expect(subcategory_card_presenter.harvey_ball_icon).to eq 'insufficient_data-harvey-ball' end it 'reports that there is insufficient data' do diff --git a/spec/presenters/subcategory_presenter_spec.rb b/spec/presenters/subcategory_presenter_spec.rb index 01847447..a280c2b1 100644 --- a/spec/presenters/subcategory_presenter_spec.rb +++ b/spec/presenters/subcategory_presenter_spec.rb @@ -3,20 +3,29 @@ require 'rails_helper' describe SubcategoryPresenter do let(:academic_year) { create(:academic_year, range: '1989-90') } let(:school) { create(:school, name: 'Best School') } - let(:subcategory) { create(:subcategory, name: 'A great subcategory', subcategory_id: 'A', description: 'A great description') } + let(:subcategory) do + create(:subcategory, name: 'A great subcategory', subcategory_id: 'A', description: 'A great description') + end let(:subcategory_presenter) do - measure1 = create(:measure, watch_low_benchmark: 4, growth_low_benchmark: 4.25, approval_low_benchmark: 4.5, ideal_low_benchmark: 4.75, subcategory: subcategory) - survey_item1 = create(:teacher_survey_item, measure: measure1) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 5) + measure1 = create(:measure, subcategory: subcategory) + survey_item1 = create(:teacher_survey_item, measure: measure1, watch_low_benchmark: 4, growth_low_benchmark: 4.25, + approval_low_benchmark: 4.5, ideal_low_benchmark: 4.75) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, + academic_year: academic_year, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item1, + academic_year: academic_year, school: school, likert_score: 5) - measure2 = create(:measure, watch_low_benchmark: 1.25, growth_low_benchmark: 1.5, approval_low_benchmark: 1.75, ideal_low_benchmark: 2.0, subcategory: subcategory) - survey_item2 = create(:teacher_survey_item, measure: measure2) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, academic_year: academic_year, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, academic_year: academic_year, school: school, likert_score: 5) + measure2 = create(:measure, subcategory: subcategory) + survey_item2 = create(:teacher_survey_item, measure: measure2, watch_low_benchmark: 1.25, + growth_low_benchmark: 1.5, approval_low_benchmark: 1.75, ideal_low_benchmark: 2.0) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, + academic_year: academic_year, school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item2, + academic_year: academic_year, school: school, likert_score: 5) - measure_of_only_admin_data = create(:measure, watch_low_benchmark: 0, growth_low_benchmark: 0, approval_low_benchmark: 0, ideal_low_benchmark: 0, subcategory: subcategory) - create(:admin_data_item, measure: measure_of_only_admin_data) + measure_of_only_admin_data = create(:measure, subcategory: subcategory) + create(:admin_data_item, measure: measure_of_only_admin_data, watch_low_benchmark: 0, growth_low_benchmark: 0, + approval_low_benchmark: 0, ideal_low_benchmark: 0) create_survey_item_responses_for_different_years_and_schools(survey_item1) @@ -45,15 +54,18 @@ describe SubcategoryPresenter do context 'When there are no measures populated with student or teacher surveys' do let(:empty_subcategory) { create :subcategory } - let(:empty_subcategory_presenter) { SubcategoryPresenter.new(subcategory: empty_subcategory, academic_year: academic_year, school: school )} + let(:empty_subcategory_presenter) do + SubcategoryPresenter.new(subcategory: empty_subcategory, academic_year: academic_year, school: school) + end it 'should make a subcategory presenter return insufficient data' do expect(empty_subcategory_presenter.subcategory_card_presenter.insufficient_data?).to eq true end end def create_survey_item_responses_for_different_years_and_schools(survey_item) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item, school: school, likert_score: 1) - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item, academic_year: academic_year, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item, + school: school, likert_score: 1) + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: survey_item, + academic_year: academic_year, likert_score: 1) end - end diff --git a/spec/presenters/variance_chart_row_presenter_spec.rb b/spec/presenters/variance_chart_row_presenter_spec.rb index d77131f9..46ced909 100644 --- a/spec/presenters/variance_chart_row_presenter_spec.rb +++ b/spec/presenters/variance_chart_row_presenter_spec.rb @@ -1,26 +1,36 @@ require 'rails_helper' describe VarianceChartRowPresenter do - let(:watch_low_benchmark) { 2.9 } let(:growth_low_benchmark) { 3.1 } let(:approval_low_benchmark) { 3.6 } let(:ideal_low_benchmark) { 3.8 } - let(:measure) { + let(:measure) do + measure = create( + :measure, + name: 'Some Title' + ) + + create(:student_survey_item, measure: measure, + watch_low_benchmark: watch_low_benchmark, + growth_low_benchmark: growth_low_benchmark, + approval_low_benchmark: approval_low_benchmark, + ideal_low_benchmark: ideal_low_benchmark) + + measure + end + + let(:measure_without_admin_data_items) do create( :measure, - name: 'Some Title', - watch_low_benchmark: watch_low_benchmark, - growth_low_benchmark: growth_low_benchmark, - approval_low_benchmark: approval_low_benchmark, - ideal_low_benchmark: ideal_low_benchmark + name: 'Some Title' ) - } + end - let(:presenter) { + let(:presenter) do VarianceChartRowPresenter.new measure: measure, score: score - } + end shared_examples_for 'measure_name' do it 'returns the measure name' do @@ -34,15 +44,15 @@ describe VarianceChartRowPresenter do it_behaves_like 'measure_name' it 'returns the correct color' do - expect(presenter.bar_color).to eq "fill-ideal" + expect(presenter.bar_color).to eq 'fill-ideal' end it 'returns a bar width equal to the approval zone width plus the proportionate ideal zone width' do - expect(presenter.bar_width).to eq "30.0%" + expect(presenter.bar_width).to eq '30.0%' end it 'returns an x-offset of 60%' do - expect(presenter.x_offset).to eq "60%" + expect(presenter.x_offset).to eq '60%' end end @@ -51,16 +61,16 @@ describe VarianceChartRowPresenter do it_behaves_like 'measure_name' - it "returns the correct color" do - expect(presenter.bar_color).to eq "fill-approval" + it 'returns the correct color' do + expect(presenter.bar_color).to eq 'fill-approval' end it 'returns a bar width equal to the proportionate approval zone width' do - expect(presenter.bar_width).to eq "10.0%" + expect(presenter.bar_width).to eq '10.0%' end it 'returns an x-offset of 60%' do - expect(presenter.x_offset).to eq "60%" + expect(presenter.x_offset).to eq '60%' end end @@ -69,17 +79,17 @@ describe VarianceChartRowPresenter do it_behaves_like 'measure_name' - it "returns the correct color" do - expect(presenter.bar_color).to eq "fill-growth" + it 'returns the correct color' do + expect(presenter.bar_color).to eq 'fill-growth' end it 'returns a bar width equal to the proportionate growth zone width' do - expect(presenter.bar_width).to eq "16.0%" + expect(presenter.bar_width).to eq '16.0%' end context 'in order to achieve the visual effect' do it 'returns an x-offset equal to 60% minus the bar width' do - expect(presenter.x_offset).to eq "44.0%" + expect(presenter.x_offset).to eq '44.0%' end end end @@ -89,17 +99,17 @@ describe VarianceChartRowPresenter do it_behaves_like 'measure_name' - it "returns the correct color" do - expect(presenter.bar_color).to eq "fill-watch" + it 'returns the correct color' do + expect(presenter.bar_color).to eq 'fill-watch' end it 'returns a bar width equal to the proportionate watch zone width plus the growth zone width' do - expect(presenter.bar_width).to eq "40.0%" + expect(presenter.bar_width).to eq '40.0%' end context 'in order to achieve the visual effect' do it 'returns an x-offset equal to 60% minus the bar width' do - expect(presenter.x_offset).to eq "20.0%" + expect(presenter.x_offset).to eq '20.0%' end end end @@ -109,37 +119,54 @@ describe VarianceChartRowPresenter do it_behaves_like 'measure_name' - it "returns the correct color" do - expect(presenter.bar_color).to eq "fill-warning" + it 'returns the correct color' do + expect(presenter.bar_color).to eq 'fill-warning' end it 'returns a bar width equal to the proportionate warning zone width plus the watch & growth zone widths' do - expect(presenter.bar_width).to eq "60.0%" + expect(presenter.bar_width).to eq '60.0%' end context 'in order to achieve the visual effect' do it 'returns an x-offset equal to 60% minus the bar width' do - expect(presenter.x_offset).to eq "0.0%" + expect(presenter.x_offset).to eq '0.0%' end end end context 'when a measure does not contain admin data items' do let(:score) { Score.new(nil, false, false) } + it 'it does not show a partial data indicator' do - expect(presenter.show_partial_data_indicator?).to be false + presenter_without_admin_data = VarianceChartRowPresenter.new measure: measure_without_admin_data_items, + score: score + expect(presenter_without_admin_data.show_partial_data_indicator?).to be false end end context 'when a measure contains admin data items' do before :each do - create :admin_data_item, measure: measure end + let(:score) { Score.new(nil, false, false) } it 'shows a partial data indicator' do - expect(presenter.show_partial_data_indicator?).to be true - expect(presenter.partial_data_sources).to eq ['administrative data'] + measure_with_admin_data = create( + :measure, + name: 'Some Title' + ) + create :admin_data_item, + measure: measure_with_admin_data, + watch_low_benchmark: watch_low_benchmark, + growth_low_benchmark: growth_low_benchmark, + approval_low_benchmark: approval_low_benchmark, + ideal_low_benchmark: ideal_low_benchmark + admin_data_presenter = VarianceChartRowPresenter.new measure: measure_with_admin_data, + score: Score.new( + 3.7, true, true + ) + expect(admin_data_presenter.show_partial_data_indicator?).to be true + expect(admin_data_presenter.partial_data_sources).to eq ['administrative data'] end end @@ -197,6 +224,12 @@ describe VarianceChartRowPresenter do context 'sorting scores' do it 'selects a longer bar before a shorter bar for measures in the approval/ideal zones' do + create(:student_survey_item, + measure: measure, + watch_low_benchmark: watch_low_benchmark, + growth_low_benchmark: growth_low_benchmark, + approval_low_benchmark: approval_low_benchmark, + ideal_low_benchmark: ideal_low_benchmark) approval_presenter = VarianceChartRowPresenter.new measure: measure, score: Score.new(3.7, true, true) ideal_presenter = VarianceChartRowPresenter.new measure: measure, score: Score.new(4.4, true, true) expect(ideal_presenter <=> approval_presenter).to be < 0 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 941bd2dc..3d016a99 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,11 +1,11 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'spec_helper' require 'rspec/rails' -Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/routing/legacy/categories_routing_spec.rb b/spec/routing/legacy/categories_routing_spec.rb index 43c35f98..766256f0 100644 --- a/spec/routing/legacy/categories_routing_spec.rb +++ b/spec/routing/legacy/categories_routing_spec.rb @@ -1,41 +1,39 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe CategoriesController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/categories").to route_to("legacy/categories#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/categories').to route_to('legacy/categories#index') end - it "routes to #new" do - expect(:get => "/categories/new").to route_to("legacy/categories#new") + it 'routes to #new' do + expect(get: '/categories/new').to route_to('legacy/categories#new') end - it "routes to #show" do - expect(:get => "/categories/1").to route_to("legacy/categories#show", :id => "1") + it 'routes to #show' do + expect(get: '/categories/1').to route_to('legacy/categories#show', id: '1') end - it "routes to #edit" do - expect(:get => "/categories/1/edit").to route_to("legacy/categories#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/categories/1/edit').to route_to('legacy/categories#edit', id: '1') end - it "routes to #create" do - expect(:post => "/categories").to route_to("legacy/categories#create") + it 'routes to #create' do + expect(post: '/categories').to route_to('legacy/categories#create') end - it "routes to #update via PUT" do - expect(:put => "/categories/1").to route_to("legacy/categories#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/categories/1').to route_to('legacy/categories#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/categories/1").to route_to("legacy/categories#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/categories/1').to route_to('legacy/categories#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/categories/1").to route_to("legacy/categories#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/categories/1').to route_to('legacy/categories#destroy', id: '1') end - end end end diff --git a/spec/routing/legacy/districts_routing_spec.rb b/spec/routing/legacy/districts_routing_spec.rb index 534dea44..71dac240 100644 --- a/spec/routing/legacy/districts_routing_spec.rb +++ b/spec/routing/legacy/districts_routing_spec.rb @@ -1,41 +1,39 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe DistrictsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/districts").to route_to("legacy/districts#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/districts').to route_to('legacy/districts#index') end - it "routes to #new" do - expect(:get => "/districts/new").to route_to("legacy/districts#new") + it 'routes to #new' do + expect(get: '/districts/new').to route_to('legacy/districts#new') end - it "routes to #show" do - expect(:get => "/districts/1").to route_to("legacy/districts#show", :id => "1") + it 'routes to #show' do + expect(get: '/districts/1').to route_to('legacy/districts#show', id: '1') end - it "routes to #edit" do - expect(:get => "/districts/1/edit").to route_to("legacy/districts#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/districts/1/edit').to route_to('legacy/districts#edit', id: '1') end - it "routes to #create" do - expect(:post => "/districts").to route_to("legacy/districts#create") + it 'routes to #create' do + expect(post: '/districts').to route_to('legacy/districts#create') end - it "routes to #update via PUT" do - expect(:put => "/districts/1").to route_to("legacy/districts#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/districts/1').to route_to('legacy/districts#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/districts/1").to route_to("legacy/districts#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/districts/1').to route_to('legacy/districts#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/districts/1").to route_to("legacy/districts#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/districts/1').to route_to('legacy/districts#destroy', id: '1') end - end end end diff --git a/spec/routing/legacy/question_lists_routing_spec.rb b/spec/routing/legacy/question_lists_routing_spec.rb index 5db33621..96d52193 100644 --- a/spec/routing/legacy/question_lists_routing_spec.rb +++ b/spec/routing/legacy/question_lists_routing_spec.rb @@ -1,41 +1,39 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe Legacy::QuestionListsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/question_lists").to route_to("legacy/question_lists#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/question_lists').to route_to('legacy/question_lists#index') end - it "routes to #new" do - expect(:get => "/question_lists/new").to route_to("legacy/question_lists#new") + it 'routes to #new' do + expect(get: '/question_lists/new').to route_to('legacy/question_lists#new') end - it "routes to #show" do - expect(:get => "/question_lists/1").to route_to("legacy/question_lists#show", :id => "1") + it 'routes to #show' do + expect(get: '/question_lists/1').to route_to('legacy/question_lists#show', id: '1') end - it "routes to #edit" do - expect(:get => "/question_lists/1/edit").to route_to("legacy/question_lists#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/question_lists/1/edit').to route_to('legacy/question_lists#edit', id: '1') end - it "routes to #create" do - expect(:post => "/question_lists").to route_to("legacy/question_lists#create") + it 'routes to #create' do + expect(post: '/question_lists').to route_to('legacy/question_lists#create') end - it "routes to #update via PUT" do - expect(:put => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/question_lists/1').to route_to('legacy/question_lists#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/question_lists/1').to route_to('legacy/question_lists#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/question_lists/1").to route_to("legacy/question_lists#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/question_lists/1').to route_to('legacy/question_lists#destroy', id: '1') end - end end end diff --git a/spec/routing/legacy/questions_routing_spec.rb b/spec/routing/legacy/questions_routing_spec.rb index 158d58dc..567064ad 100644 --- a/spec/routing/legacy/questions_routing_spec.rb +++ b/spec/routing/legacy/questions_routing_spec.rb @@ -1,41 +1,39 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe QuestionsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/questions").to route_to("legacy/questions#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/questions').to route_to('legacy/questions#index') end - it "routes to #new" do - expect(:get => "/questions/new").to route_to("legacy/questions#new") + it 'routes to #new' do + expect(get: '/questions/new').to route_to('legacy/questions#new') end - it "routes to #show" do - expect(:get => "/questions/1").to route_to("legacy/questions#show", :id => "1") + it 'routes to #show' do + expect(get: '/questions/1').to route_to('legacy/questions#show', id: '1') end - it "routes to #edit" do - expect(:get => "/questions/1/edit").to route_to("legacy/questions#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/questions/1/edit').to route_to('legacy/questions#edit', id: '1') end - it "routes to #create" do - expect(:post => "/questions").to route_to("legacy/questions#create") + it 'routes to #create' do + expect(post: '/questions').to route_to('legacy/questions#create') end - it "routes to #update via PUT" do - expect(:put => "/questions/1").to route_to("legacy/questions#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/questions/1').to route_to('legacy/questions#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/questions/1").to route_to("legacy/questions#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/questions/1').to route_to('legacy/questions#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/questions/1").to route_to("legacy/questions#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/questions/1').to route_to('legacy/questions#destroy', id: '1') end - end end end diff --git a/spec/routing/legacy/recipient_lists_routing_spec.rb b/spec/routing/legacy/recipient_lists_routing_spec.rb index 60a14eb6..03410437 100644 --- a/spec/routing/legacy/recipient_lists_routing_spec.rb +++ b/spec/routing/legacy/recipient_lists_routing_spec.rb @@ -1,47 +1,54 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe RecipientListsController, type: :routing do - describe "routing" do + describe 'routing' do before(:each) do @school = School.create!( - :name => "MyString", - :district_id => 1 + name: 'MyString', + district_id: 1 ) end - it "routes to #index" do - expect(:get => "schools/#{@school.id}/recipient_lists").to route_to("legacy/recipient_lists#index", school_id: @school.id.to_s) + it 'routes to #index' do + expect(get: "schools/#{@school.id}/recipient_lists").to route_to('legacy/recipient_lists#index', + school_id: @school.id.to_s) end - it "routes to #new" do - expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("legacy/recipient_lists#new", school_id: @school.id.to_s) + it 'routes to #new' do + expect(get: "schools/#{@school.id}/recipient_lists/new").to route_to('legacy/recipient_lists#new', + school_id: @school.id.to_s) end - it "routes to #show" do - expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#show", school_id: @school.id.to_s, :id => "1") + it 'routes to #show' do + expect(get: "schools/#{@school.id}/recipient_lists/1").to route_to('legacy/recipient_lists#show', + school_id: @school.id.to_s, id: '1') end - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("legacy/recipient_lists#edit", school_id: @school.id.to_s, :id => "1") + it 'routes to #edit' do + expect(get: "schools/#{@school.id}/recipient_lists/1/edit").to route_to('legacy/recipient_lists#edit', + school_id: @school.id.to_s, id: '1') end - it "routes to #create" do - expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("legacy/recipient_lists#create", school_id: @school.id.to_s) + it 'routes to #create' do + expect(post: "schools/#{@school.id}/recipient_lists").to route_to('legacy/recipient_lists#create', + school_id: @school.id.to_s) end - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PUT' do + expect(put: "schools/#{@school.id}/recipient_lists/1").to route_to('legacy/recipient_lists#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PATCH' do + expect(patch: "schools/#{@school.id}/recipient_lists/1").to route_to('legacy/recipient_lists#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#destroy", school_id: @school.id.to_s, :id => "1") + it 'routes to #destroy' do + expect(delete: "schools/#{@school.id}/recipient_lists/1").to route_to('legacy/recipient_lists#destroy', + school_id: @school.id.to_s, id: '1') end - end end end diff --git a/spec/routing/legacy/recipients_routing_spec.rb b/spec/routing/legacy/recipients_routing_spec.rb index 6cc9e994..f081b375 100644 --- a/spec/routing/legacy/recipients_routing_spec.rb +++ b/spec/routing/legacy/recipients_routing_spec.rb @@ -1,47 +1,54 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe RecipientsController, type: :routing do - describe "routing" do + describe 'routing' do before(:each) do @school = School.create!( - :name => "MyString", - :district_id => 1 + name: 'MyString', + district_id: 1 ) end - it "routes to #index" do - expect(:get => "schools/#{@school.id}/recipients").to route_to("legacy/recipients#index", school_id: @school.id.to_s) + it 'routes to #index' do + expect(get: "schools/#{@school.id}/recipients").to route_to('legacy/recipients#index', + school_id: @school.id.to_s) end - it "routes to #new" do - expect(:get => "schools/#{@school.id}/recipients/new").to route_to("legacy/recipients#new", school_id: @school.id.to_s) + it 'routes to #new' do + expect(get: "schools/#{@school.id}/recipients/new").to route_to('legacy/recipients#new', + school_id: @school.id.to_s) end - it "routes to #show" do - expect(:get => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#show", school_id: @school.id.to_s, :id => "1") + it 'routes to #show' do + expect(get: "schools/#{@school.id}/recipients/1").to route_to('legacy/recipients#show', + school_id: @school.id.to_s, id: '1') end - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("legacy/recipients#edit", school_id: @school.id.to_s, :id => "1") + it 'routes to #edit' do + expect(get: "schools/#{@school.id}/recipients/1/edit").to route_to('legacy/recipients#edit', + school_id: @school.id.to_s, id: '1') end - it "routes to #create" do - expect(:post => "schools/#{@school.id}/recipients").to route_to("legacy/recipients#create", school_id: @school.id.to_s) + it 'routes to #create' do + expect(post: "schools/#{@school.id}/recipients").to route_to('legacy/recipients#create', + school_id: @school.id.to_s) end - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PUT' do + expect(put: "schools/#{@school.id}/recipients/1").to route_to('legacy/recipients#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PATCH' do + expect(patch: "schools/#{@school.id}/recipients/1").to route_to('legacy/recipients#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#destroy", school_id: @school.id.to_s, :id => "1") + it 'routes to #destroy' do + expect(delete: "schools/#{@school.id}/recipients/1").to route_to('legacy/recipients#destroy', + school_id: @school.id.to_s, id: '1') end - end end end diff --git a/spec/routing/legacy/schedules_routing_spec.rb b/spec/routing/legacy/schedules_routing_spec.rb index 58374261..0dc12392 100644 --- a/spec/routing/legacy/schedules_routing_spec.rb +++ b/spec/routing/legacy/schedules_routing_spec.rb @@ -1,47 +1,54 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe SchedulesController, type: :routing do - describe "routing" do + describe 'routing' do before(:each) do @school = School.create!( - :name => "MyString", - :district_id => 1 + name: 'MyString', + district_id: 1 ) end - it "routes to #index" do - expect(:get => "schools/#{@school.id}/schedules").to route_to("legacy/schedules#index", school_id: @school.id.to_s) + it 'routes to #index' do + expect(get: "schools/#{@school.id}/schedules").to route_to('legacy/schedules#index', + school_id: @school.id.to_s) end - it "routes to #new" do - expect(:get => "schools/#{@school.id}/schedules/new").to route_to("legacy/schedules#new", school_id: @school.id.to_s) + it 'routes to #new' do + expect(get: "schools/#{@school.id}/schedules/new").to route_to('legacy/schedules#new', + school_id: @school.id.to_s) end - it "routes to #show" do - expect(:get => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#show", school_id: @school.id.to_s, :id => "1") + it 'routes to #show' do + expect(get: "schools/#{@school.id}/schedules/1").to route_to('legacy/schedules#show', + school_id: @school.id.to_s, id: '1') end - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/schedules/1/edit").to route_to("legacy/schedules#edit", school_id: @school.id.to_s, :id => "1") + it 'routes to #edit' do + expect(get: "schools/#{@school.id}/schedules/1/edit").to route_to('legacy/schedules#edit', + school_id: @school.id.to_s, id: '1') end - it "routes to #create" do - expect(:post => "schools/#{@school.id}/schedules").to route_to("legacy/schedules#create", school_id: @school.id.to_s) + it 'routes to #create' do + expect(post: "schools/#{@school.id}/schedules").to route_to('legacy/schedules#create', + school_id: @school.id.to_s) end - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PUT' do + expect(put: "schools/#{@school.id}/schedules/1").to route_to('legacy/schedules#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#update", school_id: @school.id.to_s, :id => "1") + it 'routes to #update via PATCH' do + expect(patch: "schools/#{@school.id}/schedules/1").to route_to('legacy/schedules#update', + school_id: @school.id.to_s, id: '1') end - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#destroy", school_id: @school.id.to_s, :id => "1") + it 'routes to #destroy' do + expect(delete: "schools/#{@school.id}/schedules/1").to route_to('legacy/schedules#destroy', + school_id: @school.id.to_s, id: '1') end - end end end diff --git a/spec/routing/legacy/schools_routing_spec.rb b/spec/routing/legacy/schools_routing_spec.rb index d4340f9c..11604c11 100644 --- a/spec/routing/legacy/schools_routing_spec.rb +++ b/spec/routing/legacy/schools_routing_spec.rb @@ -1,41 +1,39 @@ -require "rails_helper" +require 'rails_helper' module Legacy RSpec.describe SchoolsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/schools").to route_to("legacy/schools#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/schools').to route_to('legacy/schools#index') end - it "routes to #new" do - expect(:get => "/schools/new").to route_to("legacy/schools#new") + it 'routes to #new' do + expect(get: '/schools/new').to route_to('legacy/schools#new') end - it "routes to #show" do - expect(:get => "/schools/1").to route_to("legacy/schools#show", :id => "1") + it 'routes to #show' do + expect(get: '/schools/1').to route_to('legacy/schools#show', id: '1') end - it "routes to #edit" do - expect(:get => "/schools/1/edit").to route_to("legacy/schools#edit", :id => "1") + it 'routes to #edit' do + expect(get: '/schools/1/edit').to route_to('legacy/schools#edit', id: '1') end - it "routes to #create" do - expect(:post => "/schools").to route_to("legacy/schools#create") + it 'routes to #create' do + expect(post: '/schools').to route_to('legacy/schools#create') end - it "routes to #update via PUT" do - expect(:put => "/schools/1").to route_to("legacy/schools#update", :id => "1") + it 'routes to #update via PUT' do + expect(put: '/schools/1').to route_to('legacy/schools#update', id: '1') end - it "routes to #update via PATCH" do - expect(:patch => "/schools/1").to route_to("legacy/schools#update", :id => "1") + it 'routes to #update via PATCH' do + expect(patch: '/schools/1').to route_to('legacy/schools#update', id: '1') end - it "routes to #destroy" do - expect(:delete => "/schools/1").to route_to("legacy/schools#destroy", :id => "1") + it 'routes to #destroy' do + expect(delete: '/schools/1').to route_to('legacy/schools#destroy', id: '1') end - end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 25d922d5..ad7b2f90 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,67 +64,63 @@ RSpec.configure do |config| Capybara.page.driver.resize(3000, 3000) end -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = 'doc' + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed config.before(:each) do - stub_const("Twilio::REST::Client", FakeSMS) + stub_const('Twilio::REST::Client', FakeSMS) end config.after(:each) do FakeSMS.reset end - end - require 'active_support/all' class FakeSMS Message = Struct.new(:from, :to, :body) @@ -132,8 +128,7 @@ class FakeSMS cattr_accessor :messages self.messages = [] - def initialize(_account_sid, _auth_token) - end + def initialize(_account_sid, _auth_token); end def self.reset self.messages = [] @@ -145,12 +140,12 @@ class FakeSMS def create(from:, to:, body:) self.class.messages << Message.new(from, to, body) - return Struct.new(:sid).new(self.class.messages.length-1) + Struct.new(:sid).new(self.class.messages.length - 1) end def get(sid) phone = self.class.messages[sid].to - phone = "+1#{phone}" unless phone.starts_with?("+1") + phone = "+1#{phone}" unless phone.starts_with?('+1') Struct.new(:to).new(phone) end end @@ -160,13 +155,13 @@ def create_recipients(school, count) count.times do |i| recipients << school.recipients.create( name: "Person#{i}", - phone: "+" + ("#{i}" * 10), + phone: '+' + (i.to_s * 10) ) end - return recipients + recipients end -def create_questions(count, category=nil) +def create_questions(count, category = nil) questions = [] count.times do |i| questions << Legacy::Question.create( @@ -179,5 +174,5 @@ def create_questions(count, category=nil) category: category ) end - return questions + questions end diff --git a/spec/support/shared_contexts/rake.rb b/spec/support/shared_contexts/rake.rb index d190e2bf..0892f51a 100644 --- a/spec/support/shared_contexts/rake.rb +++ b/spec/support/shared_contexts/rake.rb @@ -1,13 +1,13 @@ -require "rake" +require 'rake' -shared_context "rake" do +shared_context 'rake' do let(:rake) { Rake::Application.new } let(:task_name) { self.class.top_level_description } - let(:task_path) { "lib/tasks/#{task_name.split(":").first}" } + let(:task_path) { "lib/tasks/#{task_name.split(':').first}" } subject { rake[task_name] } def loaded_files_excluding_current_rake_file - $".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s } + $".reject { |file| file == Rails.root.join("#{task_path}.rake").to_s } end before do diff --git a/spec/system/authentication_spec.rb b/spec/system/authentication_spec.rb index 258a3707..b9f43f73 100644 --- a/spec/system/authentication_spec.rb +++ b/spec/system/authentication_spec.rb @@ -27,12 +27,12 @@ describe 'authentication' do end end - private def username district.name.downcase end + def password "#{username}!" end diff --git a/spec/system/journey_spec.rb b/spec/system/journey_spec.rb index 43db772b..6971c8c3 100644 --- a/spec/system/journey_spec.rb +++ b/spec/system/journey_spec.rb @@ -35,25 +35,29 @@ describe 'District Admin', js: true do survey_items_for_measure_1A_i.each do |survey_item| SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do - survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, school: school, survey_item: survey_item, likert_score: 4) + survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, + school: school, survey_item: survey_item, likert_score: 4) end end survey_items_for_measure_2A_i.each do |survey_item| SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD.times do - survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, school: school, survey_item: survey_item, likert_score: 5) + survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, + school: school, survey_item: survey_item, likert_score: 5) end end survey_items_for_measure_4C_i.each do |survey_item| SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do - survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, school: school, survey_item: survey_item, likert_score: 1) + survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, + school: school, survey_item: survey_item, likert_score: 1) end end survey_items_for_subcategory.each do |survey_item| 200.times do - survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, school: school, survey_item: survey_item, likert_score: 4) + survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2020_21, + school: school, survey_item: survey_item, likert_score: 4) end end @@ -64,7 +68,7 @@ describe 'District Admin', js: true do page.driver.basic_authorize(username, password) visit '/welcome' - expect(page).to have_text("Teachers & Leadership") + expect(page).to have_text('Teachers & Leadership') go_to_school_overview_from_welcome_page(district, school) district_admin_sees_overview_content @@ -93,7 +97,7 @@ private def district_admin_sees_professional_qualifications expect(page).to have_text('Professional Qualifications') - expect(page).to have_css("[data-for-measure-id='1A-i'][width='8.26%'][x='60%']") + expect(page).to have_css("[data-for-measure-id='1A-i'][width='2.99%'][x='60%']") end def district_admin_sees_student_physical_safety diff --git a/spec/views/categories/show.html.erb_spec.rb b/spec/views/categories/show.html.erb_spec.rb index 0acf46dd..62546e10 100644 --- a/spec/views/categories/show.html.erb_spec.rb +++ b/spec/views/categories/show.html.erb_spec.rb @@ -8,21 +8,30 @@ describe 'categories/show.html.erb' do category = create(:category, name: 'Some Category', description: 'Some description of the category') category_presenter = CategoryPresenter.new(category: category) - subcategory1 = create(:subcategory, category: category, name: 'A subcategory', description: 'Some description of the subcategory') - subcategory2 = create(:subcategory_with_measures, category: category, name: 'Another subcategory', description: 'Another description of the subcategory') - - measure1 = create(:measure, subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) - survey_item1 = create(:student_survey_item, measure: measure1) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1) - - measure2 = create(:measure, name: 'The second measure name', description: 'The second measure description', subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) - student_survey_item = create(:student_survey_item, measure: measure2, prompt: "Some prompt for student data") - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item, academic_year: academic_year, school: school, likert_score: 5) - - teacher_survey_item = create(:teacher_survey_item, measure: measure2, prompt: "Some prompt for teacher data") - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item, academic_year: academic_year, school: school, likert_score: 3) - - admin_data_item = create(:admin_data_item, measure: measure2, description: "Some admin data item description") + subcategory1 = create(:subcategory, category: category, name: 'A subcategory', + description: 'Some description of the subcategory') + subcategory2 = create(:subcategory_with_measures, category: category, name: 'Another subcategory', + description: 'Another description of the subcategory') + + measure1 = create(:measure, subcategory: subcategory1) + survey_item1 = create(:student_survey_item, measure: measure1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, + approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item1, + academic_year: academic_year, school: school, likert_score: 1) + + measure2 = create(:measure, name: 'The second measure name', description: 'The second measure description', + subcategory: subcategory1) + student_survey_item = create(:student_survey_item, measure: measure2, prompt: 'Some prompt for student data', + watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, + survey_item: student_survey_item, academic_year: academic_year, school: school, likert_score: 5) + + teacher_survey_item = create(:teacher_survey_item, measure: measure2, prompt: 'Some prompt for teacher data') + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, + survey_item: teacher_survey_item, academic_year: academic_year, school: school, likert_score: 3) + + admin_data_item = create(:admin_data_item, measure: measure2, description: 'Some admin data item description', + watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) assign :category, category_presenter assign :categories, [category_presenter] diff --git a/spec/views/home/index.html.erb_spec.rb b/spec/views/home/index.html.erb_spec.rb index 6bb30217..dffd9a2e 100644 --- a/spec/views/home/index.html.erb_spec.rb +++ b/spec/views/home/index.html.erb_spec.rb @@ -12,5 +12,4 @@ describe 'home/index.html.erb' do it 'renders a dropdown with districts and a select a district prompt' do expect(subject.css('#district-dropdown option').count).to eq 3 end - end diff --git a/spec/views/legacy/categories/edit.html.erb_spec.rb b/spec/views/legacy/categories/edit.html.erb_spec.rb index 23d8fae3..214f5d60 100644 --- a/spec/views/legacy/categories/edit.html.erb_spec.rb +++ b/spec/views/legacy/categories/edit.html.erb_spec.rb @@ -1,31 +1,30 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/categories/edit", type: :view do + RSpec.describe 'legacy/categories/edit', type: :view do before(:each) do @category = assign(:category, Category.create!( - :name => "MyString", - :blurb => "MyString", - :description => "MyText", - :external_id => "MyString", - :parent_category_id => 1 - )) + name: 'MyString', + blurb: 'MyString', + description: 'MyText', + external_id: 'MyString', + parent_category_id: 1 + )) end - it "renders the edit category form" do + it 'renders the edit category form' do render - assert_select "form[action=?][method=?]", legacy_category_path(@category), "post" do + assert_select 'form[action=?][method=?]', legacy_category_path(@category), 'post' do + assert_select 'input#category_name[name=?]', 'category[name]' - assert_select "input#category_name[name=?]", "category[name]" + assert_select 'input#category_blurb[name=?]', 'category[blurb]' - assert_select "input#category_blurb[name=?]", "category[blurb]" + assert_select 'textarea#category_description[name=?]', 'category[description]' - assert_select "textarea#category_description[name=?]", "category[description]" + assert_select 'input#category_external_id[name=?]', 'category[external_id]' - assert_select "input#category_external_id[name=?]", "category[external_id]" - - assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" + assert_select 'input#category_parent_category_id[name=?]', 'category[parent_category_id]' end end end diff --git a/spec/views/legacy/categories/index.html.erb_spec.rb b/spec/views/legacy/categories/index.html.erb_spec.rb index a5d1bde3..888e169f 100644 --- a/spec/views/legacy/categories/index.html.erb_spec.rb +++ b/spec/views/legacy/categories/index.html.erb_spec.rb @@ -1,33 +1,33 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/categories/index", type: :view do + RSpec.describe 'legacy/categories/index', type: :view do before(:each) do assign(:categories, [ - Category.create!( - :name => "Name", - :blurb => "Blurb", - :description => "MyText", - :external_id => "External", - :parent_category_id => 2 - ), - Category.create!( - :name => "Name", - :blurb => "Blurb", - :description => "MyText", - :external_id => "External", - :parent_category_id => 2 - ) - ]) + Category.create!( + name: 'Name', + blurb: 'Blurb', + description: 'MyText', + external_id: 'External', + parent_category_id: 2 + ), + Category.create!( + name: 'Name', + blurb: 'Blurb', + description: 'MyText', + external_id: 'External', + parent_category_id: 2 + ) + ]) end - it "renders a list of categories" do - render(template: "legacy/categories/index") - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "Blurb".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "External".to_s, :count => 2 - assert_select "tr>td", :text => 2.to_s, :count => 2 + it 'renders a list of categories' do + render(template: 'legacy/categories/index') + assert_select 'tr>td', text: 'Name'.to_s, count: 2 + assert_select 'tr>td', text: 'Blurb'.to_s, count: 2 + assert_select 'tr>td', text: 'MyText'.to_s, count: 2 + assert_select 'tr>td', text: 'External'.to_s, count: 2 + assert_select 'tr>td', text: 2.to_s, count: 2 end end end diff --git a/spec/views/legacy/categories/new.html.erb_spec.rb b/spec/views/legacy/categories/new.html.erb_spec.rb index a380c6a2..ea16f87b 100644 --- a/spec/views/legacy/categories/new.html.erb_spec.rb +++ b/spec/views/legacy/categories/new.html.erb_spec.rb @@ -1,31 +1,30 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/categories/new", type: :view do + RSpec.describe 'legacy/categories/new', type: :view do before(:each) do assign(:category, Category.new( - :name => "MyString", - :blurb => "MyString", - :description => "MyText", - :external_id => "MyString", - :parent_category_id => 1 - )) + name: 'MyString', + blurb: 'MyString', + description: 'MyText', + external_id: 'MyString', + parent_category_id: 1 + )) end - it "renders new category form" do + it 'renders new category form' do render - assert_select "form[action=?][method=?]", legacy_categories_path, "post" do + assert_select 'form[action=?][method=?]', legacy_categories_path, 'post' do + assert_select 'input#category_name[name=?]', 'category[name]' - assert_select "input#category_name[name=?]", "category[name]" + assert_select 'input#category_blurb[name=?]', 'category[blurb]' - assert_select "input#category_blurb[name=?]", "category[blurb]" + assert_select 'textarea#category_description[name=?]', 'category[description]' - assert_select "textarea#category_description[name=?]", "category[description]" + assert_select 'input#category_external_id[name=?]', 'category[external_id]' - assert_select "input#category_external_id[name=?]", "category[external_id]" - - assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" + assert_select 'input#category_parent_category_id[name=?]', 'category[parent_category_id]' end end end diff --git a/spec/views/legacy/categories/show.html.erb_spec.rb b/spec/views/legacy/categories/show.html.erb_spec.rb index 042d7fc0..4d28e48b 100644 --- a/spec/views/legacy/categories/show.html.erb_spec.rb +++ b/spec/views/legacy/categories/show.html.erb_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -RSpec.describe "categories/show", type: :view do +RSpec.describe 'categories/show', type: :view do before(:each) do @school = assign(:school, School.create(name: 'School')) @category = assign(:category, Category.create!( - :name => "Category", - :description => "MyText", - :parent_category => Category.create(name: 'Teachers And The Teaching Environment') - )) + name: 'Category', + description: 'MyText', + parent_category: Category.create(name: 'Teachers And The Teaching Environment') + )) @school_category = assign(:school_category, SchoolCategory.create(school: @school, category: @category)) end - xit "renders attributes in

" do + xit 'renders attributes in

' do render expect(rendered).to match(/Category/) expect(rendered).to match(/MyText/) diff --git a/spec/views/legacy/districts/edit.html.erb_spec.rb b/spec/views/legacy/districts/edit.html.erb_spec.rb index fe65430b..7a0cbdf8 100644 --- a/spec/views/legacy/districts/edit.html.erb_spec.rb +++ b/spec/views/legacy/districts/edit.html.erb_spec.rb @@ -1,22 +1,21 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/districts/edit", type: :view do + RSpec.describe 'legacy/districts/edit', type: :view do before(:each) do @district = assign(:district, Legacy::District.create!( - :name => "MyString", - :state_id => 1 - )) + name: 'MyString', + state_id: 1 + )) end - it "renders the edit district form" do + it 'renders the edit district form' do render - assert_select "form[action=?][method=?]", district_path(@district), "post" do + assert_select 'form[action=?][method=?]', district_path(@district), 'post' do + assert_select 'input#district_name[name=?]', 'district[name]' - assert_select "input#district_name[name=?]", "district[name]" - - assert_select "input#district_state_id[name=?]", "district[state_id]" + assert_select 'input#district_state_id[name=?]', 'district[state_id]' end end end diff --git a/spec/views/legacy/districts/index.html.erb_spec.rb b/spec/views/legacy/districts/index.html.erb_spec.rb index 082c6656..2396d6ae 100644 --- a/spec/views/legacy/districts/index.html.erb_spec.rb +++ b/spec/views/legacy/districts/index.html.erb_spec.rb @@ -1,22 +1,22 @@ require 'rails_helper' -RSpec.describe "districts/index", type: :view do +RSpec.describe 'districts/index', type: :view do before(:each) do assign(:districts, [ - District.create!( - :name => "Name", - :state_id => 2 - ), - District.create!( - :name => "Name", - :state_id => 2 - ) - ]) + District.create!( + name: 'Name', + state_id: 2 + ), + District.create!( + name: 'Name', + state_id: 2 + ) + ]) end - xit "renders a list of districts" do + xit 'renders a list of districts' do render - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => 2.to_s, :count => 2 + assert_select 'tr>td', text: 'Name'.to_s, count: 2 + assert_select 'tr>td', text: 2.to_s, count: 2 end end diff --git a/spec/views/legacy/districts/new.html.erb_spec.rb b/spec/views/legacy/districts/new.html.erb_spec.rb index 2046dc25..de1e9fe0 100644 --- a/spec/views/legacy/districts/new.html.erb_spec.rb +++ b/spec/views/legacy/districts/new.html.erb_spec.rb @@ -1,22 +1,21 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/districts/new", type: :view do + RSpec.describe 'legacy/districts/new', type: :view do before(:each) do assign(:district, Legacy::District.new( - :name => "MyString", - :state_id => 1 - )) + name: 'MyString', + state_id: 1 + )) end - it "renders new district form" do + it 'renders new district form' do render - assert_select "form[action=?][method=?]", legacy_districts_path, "post" do + assert_select 'form[action=?][method=?]', legacy_districts_path, 'post' do + assert_select 'input#district_name[name=?]', 'district[name]' - assert_select "input#district_name[name=?]", "district[name]" - - assert_select "input#district_state_id[name=?]", "district[state_id]" + assert_select 'input#district_state_id[name=?]', 'district[state_id]' end end end diff --git a/spec/views/legacy/districts/show.html.erb_spec.rb b/spec/views/legacy/districts/show.html.erb_spec.rb index b45c846a..2fb18e9d 100644 --- a/spec/views/legacy/districts/show.html.erb_spec.rb +++ b/spec/views/legacy/districts/show.html.erb_spec.rb @@ -1,20 +1,20 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/districts/show", type: :view do + RSpec.describe 'legacy/districts/show', type: :view do before(:each) do @district = assign(:district, Legacy::District.create!( - :name => "Milford", - :state_id => 2 - )) + name: 'Milford', + state_id: 2 + )) schools = [] 3.times { |i| schools << @district.schools.create!(name: "School #{i}") } @schools = assign(:schools, schools) end - it "renders attributes in

" do - render(template: "legacy/districts/show") + it 'renders attributes in

' do + render(template: 'legacy/districts/show') expect(rendered).to match(/Milford/) expect(rendered).to match(/2/) 3.times do |i| diff --git a/spec/views/legacy/question_lists/edit.html.erb_spec.rb b/spec/views/legacy/question_lists/edit.html.erb_spec.rb index 46cd59ff..d799ddc7 100644 --- a/spec/views/legacy/question_lists/edit.html.erb_spec.rb +++ b/spec/views/legacy/question_lists/edit.html.erb_spec.rb @@ -1,25 +1,24 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/question_lists/edit", type: :view do + RSpec.describe 'legacy/question_lists/edit', type: :view do before(:each) do @question_list = assign(:question_list, QuestionList.create!( - :name => "MyString", - :description => "MyText", - :question_ids => "MyText" - )) + name: 'MyString', + description: 'MyText', + question_ids: 'MyText' + )) end - it "renders the edit question_list form" do + it 'renders the edit question_list form' do render - assert_select "form[action=?][method=?]", legacy_question_list_path(@question_list), "post" do + assert_select 'form[action=?][method=?]', legacy_question_list_path(@question_list), 'post' do + assert_select 'input#question_list_name[name=?]', 'question_list[name]' - assert_select "input#question_list_name[name=?]", "question_list[name]" + assert_select 'textarea#question_list_description[name=?]', 'question_list[description]' - assert_select "textarea#question_list_description[name=?]", "question_list[description]" - - assert_select "input[name=?]", "question_list[question_id_array][]" + assert_select 'input[name=?]', 'question_list[question_id_array][]' end end end diff --git a/spec/views/legacy/question_lists/index.html.erb_spec.rb b/spec/views/legacy/question_lists/index.html.erb_spec.rb index 72da37f3..c88cbe84 100644 --- a/spec/views/legacy/question_lists/index.html.erb_spec.rb +++ b/spec/views/legacy/question_lists/index.html.erb_spec.rb @@ -1,28 +1,28 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/question_lists/index", type: :view do + RSpec.describe 'legacy/question_lists/index', type: :view do before(:each) do assign(:question_lists, [ - QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "1,2,3" - ), - QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "2,3,4" - ) - ]) + QuestionList.create!( + name: 'Name', + description: 'MyText', + question_ids: '1,2,3' + ), + QuestionList.create!( + name: 'Name', + description: 'MyText', + question_ids: '2,3,4' + ) + ]) end - it "renders a list of question_lists" do - render(template: "legacy/question_lists/index") - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 - assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 + it 'renders a list of question_lists' do + render(template: 'legacy/question_lists/index') + assert_select 'tr>td', text: 'Name'.to_s, count: 2 + assert_select 'tr>td', text: 'MyText'.to_s, count: 2 + assert_select 'tr>td', text: '1,2,3'.to_s, count: 1 + assert_select 'tr>td', text: '2,3,4'.to_s, count: 1 end end end diff --git a/spec/views/legacy/question_lists/new.html.erb_spec.rb b/spec/views/legacy/question_lists/new.html.erb_spec.rb index 2bb76143..2c3f99da 100644 --- a/spec/views/legacy/question_lists/new.html.erb_spec.rb +++ b/spec/views/legacy/question_lists/new.html.erb_spec.rb @@ -1,25 +1,24 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/question_lists/new", type: :view do + RSpec.describe 'legacy/question_lists/new', type: :view do before(:each) do assign(:question_list, QuestionList.new( - :name => "MyString", - :description => "MyText", - :question_ids => "MyText" - )) + name: 'MyString', + description: 'MyText', + question_ids: 'MyText' + )) end - it "renders new question_list form" do + it 'renders new question_list form' do render - assert_select "form[action=?][method=?]", legacy_question_lists_path, "post" do + assert_select 'form[action=?][method=?]', legacy_question_lists_path, 'post' do + assert_select 'input#question_list_name[name=?]', 'question_list[name]' - assert_select "input#question_list_name[name=?]", "question_list[name]" + assert_select 'textarea#question_list_description[name=?]', 'question_list[description]' - assert_select "textarea#question_list_description[name=?]", "question_list[description]" - - assert_select "input[name=?]", "question_list[question_id_array][]" + assert_select 'input[name=?]', 'question_list[question_id_array][]' end end end diff --git a/spec/views/legacy/question_lists/show.html.erb_spec.rb b/spec/views/legacy/question_lists/show.html.erb_spec.rb index 37aae354..1e0594fd 100644 --- a/spec/views/legacy/question_lists/show.html.erb_spec.rb +++ b/spec/views/legacy/question_lists/show.html.erb_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/question_lists/show", type: :view do + RSpec.describe 'legacy/question_lists/show', type: :view do before(:each) do @question_list = assign(:question_list, QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "MyText" - )) + name: 'Name', + description: 'MyText', + question_ids: 'MyText' + )) end - it "renders attributes in

" do - render(template: "legacy/question_lists/show") + it 'renders attributes in

' do + render(template: 'legacy/question_lists/show') expect(rendered).to match(/Name/) expect(rendered).to match(/MyText/) expect(rendered).to match(/MyText/) diff --git a/spec/views/legacy/questions/edit.html.erb_spec.rb b/spec/views/legacy/questions/edit.html.erb_spec.rb index b87ba921..a859aac1 100644 --- a/spec/views/legacy/questions/edit.html.erb_spec.rb +++ b/spec/views/legacy/questions/edit.html.erb_spec.rb @@ -1,37 +1,36 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/questions/edit", type: :view do + RSpec.describe 'legacy/questions/edit', type: :view do before(:each) do @question = assign(:question, Question.create!( - :text => "MyString", - :option1 => "MyString", - :option2 => "MyString", - :option3 => "MyString", - :option4 => "MyString", - :option5 => "MyString", - :category_id => 1 - )) + text: 'MyString', + option1: 'MyString', + option2: 'MyString', + option3: 'MyString', + option4: 'MyString', + option5: 'MyString', + category_id: 1 + )) end - it "renders the edit question form" do + it 'renders the edit question form' do render - assert_select "form[action=?][method=?]", legacy_question_path(@question), "post" do + assert_select 'form[action=?][method=?]', legacy_question_path(@question), 'post' do + assert_select 'input#question_text[name=?]', 'question[text]' - assert_select "input#question_text[name=?]", "question[text]" + assert_select 'input#question_option1[name=?]', 'question[option1]' - assert_select "input#question_option1[name=?]", "question[option1]" + assert_select 'input#question_option2[name=?]', 'question[option2]' - assert_select "input#question_option2[name=?]", "question[option2]" + assert_select 'input#question_option3[name=?]', 'question[option3]' - assert_select "input#question_option3[name=?]", "question[option3]" + assert_select 'input#question_option4[name=?]', 'question[option4]' - assert_select "input#question_option4[name=?]", "question[option4]" + assert_select 'input#question_option5[name=?]', 'question[option5]' - assert_select "input#question_option5[name=?]", "question[option5]" - - assert_select "input#question_category_id[name=?]", "question[category_id]" + assert_select 'input#question_category_id[name=?]', 'question[category_id]' end end end diff --git a/spec/views/legacy/questions/index.html.erb_spec.rb b/spec/views/legacy/questions/index.html.erb_spec.rb index 3de2120b..75479b93 100644 --- a/spec/views/legacy/questions/index.html.erb_spec.rb +++ b/spec/views/legacy/questions/index.html.erb_spec.rb @@ -1,40 +1,40 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/questions/index", type: :view do + RSpec.describe 'legacy/questions/index', type: :view do before(:each) do assign(:questions, [ - Question.create!( - :text => "Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create(name: "Category 1") - ), - Question.create!( - :text => "Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create(name: "Category 2") - ) - ]) + Question.create!( + text: 'Text', + option1: 'Option1', + option2: 'Option2', + option3: 'Option3', + option4: 'Option4', + option5: 'Option5', + category: Category.create(name: 'Category 1') + ), + Question.create!( + text: 'Text', + option1: 'Option1', + option2: 'Option2', + option3: 'Option3', + option4: 'Option4', + option5: 'Option5', + category: Category.create(name: 'Category 2') + ) + ]) end - it "renders a list of questions" do - render(template: "legacy/questions/index") - assert_select "tr>td", :text => "Text".to_s, :count => 2 - assert_select "tr>td", :text => "Option1".to_s, :count => 2 - assert_select "tr>td", :text => "Option2".to_s, :count => 2 - assert_select "tr>td", :text => "Option3".to_s, :count => 2 - assert_select "tr>td", :text => "Option4".to_s, :count => 2 - assert_select "tr>td", :text => "Option5".to_s, :count => 2 - assert_select "tr>td", :text => "Category 1", :count => 1 - assert_select "tr>td", :text => "Category 2", :count => 1 + it 'renders a list of questions' do + render(template: 'legacy/questions/index') + assert_select 'tr>td', text: 'Text'.to_s, count: 2 + assert_select 'tr>td', text: 'Option1'.to_s, count: 2 + assert_select 'tr>td', text: 'Option2'.to_s, count: 2 + assert_select 'tr>td', text: 'Option3'.to_s, count: 2 + assert_select 'tr>td', text: 'Option4'.to_s, count: 2 + assert_select 'tr>td', text: 'Option5'.to_s, count: 2 + assert_select 'tr>td', text: 'Category 1', count: 1 + assert_select 'tr>td', text: 'Category 2', count: 1 end end end diff --git a/spec/views/legacy/questions/new.html.erb_spec.rb b/spec/views/legacy/questions/new.html.erb_spec.rb index 0ff3055d..75a3a9f4 100644 --- a/spec/views/legacy/questions/new.html.erb_spec.rb +++ b/spec/views/legacy/questions/new.html.erb_spec.rb @@ -1,37 +1,36 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/questions/new", type: :view do + RSpec.describe 'legacy/questions/new', type: :view do before(:each) do assign(:question, Question.new( - :text => "MyString", - :option1 => "MyString", - :option2 => "MyString", - :option3 => "MyString", - :option4 => "MyString", - :option5 => "MyString", - :category_id => 1 - )) + text: 'MyString', + option1: 'MyString', + option2: 'MyString', + option3: 'MyString', + option4: 'MyString', + option5: 'MyString', + category_id: 1 + )) end - it "renders new question form" do + it 'renders new question form' do render - assert_select "form[action=?][method=?]", legacy_questions_path, "post" do + assert_select 'form[action=?][method=?]', legacy_questions_path, 'post' do + assert_select 'input#question_text[name=?]', 'question[text]' - assert_select "input#question_text[name=?]", "question[text]" + assert_select 'input#question_option1[name=?]', 'question[option1]' - assert_select "input#question_option1[name=?]", "question[option1]" + assert_select 'input#question_option2[name=?]', 'question[option2]' - assert_select "input#question_option2[name=?]", "question[option2]" + assert_select 'input#question_option3[name=?]', 'question[option3]' - assert_select "input#question_option3[name=?]", "question[option3]" + assert_select 'input#question_option4[name=?]', 'question[option4]' - assert_select "input#question_option4[name=?]", "question[option4]" + assert_select 'input#question_option5[name=?]', 'question[option5]' - assert_select "input#question_option5[name=?]", "question[option5]" - - assert_select "input#question_category_id[name=?]", "question[category_id]" + assert_select 'input#question_category_id[name=?]', 'question[category_id]' end end end diff --git a/spec/views/legacy/questions/show.html.erb_spec.rb b/spec/views/legacy/questions/show.html.erb_spec.rb index b0cf501f..4c3eaf66 100644 --- a/spec/views/legacy/questions/show.html.erb_spec.rb +++ b/spec/views/legacy/questions/show.html.erb_spec.rb @@ -1,22 +1,22 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/questions/show", type: :view do + RSpec.describe 'legacy/questions/show', type: :view do before(:each) do @school = assign(:school, School.create!(name: 'School')) @question = assign(:question, Question.create!( - :text => "Question Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create!(name: 'Category Name') - )) + text: 'Question Text', + option1: 'Option1', + option2: 'Option2', + option3: 'Option3', + option4: 'Option4', + option5: 'Option5', + category: Category.create!(name: 'Category Name') + )) end - it "renders attributes in

" do - render(template: "legacy/questions/show") + it 'renders attributes in

' do + render(template: 'legacy/questions/show') expect(rendered).to match(/School/) expect(rendered).to match(/Question Text/) expect(rendered).to match(/Option1/) diff --git a/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb b/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb index 07ea9b63..1d12fadb 100644 --- a/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb +++ b/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb @@ -1,30 +1,30 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipient_lists/edit", type: :view do + RSpec.describe 'legacy/recipient_lists/edit', type: :view do before(:each) do @school = assign(:school, School.create!( - :name => "School" - )) + name: 'School' + )) @recipient_list = assign(:recipient_list, RecipientList.create!( - :name => "MyString", - :description => "MyText", - :recipient_ids => "1,2,3", - :school_id => @school.id - )) + name: 'MyString', + description: 'MyText', + recipient_ids: '1,2,3', + school_id: @school.id + )) end - it "renders the edit recipient_list form" do + it 'renders the edit recipient_list form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_list_path(@school, @recipient_list), "post" do + assert_select 'form[action=?][method=?]', legacy_school_legacy_recipient_list_path(@school, @recipient_list), + 'post' do + assert_select 'input#recipient_list_name[name=?]', 'recipient_list[name]' - assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" + assert_select 'textarea#recipient_list_description[name=?]', 'recipient_list[description]' - assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" - - assert_select "input[name=?]", "recipient_list[recipient_id_array][]" + assert_select 'input[name=?]', 'recipient_list[recipient_id_array][]' end end end diff --git a/spec/views/legacy/recipient_lists/index.html.erb_spec.rb b/spec/views/legacy/recipient_lists/index.html.erb_spec.rb index 2c1544fe..eec0b726 100644 --- a/spec/views/legacy/recipient_lists/index.html.erb_spec.rb +++ b/spec/views/legacy/recipient_lists/index.html.erb_spec.rb @@ -1,32 +1,32 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipient_lists/index", type: :view do + RSpec.describe 'legacy/recipient_lists/index', type: :view do before(:each) do @school = assign(:school, School.create!(name: 'School')) assign(:recipient_lists, [ - RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_ids => "1,2,3", - :school_id => @school.id - ), - RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_ids => "2,3,4", - :school_id => @school.id - ) - ]) + RecipientList.create!( + name: 'Name', + description: 'MyText', + recipient_ids: '1,2,3', + school_id: @school.id + ), + RecipientList.create!( + name: 'Name', + description: 'MyText', + recipient_ids: '2,3,4', + school_id: @school.id + ) + ]) end - it "renders a list of recipient_lists" do + it 'renders a list of recipient_lists' do render - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 - assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 + assert_select 'tr>td', text: 'Name'.to_s, count: 2 + assert_select 'tr>td', text: 'MyText'.to_s, count: 2 + assert_select 'tr>td', text: '1,2,3'.to_s, count: 1 + assert_select 'tr>td', text: '2,3,4'.to_s, count: 1 end end end diff --git a/spec/views/legacy/recipient_lists/new.html.erb_spec.rb b/spec/views/legacy/recipient_lists/new.html.erb_spec.rb index 85cbb74f..d93a66db 100644 --- a/spec/views/legacy/recipient_lists/new.html.erb_spec.rb +++ b/spec/views/legacy/recipient_lists/new.html.erb_spec.rb @@ -1,27 +1,28 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipient_lists/new", type: :view do + RSpec.describe 'legacy/recipient_lists/new', type: :view do before(:each) do @school = assign(:school, School.create!(name: 'School')) @recipient_list = assign(:recipient_list, RecipientList.new( - :name => "MyString", - :description => "MyText", - :recipient_ids => "MyText", - :school_id => @school.id - )) + name: 'MyString', + description: 'MyText', + recipient_ids: 'MyText', + school_id: @school.id + )) end - it "renders new recipient_list form" do + it 'renders new recipient_list form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_lists_path(@school, @recipient_list), "post" do - assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" + assert_select 'form[action=?][method=?]', legacy_school_legacy_recipient_lists_path(@school, @recipient_list), + 'post' do + assert_select 'input#recipient_list_name[name=?]', 'recipient_list[name]' - assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" + assert_select 'textarea#recipient_list_description[name=?]', 'recipient_list[description]' - assert_select "input[name=?]", "recipient_list[recipient_id_array][]" + assert_select 'input[name=?]', 'recipient_list[recipient_id_array][]' end end end diff --git a/spec/views/legacy/recipient_lists/show.html.erb_spec.rb b/spec/views/legacy/recipient_lists/show.html.erb_spec.rb index 409b145a..a9f01d42 100644 --- a/spec/views/legacy/recipient_lists/show.html.erb_spec.rb +++ b/spec/views/legacy/recipient_lists/show.html.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipient_lists/show", type: :view do + RSpec.describe 'legacy/recipient_lists/show', type: :view do before(:each) do @school = assign(:school, School.create!(name: 'School')) @@ -10,14 +10,14 @@ module Legacy end @recipient_list = assign(:recipient_list, RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_id_array => recipients.map(&:id), - :school_id => @school.id - )) + name: 'Name', + description: 'MyText', + recipient_id_array: recipients.map(&:id), + school_id: @school.id + )) end - it "renders attributes in

" do + it 'renders attributes in

' do render expect(rendered).to match(/Name/) expect(rendered).to match(/MyText/) diff --git a/spec/views/legacy/recipients/edit.html.erb_spec.rb b/spec/views/legacy/recipients/edit.html.erb_spec.rb index 0ac34507..659944f3 100644 --- a/spec/views/legacy/recipients/edit.html.erb_spec.rb +++ b/spec/views/legacy/recipients/edit.html.erb_spec.rb @@ -1,44 +1,42 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipients/edit", type: :view do + RSpec.describe 'legacy/recipients/edit', type: :view do before(:each) do - @school = assign(:recipient, School.create!(# TODO does this need to be :school? - :name => "School" - )) + @school = assign(:recipient, School.create!( # TODO: does this need to be :school? + name: 'School' + )) @recipient = assign(:recipient, Recipient.create!( - :name => "MyString", - :phone => "MyString", - :gender => "MyString", - :race => "MyString", - :ethnicity => "MyString", - :home_language_id => 1, - :income => "MyString", - :opted_out => false, - :school_id => @school.id - )) + name: 'MyString', + phone: 'MyString', + gender: 'MyString', + race: 'MyString', + ethnicity: 'MyString', + home_language_id: 1, + income: 'MyString', + opted_out: false, + school_id: @school.id + )) end - it "renders the edit recipient form" do + it 'renders the edit recipient form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_path(@school, @recipient), "post" do + assert_select 'form[action=?][method=?]', legacy_school_legacy_recipient_path(@school, @recipient), 'post' do + assert_select 'input#recipient_name[name=?]', 'recipient[name]' - assert_select "input#recipient_name[name=?]", "recipient[name]" + assert_select 'input#recipient_phone[name=?]', 'recipient[phone]' - assert_select "input#recipient_phone[name=?]", "recipient[phone]" + assert_select 'input#recipient_gender[name=?]', 'recipient[gender]' - assert_select "input#recipient_gender[name=?]", "recipient[gender]" + assert_select 'input#recipient_race[name=?]', 'recipient[race]' - assert_select "input#recipient_race[name=?]", "recipient[race]" + assert_select 'input#recipient_ethnicity[name=?]', 'recipient[ethnicity]' - assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" - - assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" - - assert_select "input#recipient_income[name=?]", "recipient[income]" + assert_select 'input#recipient_home_language_id[name=?]', 'recipient[home_language_id]' + assert_select 'input#recipient_income[name=?]', 'recipient[income]' end end end diff --git a/spec/views/legacy/recipients/index.html.erb_spec.rb b/spec/views/legacy/recipients/index.html.erb_spec.rb index 171328af..690af25d 100644 --- a/spec/views/legacy/recipients/index.html.erb_spec.rb +++ b/spec/views/legacy/recipients/index.html.erb_spec.rb @@ -1,47 +1,47 @@ require 'rails_helper' -RSpec.describe "legacy/recipients/index", type: :view do +RSpec.describe 'legacy/recipients/index', type: :view do before(:each) do @school = assign(:school, Legacy::School.create!( - name: 'School' - )) + name: 'School' + )) assign(:recipients, [ - Legacy::Recipient.create!( - :name => "Name", - :phone => "Phone", - :gender => "Gender", - :race => "Race", - :ethnicity => "Ethnicity", - :home_language_id => 2, - :income => "Income", - :opted_out => false, - :school_id => @school.id - ), - Legacy::Recipient.create!( - :name => "Name", - :phone => "Phone", - :gender => "Gender", - :race => "Race", - :ethnicity => "Ethnicity", - :home_language_id => 2, - :income => "Income", - :opted_out => false, - :school_id => @school.id - ) - ]) + Legacy::Recipient.create!( + name: 'Name', + phone: 'Phone', + gender: 'Gender', + race: 'Race', + ethnicity: 'Ethnicity', + home_language_id: 2, + income: 'Income', + opted_out: false, + school_id: @school.id + ), + Legacy::Recipient.create!( + name: 'Name', + phone: 'Phone', + gender: 'Gender', + race: 'Race', + ethnicity: 'Ethnicity', + home_language_id: 2, + income: 'Income', + opted_out: false, + school_id: @school.id + ) + ]) end - it "renders a list of recipients" do - render(template: "legacy/recipients/index") - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "Phone".to_s, :count => 2 - assert_select "tr>td", :text => "Gender".to_s, :count => 2 - assert_select "tr>td", :text => "Race".to_s, :count => 2 - assert_select "tr>td", :text => "Ethnicity".to_s, :count => 2 - assert_select "tr>td", :text => 2.to_s, :count => 2 - assert_select "tr>td", :text => "Income".to_s, :count => 2 - assert_select "tr>td", :text => false.to_s, :count => 2 - assert_select "tr>td", :text => @school.id.to_s, :count => 2 + it 'renders a list of recipients' do + render(template: 'legacy/recipients/index') + assert_select 'tr>td', text: 'Name'.to_s, count: 2 + assert_select 'tr>td', text: 'Phone'.to_s, count: 2 + assert_select 'tr>td', text: 'Gender'.to_s, count: 2 + assert_select 'tr>td', text: 'Race'.to_s, count: 2 + assert_select 'tr>td', text: 'Ethnicity'.to_s, count: 2 + assert_select 'tr>td', text: 2.to_s, count: 2 + assert_select 'tr>td', text: 'Income'.to_s, count: 2 + assert_select 'tr>td', text: false.to_s, count: 2 + assert_select 'tr>td', text: @school.id.to_s, count: 2 end end diff --git a/spec/views/legacy/recipients/new.html.erb_spec.rb b/spec/views/legacy/recipients/new.html.erb_spec.rb index 2b566875..c2921980 100644 --- a/spec/views/legacy/recipients/new.html.erb_spec.rb +++ b/spec/views/legacy/recipients/new.html.erb_spec.rb @@ -1,44 +1,42 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/recipients/new", type: :view do + RSpec.describe 'legacy/recipients/new', type: :view do before(:each) do @school = assign(:school, School.create!( - name: 'School' - )) + name: 'School' + )) @recipient = assign(:recipient, Recipient.new( - :name => "MyString", - :phone => "MyString", - :gender => "MyString", - :race => "MyString", - :ethnicity => "MyString", - :home_language_id => 1, - :income => "MyString", - :opted_out => false, - :school_id => @school.to_param - )) + name: 'MyString', + phone: 'MyString', + gender: 'MyString', + race: 'MyString', + ethnicity: 'MyString', + home_language_id: 1, + income: 'MyString', + opted_out: false, + school_id: @school.to_param + )) end - it "renders new recipient form" do + it 'renders new recipient form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_recipients_path(@school, @recipient), "post" do + assert_select 'form[action=?][method=?]', legacy_school_legacy_recipients_path(@school, @recipient), 'post' do + assert_select 'input#recipient_name[name=?]', 'recipient[name]' - assert_select "input#recipient_name[name=?]", "recipient[name]" + assert_select 'input#recipient_phone[name=?]', 'recipient[phone]' - assert_select "input#recipient_phone[name=?]", "recipient[phone]" + assert_select 'input#recipient_gender[name=?]', 'recipient[gender]' - assert_select "input#recipient_gender[name=?]", "recipient[gender]" + assert_select 'input#recipient_race[name=?]', 'recipient[race]' - assert_select "input#recipient_race[name=?]", "recipient[race]" + assert_select 'input#recipient_ethnicity[name=?]', 'recipient[ethnicity]' - assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" - - assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" - - assert_select "input#recipient_income[name=?]", "recipient[income]" + assert_select 'input#recipient_home_language_id[name=?]', 'recipient[home_language_id]' + assert_select 'input#recipient_income[name=?]', 'recipient[income]' end end end diff --git a/spec/views/legacy/recipients/show.html.erb_spec.rb b/spec/views/legacy/recipients/show.html.erb_spec.rb index 7ef6c30b..eb57925c 100644 --- a/spec/views/legacy/recipients/show.html.erb_spec.rb +++ b/spec/views/legacy/recipients/show.html.erb_spec.rb @@ -1,25 +1,25 @@ require 'rails_helper' -RSpec.describe "legacy/recipients/show", type: :view do +RSpec.describe 'legacy/recipients/show', type: :view do before(:each) do @school = assign(:school, Legacy::School.create!( - name: 'School' - )) + name: 'School' + )) @recipient = assign(:recipient, Legacy::Recipient.create!( - :name => "Name", - :phone => "Phone", - :gender => "Gender", - :race => "Race", - :ethnicity => "Ethnicity", - :home_language_id => 2, - :income => "Income", - :opted_out => false, - :school_id => @school.to_param - )) + name: 'Name', + phone: 'Phone', + gender: 'Gender', + race: 'Race', + ethnicity: 'Ethnicity', + home_language_id: 2, + income: 'Income', + opted_out: false, + school_id: @school.to_param + )) end - it "renders attributes in

" do + it 'renders attributes in

' do render expect(rendered).to match(/Name/) expect(rendered).to match(/Phone/) diff --git a/spec/views/legacy/schedules/edit.html.erb_spec.rb b/spec/views/legacy/schedules/edit.html.erb_spec.rb index ddadb10f..04dc35ab 100644 --- a/spec/views/legacy/schedules/edit.html.erb_spec.rb +++ b/spec/views/legacy/schedules/edit.html.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/schedules/edit", type: :view do + RSpec.describe 'legacy/schedules/edit', type: :view do before(:each) do question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) @@ -10,35 +10,34 @@ module Legacy recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) @schedule = assign(:schedule, Schedule.create!( - :name => "MyString", - :description => "MyText", - :school_id => @school.id, - :frequency_hours => 1, - :active => false, - :random => false, - :recipient_list_id => recipient_list.id, - :question_list_id => question_list.id - )) + name: 'MyString', + description: 'MyText', + school_id: @school.id, + frequency_hours: 1, + active: false, + random: false, + recipient_list_id: recipient_list.id, + question_list_id: question_list.id + )) end - it "renders the edit schedule form" do + it 'renders the edit schedule form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_schedule_path(@school, @schedule), "post" do + assert_select 'form[action=?][method=?]', legacy_school_legacy_schedule_path(@school, @schedule), 'post' do + assert_select 'input#schedule_name[name=?]', 'schedule[name]' - assert_select "input#schedule_name[name=?]", "schedule[name]" + assert_select 'textarea#schedule_description[name=?]', 'schedule[description]' - assert_select "textarea#schedule_description[name=?]", "schedule[description]" + assert_select 'select[name=?]', 'schedule[frequency_hours]' - assert_select "select[name=?]", "schedule[frequency_hours]" + assert_select 'input#schedule_active[name=?]', 'schedule[active]' - assert_select "input#schedule_active[name=?]", "schedule[active]" + assert_select 'input#schedule_random[name=?]', 'schedule[random]' - assert_select "input#schedule_random[name=?]", "schedule[random]" + assert_select 'select[name=?]', 'schedule[recipient_list_id]' - assert_select "select[name=?]", "schedule[recipient_list_id]" - - assert_select "select[name=?]", "schedule[question_list_id]" + assert_select 'select[name=?]', 'schedule[question_list_id]' end end end diff --git a/spec/views/legacy/schedules/new.html.erb_spec.rb b/spec/views/legacy/schedules/new.html.erb_spec.rb index fe65e7d4..8cbdf2bf 100644 --- a/spec/views/legacy/schedules/new.html.erb_spec.rb +++ b/spec/views/legacy/schedules/new.html.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/schedules/new", type: :view do + RSpec.describe 'legacy/schedules/new', type: :view do before(:each) do question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) @@ -10,35 +10,34 @@ module Legacy recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) assign(:schedule, Schedule.new( - :name => "MyString", - :description => "MyText", - :school => @school, - :frequency_hours => 1, - :active => false, - :random => false, - :recipient_list => @recipient_list, - :question_list => @question_list - )) + name: 'MyString', + description: 'MyText', + school: @school, + frequency_hours: 1, + active: false, + random: false, + recipient_list: @recipient_list, + question_list: @question_list + )) end - it "renders new schedule form" do + it 'renders new schedule form' do render - assert_select "form[action=?][method=?]", legacy_school_legacy_schedules_path(@school), "post" do + assert_select 'form[action=?][method=?]', legacy_school_legacy_schedules_path(@school), 'post' do + assert_select 'input#schedule_name[name=?]', 'schedule[name]' - assert_select "input#schedule_name[name=?]", "schedule[name]" + assert_select 'textarea#schedule_description[name=?]', 'schedule[description]' - assert_select "textarea#schedule_description[name=?]", "schedule[description]" + assert_select 'select[name=?]', 'schedule[frequency_hours]' - assert_select "select[name=?]", "schedule[frequency_hours]" + assert_select 'input#schedule_active[name=?]', 'schedule[active]' - assert_select "input#schedule_active[name=?]", "schedule[active]" + assert_select 'input#schedule_random[name=?]', 'schedule[random]' - assert_select "input#schedule_random[name=?]", "schedule[random]" + assert_select 'select[name=?]', 'schedule[recipient_list_id]' - assert_select "select[name=?]", "schedule[recipient_list_id]" - - assert_select "select[name=?]", "schedule[question_list_id]" + assert_select 'select[name=?]', 'schedule[question_list_id]' end end end diff --git a/spec/views/legacy/schedules/show.html.erb_spec.rb b/spec/views/legacy/schedules/show.html.erb_spec.rb index 4667ff5e..4711ab93 100644 --- a/spec/views/legacy/schedules/show.html.erb_spec.rb +++ b/spec/views/legacy/schedules/show.html.erb_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/schedules/show", type: :view do + RSpec.describe 'legacy/schedules/show', type: :view do before(:each) do @question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) @@ -10,18 +10,18 @@ module Legacy @recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) @schedule = assign(:schedule, Schedule.create!( - :name => "Name", - :description => "MyText", - :school => @school, - :frequency_hours => 2 * 24 * 7, - :active => false, - :random => false, - :recipient_list => @recipient_list, - :question_list => @question_list - )) + name: 'Name', + description: 'MyText', + school: @school, + frequency_hours: 2 * 24 * 7, + active: false, + random: false, + recipient_list: @recipient_list, + question_list: @question_list + )) end - it "renders attributes in

" do + it 'renders attributes in

' do render expect(rendered).to match(/Name/) expect(rendered).to match(/MyText/) diff --git a/spec/views/legacy/schools/edit.html.erb_spec.rb b/spec/views/legacy/schools/edit.html.erb_spec.rb index 624e09b8..c19c6c1e 100644 --- a/spec/views/legacy/schools/edit.html.erb_spec.rb +++ b/spec/views/legacy/schools/edit.html.erb_spec.rb @@ -1,20 +1,18 @@ require 'rails_helper' -RSpec.describe "legacy/schools/edit", type: :view do +RSpec.describe 'legacy/schools/edit', type: :view do before(:each) do @school = assign(:school, Legacy::School.create!( - :name => "MyString", - :district_id => 1 - )) + name: 'MyString', + district_id: 1 + )) end - it "renders the edit school form" do + it 'renders the edit school form' do render - assert_select "form[action=?][method=?]", legacy_school_path(@school), "post" do - - assert_select "input#school_name[name=?]", "school[name]" - + assert_select 'form[action=?][method=?]', legacy_school_path(@school), 'post' do + assert_select 'input#school_name[name=?]', 'school[name]' end end end diff --git a/spec/views/legacy/schools/new.html.erb_spec.rb b/spec/views/legacy/schools/new.html.erb_spec.rb index 55b45ea5..e3fcefb5 100644 --- a/spec/views/legacy/schools/new.html.erb_spec.rb +++ b/spec/views/legacy/schools/new.html.erb_spec.rb @@ -1,21 +1,19 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/schools/new", type: :view do + RSpec.describe 'legacy/schools/new', type: :view do before(:each) do assign(:school, School.new( - :name => "MyString", - :district_id => 1 - )) + name: 'MyString', + district_id: 1 + )) end - it "renders new school form" do + it 'renders new school form' do render - assert_select "form[action=?][method=?]", legacy_schools_path, "post" do - - assert_select "input#school_name[name=?]", "school[name]" - + assert_select 'form[action=?][method=?]', legacy_schools_path, 'post' do + assert_select 'input#school_name[name=?]', 'school[name]' end end end diff --git a/spec/views/legacy/schools/show.html.erb_spec.rb b/spec/views/legacy/schools/show.html.erb_spec.rb index b12fe4ea..1a50f028 100644 --- a/spec/views/legacy/schools/show.html.erb_spec.rb +++ b/spec/views/legacy/schools/show.html.erb_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' module Legacy - RSpec.describe "legacy/schools/show", type: :view do + RSpec.describe 'legacy/schools/show', type: :view do before(:each) do @school_categories = [] @school = assign(:school, School.create!( - :name => "School", - :district => District.create(name: 'District') - )) + name: 'School', + district: District.create(name: 'District') + )) end - it "renders attributes in

" do - render(template: "legacy/schools/show") + it 'renders attributes in

' do + render(template: 'legacy/schools/show') expect(rendered).to match(/School/) expect(rendered).to match(/District/) end diff --git a/spec/views/overview/index.html.erb_spec.rb b/spec/views/overview/index.html.erb_spec.rb index 33b2505a..95d68a4c 100644 --- a/spec/views/overview/index.html.erb_spec.rb +++ b/spec/views/overview/index.html.erb_spec.rb @@ -3,9 +3,38 @@ require 'rails_helper' describe 'overview/index.html.erb' do subject { Nokogiri::HTML(rendered) } - let(:support_for_teaching) { create(:measure, name: 'Support For Teaching Development & Growth') } - let(:effective_leadership) { create(:measure, name: 'Effective Leadership') } - let(:professional_qualifications) { create(:measure, name: 'Professional Qualifications') } + let(:support_for_teaching) do + measure = create(:measure, name: 'Support For Teaching Development & Growth', measure_id: '1') + create(:student_survey_item, + measure: measure, + watch_low_benchmark: 1.5, + growth_low_benchmark: 2.5, + approval_low_benchmark: 3.5, + ideal_low_benchmark: 4.5) + measure + end + + let(:effective_leadership) do + measure = create(:measure, name: 'Effective Leadership', measure_id: '2') + create(:teacher_survey_item, + measure: measure, + watch_low_benchmark: 1.5, + growth_low_benchmark: 2.5, + approval_low_benchmark: 3.5, + ideal_low_benchmark: 4.5) + measure + end + + let(:professional_qualifications) do + measure = create(:measure, name: 'Professional Qualifications', measure_id: '3') + create(:admin_data_item, + measure: measure, + watch_low_benchmark: 1.5, + growth_low_benchmark: 2.5, + approval_low_benchmark: 3.5, + ideal_low_benchmark: 4.5) + measure + end before :each do assign :category_presenters, [] @@ -15,39 +44,46 @@ describe 'overview/index.html.erb' do end context 'when some presenters have a nil score' do - let(:variance_chart_row_presenters) { + let(:variance_chart_row_presenters) do [ VarianceChartRowPresenter.new(measure: support_for_teaching, score: Score.new), - VarianceChartRowPresenter.new(measure: create(:measure, name: 'Should Be Displayed', measure_id: 'should-be-displayed'), score: Score.new(rand)), - VarianceChartRowPresenter.new(measure: effective_leadership, score: Score.new), + VarianceChartRowPresenter.new(measure: effective_leadership, score: Score.new(rand)), VarianceChartRowPresenter.new(measure: professional_qualifications, score: Score.new) ] - } + end it 'displays a note detailing which measures have insufficient responses for the given school & academic year' do - expect(rendered).to match /Note: The following measures are not displayed due to limited availability of school admin data and\/or low survey response rates: Support For Teaching Development & Growth; Effective Leadership; Professional Qualifications./ + expect(rendered).to match %r{Note: The following measures are not displayed due to limited availability of school admin data and/or low survey response rates: Support For Teaching Development & Growth; Professional Qualifications.} end it 'displays a variance row and label only those presenters for which the score is not nil' do displayed_variance_rows = subject.css('[data-for-measure-id]') expect(displayed_variance_rows.count).to eq 1 - expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq 'should-be-displayed' + expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq '2' displayed_variance_labels = subject.css('[data-variance-row-label]') expect(displayed_variance_labels.count).to eq 1 - expect(displayed_variance_labels.first.inner_text).to include 'Should Be Displayed' + expect(displayed_variance_labels.first.inner_text).to include 'Effective Leadership' end end context 'when all the presenters have a non-nil score' do - let(:variance_chart_row_presenters) { + let(:variance_chart_row_presenters) do + measure = create(:measure, name: 'Display Me', measure_id: 'display-me') + create(:student_survey_item, + measure: measure, + watch_low_benchmark: 1.5, + growth_low_benchmark: 2.5, + approval_low_benchmark: 3.5, + ideal_low_benchmark: 4.5) [ - VarianceChartRowPresenter.new(measure: create(:measure, name: 'Display Me', measure_id: 'display-me'), score: Score.new(rand)) + VarianceChartRowPresenter.new(measure: measure, + score: Score.new(rand)) ] - } + end it 'does not display a note detailing which measures have insufficient responses for the given school & academic year' do - expect(rendered).not_to match /Note: The following measures are not displayed due to limited availability of school admin data and\/or low survey response rates/ + expect(rendered).not_to match %r{Note: The following measures are not displayed due to limited availability of school admin data and/or low survey response rates} end it 'displays a variance row for each presenter' do diff --git a/spec/views/overview/variance_chart.html.erb_spec.rb b/spec/views/overview/variance_chart.html.erb_spec.rb index a0a5dc98..78fdc92a 100644 --- a/spec/views/overview/variance_chart.html.erb_spec.rb +++ b/spec/views/overview/variance_chart.html.erb_spec.rb @@ -4,8 +4,10 @@ describe 'overview/_variance_chart.html.erb' do context 'When there are scores to show' do subject { Nokogiri::HTML(rendered) } - let(:higher_scoring_measure) { create(:measure) } - let(:lower_scoring_measure) { create(:measure) } + let(:survey_items1) { [create(:student_survey_item)] } + let(:survey_items2) { [create(:student_survey_item)] } + let(:higher_scoring_measure) { create(:measure, survey_items: survey_items1) } + let(:lower_scoring_measure) { create(:measure, survey_items: survey_items2) } before :each do presenters = [ @@ -13,7 +15,7 @@ describe 'overview/_variance_chart.html.erb' do VarianceChartRowPresenter.new(measure: higher_scoring_measure, score: Score.new(5)) ] - render partial: 'variance_chart', locals: { presenters: presenters} + render partial: 'variance_chart', locals: { presenters: presenters } end it 'displays higher scoring measures above lower scoring measures' do @@ -39,7 +41,7 @@ describe 'overview/_variance_chart.html.erb' do VarianceChartRowPresenter.new(measure: another_measure_lacking_score, score: Score.new(nil)) ] - render partial: 'variance_chart', locals: { presenters: presenters} + render partial: 'variance_chart', locals: { presenters: presenters } end it "displays the text 'insufficient data' for an empty dataset" do