mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-08 23:18:18 -07:00
working on schedules
This commit is contained in:
parent
72418edd7c
commit
2fb55a7443
26 changed files with 726 additions and 1 deletions
169
spec/controllers/schedules_controller_spec.rb
Normal file
169
spec/controllers/schedules_controller_spec.rb
Normal file
|
|
@ -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
|
||||
45
spec/routing/schedules_routing_spec.rb
Normal file
45
spec/routing/schedules_routing_spec.rb
Normal file
|
|
@ -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
|
||||
45
spec/views/schedules/edit.html.erb_spec.rb
Normal file
45
spec/views/schedules/edit.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||
46
spec/views/schedules/index.html.erb_spec.rb
Normal file
46
spec/views/schedules/index.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||
45
spec/views/schedules/new.html.erb_spec.rb
Normal file
45
spec/views/schedules/new.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||
34
spec/views/schedules/show.html.erb_spec.rb
Normal file
34
spec/views/schedules/show.html.erb_spec.rb
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue