From 813efca4935a53592fb7974fe5b8c3fad7080667 Mon Sep 17 00:00:00 2001 From: Alex Basson Date: Thu, 9 Sep 2021 10:34:38 -0400 Subject: [PATCH] Visiting /districts/winchester/schools/winchester-high-school/dashboard displays an empty dashboard --- app/controllers/dashboard_controller.rb | 13 +++++++++++++ app/views/dashboard/index.html.erb | 1 + config/routes.rb | 6 +++++- spec/features/school_dashboard_feature_spec.rb | 14 ++++++++++++++ spec/spec_helper.rb | 3 +++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/controllers/dashboard_controller.rb create mode 100644 app/views/dashboard/index.html.erb create mode 100644 spec/features/school_dashboard_feature_spec.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 00000000..cb197508 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,13 @@ +class DashboardController < ApplicationController + + def index + @school = School.find_by_slug school_slug + end + + private + + def school_slug + params[:school_id] + end + +end \ No newline at end of file diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb new file mode 100644 index 00000000..7fb1b868 --- /dev/null +++ b/app/views/dashboard/index.html.erb @@ -0,0 +1 @@ +

<%= @school.name %>

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1f1a403b..f7c93313 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,11 @@ Rails.application.routes.draw do resources :question_lists resources :questions resources :categories - resources :districts + resources :districts do + resources :schools, only: [:index, :show] do + resources :dashboard, only: [:index] + end + end resources :experiments resources :schools do diff --git a/spec/features/school_dashboard_feature_spec.rb b/spec/features/school_dashboard_feature_spec.rb new file mode 100644 index 00000000..a9e07677 --- /dev/null +++ b/spec/features/school_dashboard_feature_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +RSpec.feature "School dashboard", type: feature do + let(:district) { District.create name: 'Winchester' } + let(:school) { + School.create name: 'Winchester High School', slug: 'winchester-high-school', district: district + } + + scenario "User views a school dashboard" do + visit "/districts/winchester/schools/#{school.slug}/dashboard?year=2020-21" + + expect(page).to have_text(school.name) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af65bbd1..3e0dfe38 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +require 'capybara/rspec' # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -47,6 +48,8 @@ RSpec.configure do |config| # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups + config.include Capybara::DSL + # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin