parent
7e051222aa
commit
392696301c
@ -0,0 +1 @@
|
||||
2.2.2
|
||||
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Districts controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Schools controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -0,0 +1,74 @@
|
||||
class DistrictsController < ApplicationController
|
||||
before_action :set_district, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /districts
|
||||
# GET /districts.json
|
||||
def index
|
||||
@districts = District.all
|
||||
end
|
||||
|
||||
# GET /districts/1
|
||||
# GET /districts/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /districts/new
|
||||
def new
|
||||
@district = District.new
|
||||
end
|
||||
|
||||
# GET /districts/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /districts
|
||||
# POST /districts.json
|
||||
def create
|
||||
@district = District.new(district_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @district.save
|
||||
format.html { redirect_to @district, notice: 'District was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @district }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @district.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /districts/1
|
||||
# PATCH/PUT /districts/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @district.update(district_params)
|
||||
format.html { redirect_to @district, notice: 'District was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @district }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @district.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /districts/1
|
||||
# DELETE /districts/1.json
|
||||
def destroy
|
||||
@district.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_district
|
||||
@district = District.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def district_params
|
||||
params.require(:district).permit(:name, :state_id)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,74 @@
|
||||
class SchoolsController < ApplicationController
|
||||
before_action :set_school, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /schools
|
||||
# GET /schools.json
|
||||
def index
|
||||
@schools = School.all
|
||||
end
|
||||
|
||||
# GET /schools/1
|
||||
# GET /schools/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /schools/new
|
||||
def new
|
||||
@school = School.new
|
||||
end
|
||||
|
||||
# GET /schools/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /schools
|
||||
# POST /schools.json
|
||||
def create
|
||||
@school = School.new(school_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @school.save
|
||||
format.html { redirect_to @school, notice: 'School was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @school }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @school.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /schools/1
|
||||
# PATCH/PUT /schools/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @school.update(school_params)
|
||||
format.html { redirect_to @school, notice: 'School was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @school }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @school.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /schools/1
|
||||
# DELETE /schools/1.json
|
||||
def destroy
|
||||
@school.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to schools_url, notice: 'School was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_school
|
||||
@school = School.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def school_params
|
||||
params.require(:school).permit(:name, :district_id)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module DistrictsHelper
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module SchoolsHelper
|
||||
end
|
||||
@ -0,0 +1,5 @@
|
||||
class District < ApplicationRecord
|
||||
has_many :schools
|
||||
|
||||
validates :name, presence: true
|
||||
end
|
||||
@ -1,2 +1,7 @@
|
||||
class Recipient < ApplicationRecord
|
||||
belongs_to :school
|
||||
validates_associated :school
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
end
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
class School < ApplicationRecord
|
||||
belongs_to :district
|
||||
has_many :recipients
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
end
|
||||
@ -0,0 +1,17 @@
|
||||
= form_for(district) do |f|
|
||||
- if district.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(district.errors.count, "error")
|
||||
prohibited this district from being saved:
|
||||
%ul
|
||||
- district.errors.full_messages.each do |message|
|
||||
%li= message
|
||||
.field
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
.field
|
||||
= f.label :state_id
|
||||
= f.number_field :state_id
|
||||
.actions
|
||||
= f.submit
|
||||
@ -0,0 +1,5 @@
|
||||
%h1 Editing District
|
||||
= render 'form', district: @district
|
||||
= link_to 'Show', @district
|
||||
|
|
||||
= link_to 'Back', districts_path
|
||||
@ -0,0 +1,18 @@
|
||||
%p#notice= notice
|
||||
%h1 Districts
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th State
|
||||
%th{:colspan => "3"}
|
||||
%tbody
|
||||
- @districts.each do |district|
|
||||
%tr
|
||||
%td= district.name
|
||||
%td= district.state_id
|
||||
%td= link_to 'Show', district
|
||||
%td= link_to 'Edit', edit_district_path(district)
|
||||
%td= link_to 'Destroy', district, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
%br/
|
||||
= link_to 'New District', new_district_path
|
||||
@ -0,0 +1,4 @@
|
||||
json.array!(@districts) do |district|
|
||||
json.extract! district, :id, :name, :state_id
|
||||
json.url district_url(district, format: :json)
|
||||
end
|
||||
@ -0,0 +1,3 @@
|
||||
%h1 New District
|
||||
= render 'form', district: @district
|
||||
= link_to 'Back', districts_path
|
||||
@ -0,0 +1,10 @@
|
||||
%p#notice= notice
|
||||
%p
|
||||
%strong Name:
|
||||
= @district.name
|
||||
%p
|
||||
%strong State:
|
||||
= @district.state_id
|
||||
= link_to 'Edit', edit_district_path(@district)
|
||||
|
|
||||
= link_to 'Back', districts_path
|
||||
@ -0,0 +1 @@
|
||||
json.extract! @district, :id, :name, :state_id, :created_at, :updated_at
|
||||
@ -1 +0,0 @@
|
||||
<%= yield %>
|
||||
@ -0,0 +1 @@
|
||||
= yield
|
||||
@ -1,67 +0,0 @@
|
||||
<%= form_for(recipient) do |f| %>
|
||||
<% if recipient.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(recipient.errors.count, "error") %> prohibited this recipient from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% recipient.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :phone %>
|
||||
<%= f.text_field :phone %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :birth_date %>
|
||||
<%= f.date_select :birth_date %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :gender %>
|
||||
<%= f.text_field :gender %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :race %>
|
||||
<%= f.text_field :race %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :ethnicity %>
|
||||
<%= f.text_field :ethnicity %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :home_language_id %>
|
||||
<%= f.number_field :home_language_id %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :income %>
|
||||
<%= f.text_field :income %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :opted_out %>
|
||||
<%= f.check_box :opted_out %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :school_id %>
|
||||
<%= f.number_field :school_id %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@ -0,0 +1,38 @@
|
||||
= form_for([@school, recipient]) do |f|
|
||||
- if recipient.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(recipient.errors.count, "error")
|
||||
prohibited this recipient from being saved:
|
||||
%ul
|
||||
- recipient.errors.full_messages.each do |message|
|
||||
%li= message
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :phone
|
||||
= f.text_field :phone, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :birth_date
|
||||
= f.date_select :birth_date, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :gender
|
||||
= f.text_field :gender, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :race
|
||||
= f.text_field :race, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :ethnicity
|
||||
= f.text_field :ethnicity, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :home_language_id
|
||||
= f.number_field :home_language_id, class: 'form-control'
|
||||
.form-group
|
||||
= f.label :income
|
||||
= f.text_field :income, class: 'form-control'
|
||||
-# .form-group
|
||||
-# = f.label :school_id
|
||||
-# = f.number_field :school_id
|
||||
.actions
|
||||
= f.submit 'Save', class: 'btn btn-primary'
|
||||
@ -1,6 +0,0 @@
|
||||
<h1>Editing Recipient</h1>
|
||||
|
||||
<%= render 'form', recipient: @recipient %>
|
||||
|
||||
<%= link_to 'Show', @recipient %> |
|
||||
<%= link_to 'Back', recipients_path %>
|
||||
@ -0,0 +1,5 @@
|
||||
%h1 Editing Recipient
|
||||
= render 'form', recipient: @recipient
|
||||
= link_to 'Show', school_recipient_path(@school, @recipient)
|
||||
|
|
||||
= link_to 'Back', school_path(@school)
|
||||
@ -1,45 +0,0 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>Recipients</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Phone</th>
|
||||
<th>Birth date</th>
|
||||
<th>Gender</th>
|
||||
<th>Race</th>
|
||||
<th>Ethnicity</th>
|
||||
<th>Home language</th>
|
||||
<th>Income</th>
|
||||
<th>Opted out</th>
|
||||
<th>School</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @recipients.each do |recipient| %>
|
||||
<tr>
|
||||
<td><%= recipient.name %></td>
|
||||
<td><%= recipient.phone %></td>
|
||||
<td><%= recipient.birth_date %></td>
|
||||
<td><%= recipient.gender %></td>
|
||||
<td><%= recipient.race %></td>
|
||||
<td><%= recipient.ethnicity %></td>
|
||||
<td><%= recipient.home_language_id %></td>
|
||||
<td><%= recipient.income %></td>
|
||||
<td><%= recipient.opted_out %></td>
|
||||
<td><%= recipient.school_id %></td>
|
||||
<td><%= link_to 'Show', recipient %></td>
|
||||
<td><%= link_to 'Edit', edit_recipient_path(recipient) %></td>
|
||||
<td><%= link_to 'Destroy', recipient, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Recipient', new_recipient_path %>
|
||||
@ -0,0 +1,33 @@
|
||||
%h1 Recipients
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th Phone
|
||||
%th Birth date
|
||||
%th Gender
|
||||
%th Race
|
||||
%th Ethnicity
|
||||
%th Home language
|
||||
%th Income
|
||||
%th Opted out
|
||||
%th School
|
||||
%th{:colspan => "3"}
|
||||
%tbody
|
||||
- @recipients.each do |recipient|
|
||||
%tr
|
||||
%td= recipient.name
|
||||
%td= recipient.phone
|
||||
%td= recipient.birth_date
|
||||
%td= recipient.gender
|
||||
%td= recipient.race
|
||||
%td= recipient.ethnicity
|
||||
%td= recipient.home_language_id
|
||||
%td= recipient.income
|
||||
%td= recipient.opted_out
|
||||
%td= recipient.school_id
|
||||
%td= link_to 'Show', school_recipient_path(@school, recipient)
|
||||
%td= link_to 'Edit', edit_school_recipient_path(@school, recipient)
|
||||
%td= link_to 'Destroy', school_recipient_path(@school, recipient), method: :delete, data: { confirm: 'Are you sure?' }
|
||||
%br/
|
||||
= link_to 'New Recipient', new_school_recipient_path(@school)
|
||||
@ -1,5 +0,0 @@
|
||||
<h1>New Recipient</h1>
|
||||
|
||||
<%= render 'form', recipient: @recipient %>
|
||||
|
||||
<%= link_to 'Back', recipients_path %>
|
||||
@ -0,0 +1,6 @@
|
||||
.row
|
||||
.offset-sm-2.col-sm-8
|
||||
%h3 Add A Recipient To This School
|
||||
= render 'form', recipient: @recipient
|
||||
%br
|
||||
%p= link_to 'Back', school_recipients_path(@school)
|
||||
@ -1,54 +0,0 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>Name:</strong>
|
||||
<%= @recipient.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Phone:</strong>
|
||||
<%= @recipient.phone %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Birth date:</strong>
|
||||
<%= @recipient.birth_date %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Gender:</strong>
|
||||
<%= @recipient.gender %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Race:</strong>
|
||||
<%= @recipient.race %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Ethnicity:</strong>
|
||||
<%= @recipient.ethnicity %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Home language:</strong>
|
||||
<%= @recipient.home_language_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Income:</strong>
|
||||
<%= @recipient.income %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Opted out:</strong>
|
||||
<%= @recipient.opted_out %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>School:</strong>
|
||||
<%= @recipient.school_id %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_recipient_path(@recipient) %> |
|
||||
<%= link_to 'Back', recipients_path %>
|
||||
@ -0,0 +1,33 @@
|
||||
%p
|
||||
%strong Name:
|
||||
= @recipient.name
|
||||
%p
|
||||
%strong Phone:
|
||||
= @recipient.phone
|
||||
%p
|
||||
%strong Birth date:
|
||||
= @recipient.birth_date
|
||||
%p
|
||||
%strong Gender:
|
||||
= @recipient.gender
|
||||
%p
|
||||
%strong Race:
|
||||
= @recipient.race
|
||||
%p
|
||||
%strong Ethnicity:
|
||||
= @recipient.ethnicity
|
||||
%p
|
||||
%strong Home language:
|
||||
= @recipient.home_language_id
|
||||
%p
|
||||
%strong Income:
|
||||
= @recipient.income
|
||||
%p
|
||||
%strong Opted out:
|
||||
= @recipient.opted_out
|
||||
%p
|
||||
%strong School:
|
||||
= @recipient.school_id
|
||||
= link_to 'Edit', edit_school_recipient_path(@school, @recipient)
|
||||
|
|
||||
= link_to 'Back', school_path(@school)
|
||||
@ -0,0 +1,17 @@
|
||||
= form_for(school) do |f|
|
||||
- if school.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(school.errors.count, "error")
|
||||
prohibited this school from being saved:
|
||||
%ul
|
||||
- school.errors.full_messages.each do |message|
|
||||
%li= message
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, class: 'form-control'
|
||||
-# .form-group
|
||||
-# = f.label :district_id
|
||||
-# = f.number_field :district_id, class: 'form-control'
|
||||
.form-group
|
||||
= f.submit 'Save School', class: 'btn btn-primary'
|
||||
@ -0,0 +1,5 @@
|
||||
%h1 Editing School
|
||||
= render 'form', school: @school
|
||||
= link_to 'Show', @school
|
||||
|
|
||||
= link_to 'Back', schools_path
|
||||
@ -0,0 +1,17 @@
|
||||
%h1 Schools
|
||||
%table
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th District
|
||||
%th{:colspan => "3"}
|
||||
%tbody
|
||||
- @schools.each do |school|
|
||||
%tr
|
||||
%td= school.name
|
||||
%td= school.district_id
|
||||
%td= link_to 'Show', school
|
||||
%td= link_to 'Edit', edit_school_path(school)
|
||||
%td= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
%br/
|
||||
= link_to 'New School', new_school_path
|
||||
@ -0,0 +1,4 @@
|
||||
json.array!(@schools) do |school|
|
||||
json.extract! school, :id, :name, :district_id
|
||||
json.url school_url(school, format: :json)
|
||||
end
|
||||
@ -0,0 +1,6 @@
|
||||
.row
|
||||
.offset-sm-2.col-sm-8
|
||||
%h3 Create A New School
|
||||
= render 'form', school: @school
|
||||
%br
|
||||
%p= link_to 'Back', schools_path
|
||||
@ -0,0 +1,13 @@
|
||||
%p
|
||||
%strong Name:
|
||||
= @school.name
|
||||
%p
|
||||
%strong District:
|
||||
= @school.district_id
|
||||
|
||||
%p= link_to "Add Recipient", new_school_recipient_path(@school)
|
||||
|
||||
|
||||
= link_to 'Edit', edit_school_path(@school)
|
||||
|
|
||||
= link_to 'Back', schools_path
|
||||
@ -0,0 +1 @@
|
||||
json.extract! @school, :id, :name, :district_id, :created_at, :updated_at
|
||||
@ -1 +1,6 @@
|
||||
WELCOME
|
||||
%p= link_to "Create A New District", new_district_path
|
||||
|
||||
%p= link_to "Create A New School", new_school_path
|
||||
|
||||
- @schools.each do |school|
|
||||
= link_to school.name, school
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
Rails.application.routes.draw do
|
||||
resources :recipients
|
||||
resources :districts
|
||||
|
||||
resources :schools do
|
||||
resources :recipients
|
||||
end
|
||||
|
||||
devise_for :users
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
|
||||
|
||||
|
||||
root to: "welcome#index"
|
||||
end
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
class CreateSchools < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :schools do |t|
|
||||
t.string :name
|
||||
t.integer :district_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,10 @@
|
||||
class CreateDistricts < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :districts do |t|
|
||||
t.string :name
|
||||
t.integer :state_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,159 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
||||
# It demonstrates how one might use RSpec to specify the controller code that
|
||||
# was generated by Rails when you ran the scaffold generator.
|
||||
#
|
||||
# It assumes that the implementation code is generated by the rails scaffold
|
||||
# generator. If you are using any extension libraries to generate different
|
||||
# controller code, this generated spec may or may not pass.
|
||||
#
|
||||
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
||||
# of tools you can use to make these specs even more expressive, but we're
|
||||
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||
#
|
||||
# Compared to earlier versions of this generator, there is very limited use of
|
||||
# stubs and message expectations in this spec. Stubs are only used when there
|
||||
# is no simpler way to get a handle on the object needed for the example.
|
||||
# Message expectations are only used when there is no simpler way to specify
|
||||
# that an instance is receiving a specific message.
|
||||
|
||||
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) {
|
||||
{name: '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
|
||||
# DistrictsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all districts as @districts" do
|
||||
district = District.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:districts)).to eq([district])
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
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 {
|
||||
post :create, params: {district: valid_attributes}, session: valid_session
|
||||
}.to change(District, :count).by(1)
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT #update" do
|
||||
context "with valid params" do
|
||||
let(:new_attributes) {
|
||||
{name: 'New District'}
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
district = District.create! valid_attributes
|
||||
put :update, params: {id: district.to_param, district: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:district)).to eq(district)
|
||||
end
|
||||
|
||||
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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested district" do
|
||||
district = District.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: district.to_param}, session: valid_session
|
||||
}.to change(District, :count).by(-1)
|
||||
end
|
||||
|
||||
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
|
||||
@ -0,0 +1,159 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
||||
# It demonstrates how one might use RSpec to specify the controller code that
|
||||
# was generated by Rails when you ran the scaffold generator.
|
||||
#
|
||||
# It assumes that the implementation code is generated by the rails scaffold
|
||||
# generator. If you are using any extension libraries to generate different
|
||||
# controller code, this generated spec may or may not pass.
|
||||
#
|
||||
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
||||
# of tools you can use to make these specs even more expressive, but we're
|
||||
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||
#
|
||||
# Compared to earlier versions of this generator, there is very limited use of
|
||||
# stubs and message expectations in this spec. Stubs are only used when there
|
||||
# is no simpler way to get a handle on the object needed for the example.
|
||||
# Message expectations are only used when there is no simpler way to specify
|
||||
# that an instance is receiving a specific message.
|
||||
|
||||
RSpec.describe SchoolsController, type: :controller do
|
||||
|
||||
# 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'}
|
||||
}
|
||||
|
||||
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 #index" do
|
||||
it "assigns all schools as @schools" do
|
||||
school = School.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:schools)).to eq([school])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested school as @school" do
|
||||
school = School.create! valid_attributes
|
||||
get :show, params: {id: school.to_param}, session: valid_session
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new school as @school" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:school)).to be_a_new(School)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested school as @school" do
|
||||
school = School.create! valid_attributes
|
||||
get :edit, params: {id: school.to_param}, session: valid_session
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new School" do
|
||||
expect {
|
||||
post :create, params: {school: valid_attributes}, session: valid_session
|
||||
}.to change(School, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created school as @school" do
|
||||
post :create, params: {school: valid_attributes}, session: valid_session
|
||||
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}, session: valid_session
|
||||
expect(response).to redirect_to(School.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved school as @school" do
|
||||
post :create, params: {school: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:school)).to be_a_new(School)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {school: 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) {
|
||||
{name: 'New School'}
|
||||
}
|
||||
|
||||
it "updates the requested school" do
|
||||
school = School.create! valid_attributes
|
||||
put :update, params: {id: school.to_param, school: new_attributes}, session: valid_session
|
||||
school.reload
|
||||
expect(school.name).to eq('New School')
|
||||
end
|
||||
|
||||
it "assigns the requested school as @school" do
|
||||
school = School.create! valid_attributes
|
||||
put :update, params: {id: school.to_param, school: valid_attributes}, session: valid_session
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
|
||||
it "redirects to the school" do
|
||||
school = School.create! valid_attributes
|
||||
put :update, params: {id: school.to_param, school: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the school as @school" do
|
||||
school = School.create! valid_attributes
|
||||
put :update, params: {id: school.to_param, school: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
school = School.create! valid_attributes
|
||||
put :update, params: {id: school.to_param, school: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested school" do
|
||||
school = School.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: school.to_param}, session: valid_session
|
||||
}.to change(School, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the schools list" do
|
||||
school = School.create! valid_attributes
|
||||
delete :destroy, params: {id: school.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(schools_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,39 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe DistrictsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/districts").to route_to("districts#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/districts/new").to route_to("districts#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/districts/1").to route_to("districts#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/districts/1/edit").to route_to("districts#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/districts").to route_to("districts#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/districts/1").to route_to("districts#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/districts/1").to route_to("districts#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/districts/1").to route_to("districts#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,39 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe SchoolsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/schools").to route_to("schools#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/schools/new").to route_to("schools#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/schools/1").to route_to("schools#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/schools/1/edit").to route_to("schools#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/schools").to route_to("schools#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/schools/1").to route_to("schools#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/schools/1").to route_to("schools#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/schools/1").to route_to("schools#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,21 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "districts/edit", type: :view do
|
||||
before(:each) do
|
||||
@district = assign(:district, District.create!(
|
||||
:name => "MyString",
|
||||
:state_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit district form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", district_path(@district), "post" do
|
||||
|
||||
assert_select "input#district_name[name=?]", "district[name]"
|
||||
|
||||
assert_select "input#district_state_id[name=?]", "district[state_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "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
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,21 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "districts/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:district, District.new(
|
||||
:name => "MyString",
|
||||
:state_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new district form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", districts_path, "post" do
|
||||
|
||||
assert_select "input#district_name[name=?]", "district[name]"
|
||||
|
||||
assert_select "input#district_state_id[name=?]", "district[state_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "districts/show", type: :view do
|
||||
before(:each) do
|
||||
@district = assign(:district, District.create!(
|
||||
:name => "Name",
|
||||
:state_id => 2
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Name/)
|
||||
expect(rendered).to match(/2/)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,20 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schools/edit", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
:name => "MyString",
|
||||
:district_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit school form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", school_path(@school), "post" do
|
||||
|
||||
assert_select "input#school_name[name=?]", "school[name]"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schools/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:schools, [
|
||||
School.create!(
|
||||
:name => "Name",
|
||||
:district_id => 2
|
||||
),
|
||||
School.create!(
|
||||
:name => "Name",
|
||||
:district_id => 2
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of schools" do
|
||||
render
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 2.to_s, :count => 2
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,20 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schools/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:school, School.new(
|
||||
:name => "MyString",
|
||||
:district_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new school form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", schools_path, "post" do
|
||||
|
||||
assert_select "input#school_name[name=?]", "school[name]"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schools/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
:name => "Name",
|
||||
:district_id => 2
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Name/)
|
||||
expect(rendered).to match(/2/)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue