From acac8f67b0830a39548cded4773be85711e6621a Mon Sep 17 00:00:00 2001 From: Alex Basson Date: Wed, 15 Sep 2021 11:57:46 -0400 Subject: [PATCH] Seed db with Professional Qualifications construct --- app/controllers/dashboard_controller.rb | 6 +---- app/models/construct.rb | 27 ++++++++++++------- .../construct_graph_row_presenter.rb | 4 +-- app/views/dashboard/index.html.erb | 2 +- .../20210915151547_create_constructs.rb | 12 +++++++++ db/schema.rb | 12 +++++++-- db/seeds.rb | 2 ++ .../features/school_dashboard_feature_spec.rb | 1 + spec/models/construct_spec.rb | 14 ++++++++++ .../construct_graph_row_presenter_spec.rb | 4 +-- spec/spec_helper.rb | 4 +++ 11 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20210915151547_create_constructs.rb create mode 100644 spec/models/construct_spec.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index b308b5da..1fbbdb95 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -4,7 +4,7 @@ class DashboardController < ApplicationController def index authenticate(district.name.downcase, "#{district.name.downcase}!") @construct_graph_row_presenters = [ - ConstructGraphRowPresenter.new(construct: professional_qualifications_construct, score: 4.8) + ConstructGraphRowPresenter.new(construct: Construct.find_by_construct_id('1A-i'), score: 4.8) ] end @@ -22,8 +22,4 @@ class DashboardController < ApplicationController @district ||= @school.district end - def professional_qualifications_construct - Construct.new title: "Professional Qualifications", watch_low_benchmark: 2.48, growth_low_benchmark: 2.99, approval_low_benchmark: 3.49, ideal_low_benchmark: 4.7 - end - end diff --git a/app/models/construct.rb b/app/models/construct.rb index 7f594936..9ac78d7f 100644 --- a/app/models/construct.rb +++ b/app/models/construct.rb @@ -1,19 +1,28 @@ -class Construct +class Construct < ActiveRecord::Base Zone = Struct.new(:low_benchmark, :high_benchmark, :type) do def includes_score?(score) score > low_benchmark and score < high_benchmark end end - attr_reader :title, :warning_zone, :watch_zone, :growth_zone, :approval_zone, :ideal_zone + def warning_zone + Zone.new(1, watch_low_benchmark, :warning) + end + + def watch_zone + Zone.new(watch_low_benchmark, growth_low_benchmark, :watch) + end + + def growth_zone + Zone.new(growth_low_benchmark, approval_low_benchmark, :growth) + end + + def approval_zone + Zone.new(approval_low_benchmark, ideal_low_benchmark, :approval) + end - def initialize(title:, watch_low_benchmark:, growth_low_benchmark:, approval_low_benchmark:, ideal_low_benchmark:) - @title = title - @warning_zone = Zone.new(1, watch_low_benchmark, :warning) - @watch_zone = Zone.new(watch_low_benchmark, growth_low_benchmark, :watch) - @growth_zone = Zone.new(growth_low_benchmark, approval_low_benchmark, :growth) - @approval_zone = Zone.new(approval_low_benchmark, ideal_low_benchmark, :approval) - @ideal_zone = Zone.new(ideal_low_benchmark, 5, :ideal) + def ideal_zone + Zone.new(ideal_low_benchmark, 5.0, :ideal) end def zone_for_score(score) diff --git a/app/presenters/construct_graph_row_presenter.rb b/app/presenters/construct_graph_row_presenter.rb index f2734d34..2208d30c 100644 --- a/app/presenters/construct_graph_row_presenter.rb +++ b/app/presenters/construct_graph_row_presenter.rb @@ -5,8 +5,8 @@ class ConstructGraphRowPresenter @score = score end - def construct_title - @construct.title + def construct_name + @construct.name end def bar_color diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 8d3bd669..31f4715e 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -41,7 +41,7 @@ > <%= @construct_graph_row_presenters.each_with_index do |presenter, index| %> - y=<%= index * construct_row_height + construct_row_height / 2 %> text-anchor="end" dominant-baseline="middle"><%= presenter.construct_title %> + y=<%= index * construct_row_height + construct_row_height / 2 %> text-anchor="end" dominant-baseline="middle"><%= presenter.construct_name %> <% end %> diff --git a/db/migrate/20210915151547_create_constructs.rb b/db/migrate/20210915151547_create_constructs.rb new file mode 100644 index 00000000..7b99e42e --- /dev/null +++ b/db/migrate/20210915151547_create_constructs.rb @@ -0,0 +1,12 @@ +class CreateConstructs < ActiveRecord::Migration[5.0] + def change + create_table :constructs do |t| + t.string :construct_id + t.string :name + t.float :watch_low_benchmark + t.float :growth_low_benchmark + t.float :approval_low_benchmark + t.float :ideal_low_benchmark + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 952a98a1..5bb67008 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,11 +10,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181221180917) do +ActiveRecord::Schema.define(version: 20210915151547) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "pg_stat_statements" create_table "attempts", force: :cascade do |t| t.integer "recipient_id" @@ -49,6 +48,15 @@ ActiveRecord::Schema.define(version: 20181221180917) do t.index ["slug"], name: "index_categories_on_slug", unique: true, using: :btree end + create_table "constructs", force: :cascade do |t| + t.string "construct_id" + t.string "name" + t.float "watch_low_benchmark" + t.float "growth_low_benchmark" + t.float "approval_low_benchmark" + t.float "ideal_low_benchmark" + end + create_table "districts", force: :cascade do |t| t.string "name" t.integer "state_id" diff --git a/db/seeds.rb b/db/seeds.rb index f6665217..ea2936fd 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,6 +6,8 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +Construct.destroy_all +Construct.create construct_id: '1A-i', name: 'Professional Qualifications', watch_low_benchmark: 2.5, growth_low_benchmark: 3.0, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.7 # questions = Category.find_by_name('Family Subcategory').child_categories.map(&:questions).flatten # QuestionList.create(name: 'Family Questions', question_id_array: questions.map(&:id)) diff --git a/spec/features/school_dashboard_feature_spec.rb b/spec/features/school_dashboard_feature_spec.rb index cf37a633..910afc2a 100644 --- a/spec/features/school_dashboard_feature_spec.rb +++ b/spec/features/school_dashboard_feature_spec.rb @@ -20,6 +20,7 @@ feature "School dashboard", type: feature do visit "/districts/winchester/schools/#{school.slug}/dashboard?year=2020-21" expect(page).to have_text(school.name) + expect(page).to have_text('Professional Qualifications') end let(:username) { 'winchester' } diff --git a/spec/models/construct_spec.rb b/spec/models/construct_spec.rb new file mode 100644 index 00000000..2ff771e0 --- /dev/null +++ b/spec/models/construct_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +describe Construct, type: :model do + it 'returns the construct for the given construct id' do + construct = Construct.find_by_construct_id('1A-i') + + expect(construct.name).to eq 'Professional Qualifications' + expect(construct.warning_zone).to eq Construct::Zone.new(1.0, 2.5, :warning) + expect(construct.watch_zone).to eq Construct::Zone.new(2.5, 3.0, :watch) + expect(construct.growth_zone).to eq Construct::Zone.new(3.0, 3.5, :growth) + expect(construct.approval_zone).to eq Construct::Zone.new(3.5, 4.7, :approval) + expect(construct.ideal_zone).to eq Construct::Zone.new(4.7, 5.0, :ideal) + end +end diff --git a/spec/presenters/construct_graph_row_presenter_spec.rb b/spec/presenters/construct_graph_row_presenter_spec.rb index 46f3975d..afa88864 100644 --- a/spec/presenters/construct_graph_row_presenter_spec.rb +++ b/spec/presenters/construct_graph_row_presenter_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "construct graph row presenter" do let(:construct) { Construct.new( - title: 'Some Title', + name: 'Some Title', watch_low_benchmark: watch_low_benchmark, growth_low_benchmark: growth_low_benchmark, approval_low_benchmark: approval_low_benchmark, @@ -23,7 +23,7 @@ RSpec.describe "construct graph row presenter" do shared_examples_for 'construct_title' do it('returns the construct title') do - expect(presenter.construct_title).to eq 'Some Title' + expect(presenter.construct_name).to eq 'Some Title' end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3e0dfe38..b173bec3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,6 +50,10 @@ RSpec.configure do |config| config.include Capybara::DSL + config.before(:suite) do + Rails.application.load_seed # loading seeds + 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