parent
72418edd7c
commit
2fb55a7443
@ -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 schedules controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -0,0 +1,64 @@
|
||||
class SchedulesController < ApplicationController
|
||||
before_action :set_school
|
||||
before_action :set_schedule, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET schools/1/schedules
|
||||
def index
|
||||
@schedules = @school.schedules
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/new
|
||||
def new
|
||||
@schedule = @school.schedules.build
|
||||
end
|
||||
|
||||
# GET schools/1/schedules/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST schools/1/schedules
|
||||
def create
|
||||
@schedule = @school.schedules.build(schedule_params)
|
||||
|
||||
if @schedule.save
|
||||
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.')
|
||||
else
|
||||
render action: 'new'
|
||||
end
|
||||
end
|
||||
|
||||
# PUT schools/1/schedules/1
|
||||
def update
|
||||
if @schedule.update_attributes(schedule_params)
|
||||
redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.')
|
||||
else
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE schools/1/schedules/1
|
||||
def destroy
|
||||
@schedule.destroy
|
||||
|
||||
redirect_to @school
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_school
|
||||
@school = School.find(params[:school_id])
|
||||
end
|
||||
|
||||
def set_schedule
|
||||
@schedule = @school.schedules.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def schedule_params
|
||||
params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module SchedulesHelper
|
||||
end
|
||||
@ -0,0 +1,11 @@
|
||||
class Schedule < ApplicationRecord
|
||||
belongs_to :school
|
||||
belongs_to :recipient_list
|
||||
belongs_to :question_list
|
||||
|
||||
validates :name, presence: true
|
||||
validates :recipient_list, presence: true
|
||||
validates :question_list, presence: true
|
||||
|
||||
|
||||
end
|
||||
@ -0,0 +1,51 @@
|
||||
= form_for([@schedule.school, @schedule]) do |f|
|
||||
- if @schedule.errors.any?
|
||||
#error_explanation
|
||||
%h2
|
||||
= pluralize(@schedule.errors.count, "error")
|
||||
prohibited this schedule from being saved:
|
||||
%ul
|
||||
- @schedule.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
.field
|
||||
= f.label :name
|
||||
%br/
|
||||
= f.text_field :name
|
||||
.field
|
||||
= f.label :description
|
||||
%br/
|
||||
= f.text_area :description
|
||||
.field
|
||||
= f.label :school_id
|
||||
%br/
|
||||
= f.number_field :school_id
|
||||
.field
|
||||
= f.label :frequency_hours
|
||||
%br/
|
||||
= f.number_field :frequency_hours
|
||||
.field
|
||||
= f.label :start_date
|
||||
%br/
|
||||
= f.date_select :start_date
|
||||
.field
|
||||
= f.label :end_date
|
||||
%br/
|
||||
= f.date_select :end_date
|
||||
.field
|
||||
= f.label :active
|
||||
%br/
|
||||
= f.check_box :active
|
||||
.field
|
||||
= f.label :random
|
||||
%br/
|
||||
= f.check_box :random
|
||||
.field
|
||||
= f.label :recipient_list_id
|
||||
%br/
|
||||
= f.number_field :recipient_list_id
|
||||
.field
|
||||
= f.label :question_list_id
|
||||
%br/
|
||||
= f.number_field :question_list_id
|
||||
.actions
|
||||
= f.submit
|
||||
@ -0,0 +1,5 @@
|
||||
%h1 Editing schedule
|
||||
= render 'form'
|
||||
= link_to 'Show', [@schedule.school, @schedule]
|
||||
|
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
@ -0,0 +1,33 @@
|
||||
%h1 Listing schedules
|
||||
%table
|
||||
%tr
|
||||
%th Name
|
||||
%th Description
|
||||
%th School
|
||||
%th Frequency hours
|
||||
%th Start date
|
||||
%th End date
|
||||
%th Active
|
||||
%th Random
|
||||
%th Recipient list
|
||||
%th Question list
|
||||
%th
|
||||
%th
|
||||
%th
|
||||
- @schedules.each do |schedule|
|
||||
%tr
|
||||
%td= schedule.name
|
||||
%td= schedule.description
|
||||
%td= schedule.school.name
|
||||
%td= schedule.frequency_hours
|
||||
%td= schedule.start_date
|
||||
%td= schedule.end_date
|
||||
%td= schedule.active
|
||||
%td= schedule.random
|
||||
%td= schedule.recipient_list.name
|
||||
%td= schedule.question_list.name
|
||||
%td= link_to 'Show', [schedule.school, schedule]
|
||||
%td= link_to 'Edit', edit_school_schedule_path(schedule.school, schedule)
|
||||
%td= link_to 'Destroy', [schedule.school, schedule], :confirm => 'Are you sure?', :method => :delete
|
||||
%br/
|
||||
= link_to 'New Schedule', new_school_schedule_path(@school)
|
||||
@ -0,0 +1,3 @@
|
||||
%h1 New schedule
|
||||
= render 'form'
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
@ -0,0 +1,34 @@
|
||||
%p#notice= notice
|
||||
%p
|
||||
%b Name:
|
||||
= @schedule.name
|
||||
%p
|
||||
%b Description:
|
||||
= @schedule.description
|
||||
%p
|
||||
%b School:
|
||||
= @schedule.school.name
|
||||
%p
|
||||
%b Frequency hours:
|
||||
= @schedule.frequency_hours
|
||||
%p
|
||||
%b Start date:
|
||||
= @schedule.start_date
|
||||
%p
|
||||
%b End date:
|
||||
= @schedule.end_date
|
||||
%p
|
||||
%b Active:
|
||||
= @schedule.active
|
||||
%p
|
||||
%b Random:
|
||||
= @schedule.random
|
||||
%p
|
||||
%b Recipient list:
|
||||
= @schedule.recipient_list.name
|
||||
%p
|
||||
%b Question list:
|
||||
= @schedule.question_list.name
|
||||
= link_to 'Edit', edit_school_schedule_path(@schedule.school, @schedule)
|
||||
|
|
||||
= link_to 'Back', school_schedules_path(@schedule.school)
|
||||
@ -0,0 +1,4 @@
|
||||
json.array!(@school_schedules) do |school_schedule|
|
||||
json.extract! school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id
|
||||
json.url school_schedule_url(school_schedule, format: :json)
|
||||
end
|
||||
@ -0,0 +1 @@
|
||||
json.extract! @school_schedule, :id, :name, :description, :school_id, :frequency_hours, :start_date, :end_date, :active, :random, :recipient_list_id, :question_list_id, :created_at, :updated_at
|
||||
@ -0,0 +1,18 @@
|
||||
class CreateSchedules < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :schedules do |t|
|
||||
t.references :school, foreign_key: true
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.integer :frequency_hours
|
||||
t.date :start_date
|
||||
t.date :end_date
|
||||
t.boolean :active, default: true
|
||||
t.boolean :random, default: false
|
||||
t.integer :recipient_list_id
|
||||
t.integer :question_list_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,169 @@
|
||||
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 SchedulesController, type: :controller do
|
||||
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
let(:recipient_list) { RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3]) }
|
||||
let(:question_list) { QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) }
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Schedule. As you add validations to Schedule, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
school_id: school.id,
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list_id: question_list.id,
|
||||
name: 'Parents Schedule',
|
||||
description: 'Schedule for parent questions'
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
# SchedulesController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all schedules as @schedules" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
get :index, params: {school_id: school.id}, session: valid_session
|
||||
expect(assigns(:schedules)).to eq([schedule])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested schedule as @schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
get :show, params: {school_id: school.id, id: schedule.to_param}, session: valid_session
|
||||
expect(assigns(:schedule)).to eq(schedule)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new schedule as @schedule" do
|
||||
get :new, params: {school_id: school.id}, session: valid_session
|
||||
expect(assigns(:schedule)).to be_a_new(Schedule)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested schedule as @schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
get :edit, params: {school_id: school.id, id: schedule.to_param}, session: valid_session
|
||||
expect(assigns(:schedule)).to eq(schedule)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Schedule" do
|
||||
expect {
|
||||
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
|
||||
}.to change(Schedule, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created schedule as @schedule" do
|
||||
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
|
||||
expect(assigns(:schedule)).to be_a(Schedule)
|
||||
expect(assigns(:schedule)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created schedule" do
|
||||
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to([school, Schedule.last])
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved schedule as @schedule" do
|
||||
post :create, params: {school_id: school.id, schedule: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:schedule)).to be_a_new(Schedule)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {school_id: school.id, schedule: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("new")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT #update" do
|
||||
context "with valid params" do
|
||||
let(:new_attributes) {
|
||||
{name: 'New Name'}
|
||||
}
|
||||
|
||||
it "updates the requested schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
put :update, params: {school_id: school.id, id: schedule.to_param, schedule: new_attributes}, session: valid_session
|
||||
schedule.reload
|
||||
expect(schedule.name).to eq('New Name')
|
||||
end
|
||||
|
||||
it "assigns the requested schedule as @schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
put :update, params: {school_id: school.id, id: schedule.to_param, schedule: valid_attributes}, session: valid_session
|
||||
expect(assigns(:schedule)).to eq(schedule)
|
||||
end
|
||||
|
||||
it "redirects to the schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
put :update, params: {school_id: school.id, id: schedule.to_param, schedule: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to([school, schedule])
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the schedule as @schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
put :update, params: {school_id: school.id, id: schedule.to_param, schedule: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:schedule)).to eq(schedule)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
put :update, params: {school_id: school.id, id: schedule.to_param, schedule: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested schedule" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {school_id: school.id, id: schedule.to_param}, session: valid_session
|
||||
}.to change(Schedule, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the schedules list" do
|
||||
schedule = Schedule.create! valid_attributes
|
||||
delete :destroy, params: {school_id: school.id, id: schedule.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@ -0,0 +1,45 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe SchedulesController, type: :routing do
|
||||
describe "routing" do
|
||||
before(:each) do
|
||||
@school = School.create!(
|
||||
:name => "MyString",
|
||||
:district_id => 1
|
||||
)
|
||||
end
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "schools/#{@school.id}/schedules").to route_to("schedules#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/schedules/new").to route_to("schedules#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/schedules/1").to route_to("schedules#show", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "schools/#{@school.id}/schedules/1/edit").to route_to("schedules#edit", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "schools/#{@school.id}/schedules").to route_to("schedules#create", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "schools/#{@school.id}/schedules/1").to route_to("schedules#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "schools/#{@school.id}/schedules/1").to route_to("schedules#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "schools/#{@school.id}/schedules/1").to route_to("schedules#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,45 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schedules/edit", type: :view do
|
||||
before(:each) do
|
||||
question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3])
|
||||
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school)
|
||||
|
||||
@schedule = assign(:schedule, Schedule.create!(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:school_id => @school.id,
|
||||
:frequency_hours => 1,
|
||||
:active => false,
|
||||
:random => false,
|
||||
:recipient_list_id => recipient_list.id,
|
||||
:question_list_id => question_list.id
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit schedule form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", school_schedule_path(@school, @schedule), "post" do
|
||||
|
||||
assert_select "input#schedule_name[name=?]", "schedule[name]"
|
||||
|
||||
assert_select "textarea#schedule_description[name=?]", "schedule[description]"
|
||||
|
||||
assert_select "input#schedule_school_id[name=?]", "schedule[school_id]"
|
||||
|
||||
assert_select "input#schedule_frequency_hours[name=?]", "schedule[frequency_hours]"
|
||||
|
||||
assert_select "input#schedule_active[name=?]", "schedule[active]"
|
||||
|
||||
assert_select "input#schedule_random[name=?]", "schedule[random]"
|
||||
|
||||
assert_select "input#schedule_recipient_list_id[name=?]", "schedule[recipient_list_id]"
|
||||
|
||||
assert_select "input#schedule_question_list_id[name=?]", "schedule[question_list_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,46 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schedules/index", type: :view do
|
||||
before(:each) do
|
||||
@question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3])
|
||||
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
@recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school)
|
||||
|
||||
assign(:schedules, [
|
||||
Schedule.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:school_id => @school.id,
|
||||
:frequency_hours => 3,
|
||||
:active => false,
|
||||
:random => false,
|
||||
:recipient_list_id => @recipient_list.id,
|
||||
:question_list_id => @question_list.id
|
||||
),
|
||||
Schedule.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:school_id => @school.id,
|
||||
:frequency_hours => 3,
|
||||
:active => false,
|
||||
:random => true,
|
||||
:recipient_list_id => @recipient_list.id,
|
||||
:question_list_id => @question_list.id,
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of schedules" do
|
||||
render
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "MyText".to_s, :count => 2
|
||||
assert_select "tr>td", :text => @school.name, :count => 2
|
||||
assert_select "tr>td", :text => 3.to_s, :count => 2
|
||||
assert_select "tr>td", :text => false.to_s, :count => 3
|
||||
assert_select "tr>td", :text => true.to_s, :count => 1
|
||||
assert_select "tr>td", :text => @recipient_list.name, :count => 2
|
||||
assert_select "tr>td", :text => @question_list.name, :count => 2
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,45 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schedules/new", type: :view do
|
||||
before(:each) do
|
||||
question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3])
|
||||
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school)
|
||||
|
||||
assign(:schedule, Schedule.new(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:school => @school,
|
||||
:frequency_hours => 1,
|
||||
:active => false,
|
||||
:random => false,
|
||||
:recipient_list => @recipient_list,
|
||||
:question_list => @question_list
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new schedule form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", school_schedules_path(@school), "post" do
|
||||
|
||||
assert_select "input#schedule_name[name=?]", "schedule[name]"
|
||||
|
||||
assert_select "textarea#schedule_description[name=?]", "schedule[description]"
|
||||
|
||||
assert_select "input#schedule_school_id[name=?]", "schedule[school_id]"
|
||||
|
||||
assert_select "input#schedule_frequency_hours[name=?]", "schedule[frequency_hours]"
|
||||
|
||||
assert_select "input#schedule_active[name=?]", "schedule[active]"
|
||||
|
||||
assert_select "input#schedule_random[name=?]", "schedule[random]"
|
||||
|
||||
assert_select "input#schedule_recipient_list_id[name=?]", "schedule[recipient_list_id]"
|
||||
|
||||
assert_select "input#schedule_question_list_id[name=?]", "schedule[question_list_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,34 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "schedules/show", type: :view do
|
||||
before(:each) do
|
||||
@question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3])
|
||||
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
@recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school)
|
||||
|
||||
@schedule = assign(:schedule, Schedule.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:school => @school,
|
||||
:frequency_hours => 3,
|
||||
:active => false,
|
||||
:random => false,
|
||||
:recipient_list => @recipient_list,
|
||||
:question_list => @question_list
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Name/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
expect(rendered).to match(/#{@school.name}/)
|
||||
expect(rendered).to match(/3/)
|
||||
expect(rendered).to match(/false/)
|
||||
expect(rendered).to match(/false/)
|
||||
expect(rendered).to match(/#{@recipient_list.name}/)
|
||||
expect(rendered).to match(/#{@question_list.name}/)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,49 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SchedulesControllerTest < ActionController::TestCase
|
||||
setup do
|
||||
@school = schools(:one)
|
||||
@schedule = schedules(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index, params: { school_id: @school }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get :new, params: { school_id: @school }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create schedule" do
|
||||
assert_difference('Schedule.count') do
|
||||
post :create, params: { school_id: @school, schedule: @schedule.attributes }
|
||||
end
|
||||
|
||||
assert_redirected_to school_schedule_path(@school, Schedule.last)
|
||||
end
|
||||
|
||||
test "should show schedule" do
|
||||
get :show, params: { school_id: @school, id: @schedule }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get :edit, params: { school_id: @school, id: @schedule }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update schedule" do
|
||||
put :update, params: { school_id: @school, id: @schedule, schedule: @schedule.attributes }
|
||||
assert_redirected_to school_schedule_path(@school, Schedule.last)
|
||||
end
|
||||
|
||||
test "should destroy schedule" do
|
||||
assert_difference('Schedule.count', -1) do
|
||||
delete :destroy, params: { school_id: @school, id: @schedule }
|
||||
end
|
||||
|
||||
assert_redirected_to school_schedules_path(@school)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,27 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
school: one
|
||||
name: MyString
|
||||
description: MyText
|
||||
school_id: 1
|
||||
frequency_hours: 1
|
||||
start_date: 2017-03-06
|
||||
end_date: 2017-03-06
|
||||
active: false
|
||||
random: false
|
||||
recipient_list_id: 1
|
||||
question_list_id: 1
|
||||
|
||||
two:
|
||||
school: two
|
||||
name: MyString
|
||||
description: MyText
|
||||
school_id: 1
|
||||
frequency_hours: 1
|
||||
start_date: 2017-03-06
|
||||
end_date: 2017-03-06
|
||||
active: false
|
||||
random: false
|
||||
recipient_list_id: 1
|
||||
question_list_id: 1
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ScheduleTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ScheduleTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Reference in new issue