mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
more scaffolding
This commit is contained in:
parent
7e051222aa
commit
392696301c
66 changed files with 1110 additions and 241 deletions
1
.ruby-version
Normal file
1
.ruby-version
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
2.2.2
|
||||||
2
Gemfile
2
Gemfile
|
|
@ -14,7 +14,7 @@ gem 'pg'
|
||||||
# Use Puma as the app server
|
# Use Puma as the app server
|
||||||
gem 'puma', '~> 3.0'
|
gem 'puma', '~> 3.0'
|
||||||
# Use SCSS for stylesheets
|
# Use SCSS for stylesheets
|
||||||
gem 'sass-rails', '~> 5.0'
|
gem 'sass-rails', '>= 5.0.6'
|
||||||
# Use Uglifier as compressor for JavaScript assets
|
# Use Uglifier as compressor for JavaScript assets
|
||||||
gem 'uglifier', '>= 1.3.0'
|
gem 'uglifier', '>= 1.3.0'
|
||||||
# Use CoffeeScript for .coffee assets and views
|
# Use CoffeeScript for .coffee assets and views
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ GEM
|
||||||
rspec-support (~> 3.5.0)
|
rspec-support (~> 3.5.0)
|
||||||
rspec-support (3.5.0)
|
rspec-support (3.5.0)
|
||||||
sass (3.4.23)
|
sass (3.4.23)
|
||||||
sass-rails (5.0.5)
|
sass-rails (5.0.6)
|
||||||
railties (>= 4.0.0, < 6)
|
railties (>= 4.0.0, < 6)
|
||||||
sass (~> 3.1)
|
sass (~> 3.1)
|
||||||
sprockets (>= 2.8, < 4.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
|
|
@ -256,7 +256,7 @@ DEPENDENCIES
|
||||||
rails (~> 5.0.1)
|
rails (~> 5.0.1)
|
||||||
rails-controller-testing
|
rails-controller-testing
|
||||||
rspec-rails (~> 3.5)
|
rspec-rails (~> 3.5)
|
||||||
sass-rails (~> 5.0)
|
sass-rails (>= 5.0.6)
|
||||||
seed_dump
|
seed_dump
|
||||||
spring
|
spring
|
||||||
spring-watcher-listen (~> 2.0.0)
|
spring-watcher-listen (~> 2.0.0)
|
||||||
|
|
|
||||||
3
app/assets/javascripts/districts.coffee
Normal file
3
app/assets/javascripts/districts.coffee
Normal file
|
|
@ -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/
|
||||||
3
app/assets/javascripts/schools.coffee
Normal file
3
app/assets/javascripts/schools.coffee
Normal file
|
|
@ -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/
|
||||||
3
app/assets/stylesheets/districts.scss
Normal file
3
app/assets/stylesheets/districts.scss
Normal file
|
|
@ -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/
|
||||||
|
|
@ -36,6 +36,7 @@ header {
|
||||||
|
|
||||||
a, a:hover, a:visited {
|
a, a:hover, a:visited {
|
||||||
color: $darkgrey;
|
color: $darkgrey;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
app/assets/stylesheets/schools.scss
Normal file
3
app/assets/stylesheets/schools.scss
Normal file
|
|
@ -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/
|
||||||
74
app/controllers/districts_controller.rb
Normal file
74
app/controllers/districts_controller.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
class RecipientsController < ApplicationController
|
class RecipientsController < ApplicationController
|
||||||
|
before_action :set_school
|
||||||
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
|
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /recipients
|
# GET /recipients
|
||||||
# GET /recipients.json
|
# GET /recipients.json
|
||||||
def index
|
def index
|
||||||
@recipients = Recipient.all
|
@recipients = @school.recipients.all
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /recipients/1
|
# GET /recipients/1
|
||||||
|
|
@ -14,7 +15,7 @@ class RecipientsController < ApplicationController
|
||||||
|
|
||||||
# GET /recipients/new
|
# GET /recipients/new
|
||||||
def new
|
def new
|
||||||
@recipient = Recipient.new
|
@recipient = @school.recipients.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /recipients/1/edit
|
# GET /recipients/1/edit
|
||||||
|
|
@ -24,11 +25,11 @@ class RecipientsController < ApplicationController
|
||||||
# POST /recipients
|
# POST /recipients
|
||||||
# POST /recipients.json
|
# POST /recipients.json
|
||||||
def create
|
def create
|
||||||
@recipient = Recipient.new(recipient_params)
|
@recipient = @school.recipients.new(recipient_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @recipient.save
|
if @recipient.save
|
||||||
format.html { redirect_to @recipient, notice: 'Recipient was successfully created.' }
|
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' }
|
||||||
format.json { render :show, status: :created, location: @recipient }
|
format.json { render :show, status: :created, location: @recipient }
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
format.html { render :new }
|
||||||
|
|
@ -42,7 +43,7 @@ class RecipientsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @recipient.update(recipient_params)
|
if @recipient.update(recipient_params)
|
||||||
format.html { redirect_to @recipient, notice: 'Recipient was successfully updated.' }
|
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' }
|
||||||
format.json { render :show, status: :ok, location: @recipient }
|
format.json { render :show, status: :ok, location: @recipient }
|
||||||
else
|
else
|
||||||
format.html { render :edit }
|
format.html { render :edit }
|
||||||
|
|
@ -56,15 +57,20 @@ class RecipientsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@recipient.destroy
|
@recipient.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to recipients_url, notice: 'Recipient was successfully destroyed.' }
|
format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
def set_school
|
||||||
|
@school = School.find(params[:school_id])
|
||||||
|
end
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_recipient
|
def set_recipient
|
||||||
@recipient = Recipient.find(params[:id])
|
@recipient = @school.recipients.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|
|
||||||
74
app/controllers/schools_controller.rb
Normal file
74
app/controllers/schools_controller.rb
Normal file
|
|
@ -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
|
||||||
2
app/helpers/districts_helper.rb
Normal file
2
app/helpers/districts_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
module DistrictsHelper
|
||||||
|
end
|
||||||
2
app/helpers/schools_helper.rb
Normal file
2
app/helpers/schools_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
module SchoolsHelper
|
||||||
|
end
|
||||||
5
app/models/district.rb
Normal file
5
app/models/district.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class District < ApplicationRecord
|
||||||
|
has_many :schools
|
||||||
|
|
||||||
|
validates :name, presence: true
|
||||||
|
end
|
||||||
|
|
@ -1,2 +1,7 @@
|
||||||
class Recipient < ApplicationRecord
|
class Recipient < ApplicationRecord
|
||||||
|
belongs_to :school
|
||||||
|
validates_associated :school
|
||||||
|
|
||||||
|
validates :name, presence: true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
7
app/models/school.rb
Normal file
7
app/models/school.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
class School < ApplicationRecord
|
||||||
|
belongs_to :district
|
||||||
|
has_many :recipients
|
||||||
|
|
||||||
|
validates :name, presence: true
|
||||||
|
|
||||||
|
end
|
||||||
17
app/views/districts/_form.html.haml
Normal file
17
app/views/districts/_form.html.haml
Normal file
|
|
@ -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
|
||||||
5
app/views/districts/edit.html.haml
Normal file
5
app/views/districts/edit.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
%h1 Editing District
|
||||||
|
= render 'form', district: @district
|
||||||
|
= link_to 'Show', @district
|
||||||
|
|
|
||||||
|
= link_to 'Back', districts_path
|
||||||
18
app/views/districts/index.html.haml
Normal file
18
app/views/districts/index.html.haml
Normal file
|
|
@ -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
|
||||||
4
app/views/districts/index.json.jbuilder
Normal file
4
app/views/districts/index.json.jbuilder
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
json.array!(@districts) do |district|
|
||||||
|
json.extract! district, :id, :name, :state_id
|
||||||
|
json.url district_url(district, format: :json)
|
||||||
|
end
|
||||||
3
app/views/districts/new.html.haml
Normal file
3
app/views/districts/new.html.haml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
%h1 New District
|
||||||
|
= render 'form', district: @district
|
||||||
|
= link_to 'Back', districts_path
|
||||||
10
app/views/districts/show.html.haml
Normal file
10
app/views/districts/show.html.haml
Normal file
|
|
@ -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
|
||||||
1
app/views/districts/show.json.jbuilder
Normal file
1
app/views/districts/show.json.jbuilder
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
json.extract! @district, :id, :name, :state_id, :created_at, :updated_at
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
%html
|
%html
|
||||||
%head
|
%head
|
||||||
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
|
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
|
||||||
%title Edcontext
|
%title EdContext
|
||||||
= csrf_meta_tags
|
= csrf_meta_tags
|
||||||
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
|
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
|
||||||
= stylesheet_link_tag 'https://fonts.googleapis.com/css?family=Roboto:300'
|
= stylesheet_link_tag 'https://fonts.googleapis.com/css?family=Roboto:300'
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
<%= yield %>
|
|
||||||
1
app/views/layouts/mailer.text.haml
Normal file
1
app/views/layouts/mailer.text.haml
Normal file
|
|
@ -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 %>
|
|
||||||
38
app/views/recipients/_form.html.haml
Normal file
38
app/views/recipients/_form.html.haml
Normal file
|
|
@ -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 %>
|
|
||||||
5
app/views/recipients/edit.html.haml
Normal file
5
app/views/recipients/edit.html.haml
Normal file
|
|
@ -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 %>
|
|
||||||
33
app/views/recipients/index.html.haml
Normal file
33
app/views/recipients/index.html.haml
Normal file
|
|
@ -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 %>
|
|
||||||
6
app/views/recipients/new.html.haml
Normal file
6
app/views/recipients/new.html.haml
Normal file
|
|
@ -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 %>
|
|
||||||
33
app/views/recipients/show.html.haml
Normal file
33
app/views/recipients/show.html.haml
Normal file
|
|
@ -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)
|
||||||
17
app/views/schools/_form.html.haml
Normal file
17
app/views/schools/_form.html.haml
Normal file
|
|
@ -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'
|
||||||
5
app/views/schools/edit.html.haml
Normal file
5
app/views/schools/edit.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
%h1 Editing School
|
||||||
|
= render 'form', school: @school
|
||||||
|
= link_to 'Show', @school
|
||||||
|
|
|
||||||
|
= link_to 'Back', schools_path
|
||||||
17
app/views/schools/index.html.haml
Normal file
17
app/views/schools/index.html.haml
Normal file
|
|
@ -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
|
||||||
4
app/views/schools/index.json.jbuilder
Normal file
4
app/views/schools/index.json.jbuilder
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
json.array!(@schools) do |school|
|
||||||
|
json.extract! school, :id, :name, :district_id
|
||||||
|
json.url school_url(school, format: :json)
|
||||||
|
end
|
||||||
6
app/views/schools/new.html.haml
Normal file
6
app/views/schools/new.html.haml
Normal file
|
|
@ -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
|
||||||
13
app/views/schools/show.html.haml
Normal file
13
app/views/schools/show.html.haml
Normal file
|
|
@ -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
|
||||||
1
app/views/schools/show.json.jbuilder
Normal file
1
app/views/schools/show.json.jbuilder
Normal file
|
|
@ -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
|
Rails.application.routes.draw do
|
||||||
resources :recipients
|
resources :districts
|
||||||
|
|
||||||
|
resources :schools do
|
||||||
|
resources :recipients
|
||||||
|
end
|
||||||
|
|
||||||
devise_for :users
|
devise_for :users
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
root to: "welcome#index"
|
root to: "welcome#index"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
10
db/migrate/20170228164212_create_schools.rb
Normal file
10
db/migrate/20170228164212_create_schools.rb
Normal file
|
|
@ -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
|
||||||
10
db/migrate/20170228164245_create_districts.rb
Normal file
10
db/migrate/20170228164245_create_districts.rb
Normal file
|
|
@ -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
|
||||||
16
db/schema.rb
16
db/schema.rb
|
|
@ -10,11 +10,18 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170225150432) do
|
ActiveRecord::Schema.define(version: 20170228164245) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "districts", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.integer "state_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "recipients", force: :cascade do |t|
|
create_table "recipients", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "phone"
|
t.string "phone"
|
||||||
|
|
@ -30,6 +37,13 @@ ActiveRecord::Schema.define(version: 20170225150432) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "schools", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.integer "district_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
|
|
||||||
159
spec/controllers/districts_controller_spec.rb
Normal file
159
spec/controllers/districts_controller_spec.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -20,16 +20,20 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe RecipientsController, type: :controller do
|
RSpec.describe RecipientsController, type: :controller do
|
||||||
|
|
||||||
|
let(:school) { School.create!(name: 'School') }
|
||||||
|
|
||||||
# This should return the minimal set of attributes required to create a valid
|
# This should return the minimal set of attributes required to create a valid
|
||||||
# Recipient. As you add validations to Recipient, be sure to
|
# Recipient. As you add validations to Recipient, be sure to
|
||||||
# adjust the attributes here as well.
|
# adjust the attributes here as well.
|
||||||
let(:valid_attributes) {
|
let(:valid_attributes) {
|
||||||
skip("Add a hash of attributes valid for your model")
|
{
|
||||||
|
name: 'Recipient Name',
|
||||||
|
phone: '111-222-3333',
|
||||||
|
school_id: school.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:invalid_attributes) {
|
let(:invalid_attributes) { {name: '', phone: '111-222-3333'} }
|
||||||
skip("Add a hash of attributes invalid for your model")
|
|
||||||
}
|
|
||||||
|
|
||||||
# This should return the minimal set of values that should be in the session
|
# 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
|
# in order to pass any filters (e.g. authentication) defined in
|
||||||
|
|
@ -39,7 +43,7 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
describe "GET #index" do
|
describe "GET #index" do
|
||||||
it "assigns all recipients as @recipients" do
|
it "assigns all recipients as @recipients" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
get :index, params: {}, session: valid_session
|
get :index, params: {school_id: school.to_param}, session: valid_session
|
||||||
expect(assigns(:recipients)).to eq([recipient])
|
expect(assigns(:recipients)).to eq([recipient])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -47,14 +51,14 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
describe "GET #show" do
|
describe "GET #show" do
|
||||||
it "assigns the requested recipient as @recipient" do
|
it "assigns the requested recipient as @recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
get :show, params: {id: recipient.to_param}, session: valid_session
|
get :show, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||||
expect(assigns(:recipient)).to eq(recipient)
|
expect(assigns(:recipient)).to eq(recipient)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET #new" do
|
describe "GET #new" do
|
||||||
it "assigns a new recipient as @recipient" do
|
it "assigns a new recipient as @recipient" do
|
||||||
get :new, params: {}, session: valid_session
|
get :new, params: {school_id: school.id}, session: valid_session
|
||||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -62,7 +66,7 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
describe "GET #edit" do
|
describe "GET #edit" do
|
||||||
it "assigns the requested recipient as @recipient" do
|
it "assigns the requested recipient as @recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
get :edit, params: {id: recipient.to_param}, session: valid_session
|
get :edit, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||||
expect(assigns(:recipient)).to eq(recipient)
|
expect(assigns(:recipient)).to eq(recipient)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -71,30 +75,30 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
context "with valid params" do
|
context "with valid params" do
|
||||||
it "creates a new Recipient" do
|
it "creates a new Recipient" do
|
||||||
expect {
|
expect {
|
||||||
post :create, params: {recipient: valid_attributes}, session: valid_session
|
post :create, params: {school_id: school.to_param, recipient: valid_attributes}, session: valid_session
|
||||||
}.to change(Recipient, :count).by(1)
|
}.to change(Recipient, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "assigns a newly created recipient as @recipient" do
|
it "assigns a newly created recipient as @recipient" do
|
||||||
post :create, params: {recipient: valid_attributes}, session: valid_session
|
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_a(Recipient)
|
||||||
expect(assigns(:recipient)).to be_persisted
|
expect(assigns(:recipient)).to be_persisted
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the created recipient" do
|
it "redirects to the created recipient" do
|
||||||
post :create, params: {recipient: valid_attributes}, session: valid_session
|
post :create, params: {school_id: school.to_param, recipient: valid_attributes}, session: valid_session
|
||||||
expect(response).to redirect_to(Recipient.last)
|
expect(response).to redirect_to(school_recipient_path(school, Recipient.last))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid params" do
|
context "with invalid params" do
|
||||||
it "assigns a newly created but unsaved recipient as @recipient" do
|
it "assigns a newly created but unsaved recipient as @recipient" do
|
||||||
post :create, params: {recipient: invalid_attributes}, session: valid_session
|
post :create, params: {school_id: school.to_param, recipient: invalid_attributes}, session: valid_session
|
||||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the 'new' template" do
|
it "re-renders the 'new' template" do
|
||||||
post :create, params: {recipient: invalid_attributes}, session: valid_session
|
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
|
end
|
||||||
|
|
@ -103,39 +107,40 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
describe "PUT #update" do
|
describe "PUT #update" do
|
||||||
context "with valid params" do
|
context "with valid params" do
|
||||||
let(:new_attributes) {
|
let(:new_attributes) {
|
||||||
skip("Add a hash of attributes valid for your model")
|
{name: 'New Name'}
|
||||||
}
|
}
|
||||||
|
|
||||||
it "updates the requested recipient" do
|
it "updates the requested recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
put :update, params: {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
|
recipient.reload
|
||||||
skip("Add assertions for updated state")
|
expect(recipient.name).to eq('New Name')
|
||||||
|
expect(recipient.phone).to eq('111-222-3333')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "assigns the requested recipient as @recipient" do
|
it "assigns the requested recipient as @recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
put :update, params: {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)
|
expect(assigns(:recipient)).to eq(recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the recipient" do
|
it "redirects to the recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
put :update, params: {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(recipient)
|
expect(response).to redirect_to(school_recipient_url(school, recipient))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid params" do
|
context "with invalid params" do
|
||||||
it "assigns the recipient as @recipient" do
|
it "assigns the recipient as @recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
put :update, params: {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)
|
expect(assigns(:recipient)).to eq(recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the 'edit' template" do
|
it "re-renders the 'edit' template" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
put :update, params: {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(response).to render_template("edit")
|
expect(response).to render_template("edit")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -145,14 +150,14 @@ RSpec.describe RecipientsController, type: :controller do
|
||||||
it "destroys the requested recipient" do
|
it "destroys the requested recipient" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
expect {
|
expect {
|
||||||
delete :destroy, params: {id: recipient.to_param}, session: valid_session
|
delete :destroy, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||||
}.to change(Recipient, :count).by(-1)
|
}.to change(Recipient, :count).by(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the recipients list" do
|
it "redirects to the recipients list" do
|
||||||
recipient = Recipient.create! valid_attributes
|
recipient = Recipient.create! valid_attributes
|
||||||
delete :destroy, params: {id: recipient.to_param}, session: valid_session
|
delete :destroy, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||||
expect(response).to redirect_to(recipients_url)
|
expect(response).to redirect_to(school)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
159
spec/controllers/schools_controller_spec.rb
Normal file
159
spec/controllers/schools_controller_spec.rb
Normal file
|
|
@ -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
|
||||||
39
spec/routing/districts_routing_spec.rb
Normal file
39
spec/routing/districts_routing_spec.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -2,37 +2,43 @@ require "rails_helper"
|
||||||
|
|
||||||
RSpec.describe RecipientsController, type: :routing do
|
RSpec.describe RecipientsController, type: :routing do
|
||||||
describe "routing" do
|
describe "routing" do
|
||||||
|
before(:each) do
|
||||||
|
@school = School.create!(
|
||||||
|
:name => "MyString",
|
||||||
|
:district_id => 1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it "routes to #index" do
|
it "routes to #index" do
|
||||||
expect(:get => "/recipients").to route_to("recipients#index")
|
expect(:get => "schools/#{@school.id}/recipients").to route_to("recipients#index", school_id: @school.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #new" do
|
it "routes to #new" do
|
||||||
expect(:get => "/recipients/new").to route_to("recipients#new")
|
expect(:get => "schools/#{@school.id}/recipients/new").to route_to("recipients#new", school_id: @school.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #show" do
|
it "routes to #show" do
|
||||||
expect(:get => "/recipients/1").to route_to("recipients#show", :id => "1")
|
expect(:get => "schools/#{@school.id}/recipients/1").to route_to("recipients#show", school_id: @school.id.to_s, :id => "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #edit" do
|
it "routes to #edit" do
|
||||||
expect(:get => "/recipients/1/edit").to route_to("recipients#edit", :id => "1")
|
expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("recipients#edit", school_id: @school.id.to_s, :id => "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #create" do
|
it "routes to #create" do
|
||||||
expect(:post => "/recipients").to route_to("recipients#create")
|
expect(:post => "schools/#{@school.id}/recipients").to route_to("recipients#create", school_id: @school.id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #update via PUT" do
|
it "routes to #update via PUT" do
|
||||||
expect(:put => "/recipients/1").to route_to("recipients#update", :id => "1")
|
expect(:put => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #update via PATCH" do
|
it "routes to #update via PATCH" do
|
||||||
expect(:patch => "/recipients/1").to route_to("recipients#update", :id => "1")
|
expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #destroy" do
|
it "routes to #destroy" do
|
||||||
expect(:delete => "/recipients/1").to route_to("recipients#destroy", :id => "1")
|
expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("recipients#destroy", school_id: @school.id.to_s, :id => "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
39
spec/routing/schools_routing_spec.rb
Normal file
39
spec/routing/schools_routing_spec.rb
Normal file
|
|
@ -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
|
||||||
21
spec/views/districts/edit.html.erb_spec.rb
Normal file
21
spec/views/districts/edit.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
22
spec/views/districts/index.html.erb_spec.rb
Normal file
22
spec/views/districts/index.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
21
spec/views/districts/new.html.erb_spec.rb
Normal file
21
spec/views/districts/new.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
16
spec/views/districts/show.html.erb_spec.rb
Normal file
16
spec/views/districts/show.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -2,6 +2,10 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "recipients/edit", type: :view do
|
RSpec.describe "recipients/edit", type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
@school = assign(:recipient, School.create!(
|
||||||
|
:name => "School"
|
||||||
|
))
|
||||||
|
|
||||||
@recipient = assign(:recipient, Recipient.create!(
|
@recipient = assign(:recipient, Recipient.create!(
|
||||||
:name => "MyString",
|
:name => "MyString",
|
||||||
:phone => "MyString",
|
:phone => "MyString",
|
||||||
|
|
@ -11,14 +15,14 @@ RSpec.describe "recipients/edit", type: :view do
|
||||||
:home_language_id => 1,
|
:home_language_id => 1,
|
||||||
:income => "MyString",
|
:income => "MyString",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => 1
|
:school_id => @school.id
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the edit recipient form" do
|
it "renders the edit recipient form" do
|
||||||
render
|
render
|
||||||
|
|
||||||
assert_select "form[action=?][method=?]", recipient_path(@recipient), "post" do
|
assert_select "form[action=?][method=?]", school_recipient_path(@school, @recipient), "post" do
|
||||||
|
|
||||||
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
||||||
|
|
||||||
|
|
@ -34,9 +38,6 @@ RSpec.describe "recipients/edit", type: :view do
|
||||||
|
|
||||||
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
||||||
|
|
||||||
assert_select "input#recipient_opted_out[name=?]", "recipient[opted_out]"
|
|
||||||
|
|
||||||
assert_select "input#recipient_school_id[name=?]", "recipient[school_id]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "recipients/index", type: :view do
|
RSpec.describe "recipients/index", type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
@school = assign(:school, School.create!(
|
||||||
|
name: 'School'
|
||||||
|
))
|
||||||
|
|
||||||
assign(:recipients, [
|
assign(:recipients, [
|
||||||
Recipient.create!(
|
Recipient.create!(
|
||||||
:name => "Name",
|
:name => "Name",
|
||||||
|
|
@ -12,7 +16,7 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
:home_language_id => 2,
|
:home_language_id => 2,
|
||||||
:income => "Income",
|
:income => "Income",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => 3
|
:school_id => @school.to_param
|
||||||
),
|
),
|
||||||
Recipient.create!(
|
Recipient.create!(
|
||||||
:name => "Name",
|
:name => "Name",
|
||||||
|
|
@ -23,7 +27,7 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
:home_language_id => 2,
|
:home_language_id => 2,
|
||||||
:income => "Income",
|
:income => "Income",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => 3
|
:school_id => @school.to_param
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
@ -38,6 +42,6 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
assert_select "tr>td", :text => 2.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 => "Income".to_s, :count => 2
|
||||||
assert_select "tr>td", :text => false.to_s, :count => 2
|
assert_select "tr>td", :text => false.to_s, :count => 2
|
||||||
assert_select "tr>td", :text => 3.to_s, :count => 2
|
assert_select "tr>td", :text => @school.to_param, :count => 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "recipients/new", type: :view do
|
RSpec.describe "recipients/new", type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
assign(:recipient, Recipient.new(
|
@school = assign(:school, School.create!(
|
||||||
|
name: 'School'
|
||||||
|
))
|
||||||
|
|
||||||
|
@recipient = assign(:recipient, Recipient.new(
|
||||||
:name => "MyString",
|
:name => "MyString",
|
||||||
:phone => "MyString",
|
:phone => "MyString",
|
||||||
:gender => "MyString",
|
:gender => "MyString",
|
||||||
|
|
@ -11,14 +15,14 @@ RSpec.describe "recipients/new", type: :view do
|
||||||
:home_language_id => 1,
|
:home_language_id => 1,
|
||||||
:income => "MyString",
|
:income => "MyString",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => 1
|
:school_id => @school.to_param
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders new recipient form" do
|
it "renders new recipient form" do
|
||||||
render
|
render
|
||||||
|
|
||||||
assert_select "form[action=?][method=?]", recipients_path, "post" do
|
assert_select "form[action=?][method=?]", school_recipients_path(@school, @recipient), "post" do
|
||||||
|
|
||||||
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
||||||
|
|
||||||
|
|
@ -34,9 +38,6 @@ RSpec.describe "recipients/new", type: :view do
|
||||||
|
|
||||||
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
||||||
|
|
||||||
assert_select "input#recipient_opted_out[name=?]", "recipient[opted_out]"
|
|
||||||
|
|
||||||
assert_select "input#recipient_school_id[name=?]", "recipient[school_id]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "recipients/show", type: :view do
|
RSpec.describe "recipients/show", type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
@school = assign(:school, School.create!(
|
||||||
|
name: 'School'
|
||||||
|
))
|
||||||
|
|
||||||
@recipient = assign(:recipient, Recipient.create!(
|
@recipient = assign(:recipient, Recipient.create!(
|
||||||
:name => "Name",
|
:name => "Name",
|
||||||
:phone => "Phone",
|
:phone => "Phone",
|
||||||
|
|
@ -11,7 +15,7 @@ RSpec.describe "recipients/show", type: :view do
|
||||||
:home_language_id => 2,
|
:home_language_id => 2,
|
||||||
:income => "Income",
|
:income => "Income",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => 3
|
:school_id => @school.to_param
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -25,6 +29,6 @@ RSpec.describe "recipients/show", type: :view do
|
||||||
expect(rendered).to match(/2/)
|
expect(rendered).to match(/2/)
|
||||||
expect(rendered).to match(/Income/)
|
expect(rendered).to match(/Income/)
|
||||||
expect(rendered).to match(/false/)
|
expect(rendered).to match(/false/)
|
||||||
expect(rendered).to match(/3/)
|
expect(rendered).to match(/#{@school.to_param}/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
20
spec/views/schools/edit.html.erb_spec.rb
Normal file
20
spec/views/schools/edit.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
22
spec/views/schools/index.html.erb_spec.rb
Normal file
22
spec/views/schools/index.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
20
spec/views/schools/new.html.erb_spec.rb
Normal file
20
spec/views/schools/new.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||||
16
spec/views/schools/show.html.erb_spec.rb
Normal file
16
spec/views/schools/show.html.erb_spec.rb
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue