mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-10 07:50:33 -07:00
Extract legacy parts of the codebase into its own module
This commit is contained in:
parent
cf6e80ce6b
commit
413096dfe2
269 changed files with 5549 additions and 5279 deletions
|
|
@ -1,213 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AttemptsController, type: :controller do
|
||||
|
||||
let(:valid_session) { {} }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 2) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:category) { Category.create(name: 'Test Category')}
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let(:schedule) { Schedule.create(name: 'Test Schedule', question_list: question_list, recipient_list: recipient_list) }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
|
||||
let(:recipient_schedule) { RecipientSchedule.create(recipient: recipients.first, schedule: schedule, next_attempt_at: Time.now) }
|
||||
let(:recipient_schedule2) { RecipientSchedule.create(recipient: recipients.last, schedule: schedule, next_attempt_at: Time.now) }
|
||||
|
||||
let!(:first_attempt) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.first,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
let!(:attempt) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.first,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
let!(:attempt2) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.last,
|
||||
recipient_schedule: recipient_schedule2,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
describe "POST #twilio" do
|
||||
context "with valid params" do
|
||||
let(:twilio_attributes) {
|
||||
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => '3','NumMedia' => '0'}
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes
|
||||
end
|
||||
|
||||
it 'creates the first attempt with response for the question' do
|
||||
expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(1)
|
||||
end
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to eq(3)
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.responded_at).to be_present
|
||||
|
||||
expect(first_attempt.answer_index).to be_nil
|
||||
expect(first_attempt.twilio_details).to be_nil
|
||||
expect(first_attempt.responded_at).to be_nil
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
expect(response.body).to eq "We've registered your response of \"Option 0:3 C\". You are the first person to respond to this question. Once more people have responded you will be able to see all responses at: http://test.host/schools/school/categories/test-category"
|
||||
end
|
||||
|
||||
context "with second response" do
|
||||
let(:twilio_attributes2) {
|
||||
{'MessageSid' => 'fwefwefewfewfasfsdfdf','AccountSid' => 'wefwegdbvcbrtnrn','MessagingServiceSid' => 'dfvdfvegbdfb','From' => '+1111111111','To' => '2223334444','Body' => '4','NumMedia' => '0'}
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes2
|
||||
end
|
||||
|
||||
it 'updates the second attempt with response for the school' do
|
||||
expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(2)
|
||||
end
|
||||
|
||||
it "updates the attempt from the second recipient" do
|
||||
attempt2.reload
|
||||
expect(attempt2.answer_index).to eq(4)
|
||||
expect(attempt2.twilio_details).to eq(twilio_attributes2.with_indifferent_access.to_yaml)
|
||||
expect(attempt2.responded_at).to be_present
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
expect(response.body).to eq "We've registered your response of \"Option 0:3 D\". 2 people have responded to this question so far. To see all responses visit: http://test.host/schools/school/categories/test-category"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['stOp', 'cANcel', 'QuIt', 'no'].each do |command|
|
||||
context "with #{command} command" do
|
||||
let(:twilio_attributes) {
|
||||
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
post :twilio, params: twilio_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to be_opted_out
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_attributes
|
||||
expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['staRt', 'reSUme', 'rEstaRt', 'Yes', 'go'].each do |command|
|
||||
context "with #{command} command" do
|
||||
before :each do
|
||||
attempt.recipient.update(opted_out: true)
|
||||
end
|
||||
|
||||
let(:twilio_attributes) {
|
||||
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
expect(attempt.recipient).to be_opted_out
|
||||
post :twilio, params: twilio_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to_not be_opted_out
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_attributes
|
||||
expect(response.body).to eq('Thank you, you will now begin receiving messages again.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['skip', 'i dont know', "i don't know", 'next'].each do |command|
|
||||
context "with #{command} command" do
|
||||
let(:twilio_skip_attributes) {
|
||||
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => command,'NumMedia' => '0'}
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
post :twilio, params: twilio_skip_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.responded_at).to be_present
|
||||
expect(attempt.twilio_details).to eq(twilio_skip_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to_not be_opted_out
|
||||
|
||||
school_attempts = attempt.question.attempts.for_school(school)
|
||||
expect(school_attempts.with_answer.count).to eq(0)
|
||||
expect(school_attempts.with_no_answer.count).to eq(3)
|
||||
expect(school_attempts.not_yet_responded.count).to eq(2)
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_skip_attributes
|
||||
expect(response.body).to eq('Thank you, this question has been skipped.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #twilio with response to repeated question" do
|
||||
context "with valid params" do
|
||||
|
||||
let!(:recent_first_attempt) {
|
||||
first_attempt.update(sent_at: Time.new)
|
||||
return first_attempt
|
||||
}
|
||||
|
||||
let(:twilio_attributes) {
|
||||
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => '2','NumMedia' => '0'}
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes
|
||||
end
|
||||
|
||||
it "updates the first attempt (that now has the most recent sent_at)" do
|
||||
recent_first_attempt.reload
|
||||
expect(recent_first_attempt.answer_index).to eq(2)
|
||||
expect(recent_first_attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(recent_first_attempt.responded_at).to be_present
|
||||
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to be_nil
|
||||
expect(attempt.responded_at).to be_nil
|
||||
|
||||
expect(recent_first_attempt.id).to be < attempt.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,171 +1,17 @@
|
|||
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 CategoriesController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Category. As you add validations to Category, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{name: 'Category', external_id: 'A'}
|
||||
describe CategoriesController, type: :controller do
|
||||
include BasicAuthHelper
|
||||
let(:school) { create(:school) }
|
||||
let(:district) { create(:district) }
|
||||
let!(:categories) {
|
||||
[create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{name: ''}
|
||||
}
|
||||
|
||||
let(:district) {
|
||||
District.create! name: 'District'
|
||||
}
|
||||
|
||||
# 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
|
||||
# CategoriesController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all categories as @categories" do
|
||||
category = Category.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:categories)).to eq([category])
|
||||
end
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
login_as district
|
||||
category = categories.first
|
||||
get :show, params: { id: category.to_param, school_id: school.to_param, district_id: district.to_param }
|
||||
expect(assigns(:categories).map(&:name)).to eql ['First', 'Second']
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested school and category as @school and @category" do
|
||||
school = School.create! name: 'School', district: district
|
||||
category = Category.create! valid_attributes
|
||||
get :show, params: {school_id: school.id, id: category.to_param}, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
|
||||
it "redirects to root_path if school is not provided" do
|
||||
category = Category.create! valid_attributes
|
||||
get :show, params: {id: category.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new category as @category" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:category)).to be_a_new(Category)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested category as @category" do
|
||||
category = Category.create! valid_attributes
|
||||
get :edit, params: {id: category.to_param}, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Category" do
|
||||
expect {
|
||||
post :create, params: {category: valid_attributes}, session: valid_session
|
||||
}.to change(Category, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created category as @category" do
|
||||
post :create, params: {category: valid_attributes}, session: valid_session
|
||||
expect(assigns(:category)).to be_a(Category)
|
||||
expect(assigns(:category)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created category" do
|
||||
post :create, params: {category: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(Category.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved category as @category" do
|
||||
post :create, params: {category: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:category)).to be_a_new(Category)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {category: 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: 'Category 2'}
|
||||
}
|
||||
|
||||
it "updates the requested category" do
|
||||
category = Category.create! valid_attributes
|
||||
put :update, params: {id: category.to_param, category: new_attributes}, session: valid_session
|
||||
category.reload
|
||||
expect(category.name).to eq('Category 2')
|
||||
end
|
||||
|
||||
it "assigns the requested category as @category" do
|
||||
category = Category.create! valid_attributes
|
||||
put :update, params: {id: category.to_param, category: valid_attributes}, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
|
||||
it "redirects to the category" do
|
||||
category = Category.create! valid_attributes
|
||||
put :update, params: {id: category.to_param, category: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(category)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the category as @category" do
|
||||
category = Category.create! valid_attributes
|
||||
put :update, params: {id: category.to_param, category: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
category = Category.create! valid_attributes
|
||||
put :update, params: {id: category.to_param, category: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested category" do
|
||||
category = Category.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: category.to_param}, session: valid_session
|
||||
}.to change(Category, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the categories list" do
|
||||
category = Category.create! valid_attributes
|
||||
delete :destroy, params: {id: category.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(categories_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ describe DashboardController, type: :controller do
|
|||
let(:school) { create(:school) }
|
||||
let(:district) { create(:district) }
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
[create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
|
|
|
|||
|
|
@ -1,140 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
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: 'Milford'}
|
||||
}
|
||||
|
||||
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
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:districts)).to eq(District.all.alphabetic)
|
||||
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
|
||||
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
describe HomeController, type: :controller do
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
[create(:category, name: 'Second', sort_index: 2), create(:category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
|
|
|
|||
214
spec/controllers/legacy/attempts_controller_spec.rb
Normal file
214
spec/controllers/legacy/attempts_controller_spec.rb
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe AttemptsController, type: :controller do
|
||||
|
||||
let(:valid_session) { {} }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 2) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:category) { Legacy::Category.create(name: 'Test Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let(:schedule) { Schedule.create(name: 'Test Schedule', question_list: question_list, recipient_list: recipient_list) }
|
||||
let(:school) { Legacy::School.create!(name: 'School') }
|
||||
|
||||
let(:recipient_schedule) { RecipientSchedule.create(recipient: recipients.first, schedule: schedule, next_attempt_at: Time.now) }
|
||||
let(:recipient_schedule2) { RecipientSchedule.create(recipient: recipients.last, schedule: schedule, next_attempt_at: Time.now) }
|
||||
|
||||
let!(:first_attempt) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.first,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
let!(:attempt) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.first,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
let!(:attempt2) {
|
||||
Attempt.create(
|
||||
schedule: schedule,
|
||||
recipient: recipients.last,
|
||||
recipient_schedule: recipient_schedule2,
|
||||
question: questions.first,
|
||||
sent_at: Time.new
|
||||
)
|
||||
}
|
||||
|
||||
describe "POST #twilio" do
|
||||
context "with valid params" do
|
||||
let(:twilio_attributes) {
|
||||
{ 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '3', 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes
|
||||
end
|
||||
|
||||
it 'creates the first attempt with response for the question' do
|
||||
expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(1)
|
||||
end
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to eq(3)
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.responded_at).to be_present
|
||||
|
||||
expect(first_attempt.answer_index).to be_nil
|
||||
expect(first_attempt.twilio_details).to be_nil
|
||||
expect(first_attempt.responded_at).to be_nil
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
expect(response.body).to eq "We've registered your response of \"Option 0:3 C\". You are the first person to respond to this question. Once more people have responded you will be able to see all responses at: http://test.host/schools/school/categories/test-category"
|
||||
end
|
||||
|
||||
context "with second response" do
|
||||
let(:twilio_attributes2) {
|
||||
{ 'MessageSid' => 'fwefwefewfewfasfsdfdf', 'AccountSid' => 'wefwegdbvcbrtnrn', 'MessagingServiceSid' => 'dfvdfvegbdfb', 'From' => '+1111111111', 'To' => '2223334444', 'Body' => '4', 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes2
|
||||
end
|
||||
|
||||
it 'updates the second attempt with response for the school' do
|
||||
expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(2)
|
||||
end
|
||||
|
||||
it "updates the attempt from the second recipient" do
|
||||
attempt2.reload
|
||||
expect(attempt2.answer_index).to eq(4)
|
||||
expect(attempt2.twilio_details).to eq(twilio_attributes2.with_indifferent_access.to_yaml)
|
||||
expect(attempt2.responded_at).to be_present
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
expect(response.body).to eq "We've registered your response of \"Option 0:3 D\". 2 people have responded to this question so far. To see all responses visit: http://test.host/schools/school/categories/test-category"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['stOp', 'cANcel', 'QuIt', 'no'].each do |command|
|
||||
context "with #{command} command" do
|
||||
let(:twilio_attributes) {
|
||||
{ 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
post :twilio, params: twilio_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to be_opted_out
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_attributes
|
||||
expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['staRt', 'reSUme', 'rEstaRt', 'Yes', 'go'].each do |command|
|
||||
context "with #{command} command" do
|
||||
before :each do
|
||||
attempt.recipient.update(opted_out: true)
|
||||
end
|
||||
|
||||
let(:twilio_attributes) {
|
||||
{ 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
expect(attempt.recipient).to be_opted_out
|
||||
post :twilio, params: twilio_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to_not be_opted_out
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_attributes
|
||||
expect(response.body).to eq('Thank you, you will now begin receiving messages again.')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
['skip', 'i dont know', "i don't know", 'next'].each do |command|
|
||||
context "with #{command} command" do
|
||||
let(:twilio_skip_attributes) {
|
||||
{ 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => command, 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
it "updates the last attempt by recipient phone number" do
|
||||
post :twilio, params: twilio_skip_attributes
|
||||
attempt.reload
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.responded_at).to be_present
|
||||
expect(attempt.twilio_details).to eq(twilio_skip_attributes.with_indifferent_access.to_yaml)
|
||||
expect(attempt.recipient).to_not be_opted_out
|
||||
|
||||
school_attempts = attempt.question.attempts.for_school(school)
|
||||
expect(school_attempts.with_answer.count).to eq(0)
|
||||
expect(school_attempts.with_no_answer.count).to eq(3)
|
||||
expect(school_attempts.not_yet_responded.count).to eq(2)
|
||||
end
|
||||
|
||||
it "sends back a message" do
|
||||
post :twilio, params: twilio_skip_attributes
|
||||
expect(response.body).to eq('Thank you, this question has been skipped.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #twilio with response to repeated question" do
|
||||
context "with valid params" do
|
||||
|
||||
let!(:recent_first_attempt) {
|
||||
first_attempt.update(sent_at: Time.new)
|
||||
return first_attempt
|
||||
}
|
||||
|
||||
let(:twilio_attributes) {
|
||||
{ 'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf', 'AccountSid' => 'wefiuwhefuwehfuwefinwefw', 'MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf', 'From' => '+0000000000', 'To' => '2223334444', 'Body' => '2', 'NumMedia' => '0' }
|
||||
}
|
||||
|
||||
before :each do
|
||||
post :twilio, params: twilio_attributes
|
||||
end
|
||||
|
||||
it "updates the first attempt (that now has the most recent sent_at)" do
|
||||
recent_first_attempt.reload
|
||||
expect(recent_first_attempt.answer_index).to eq(2)
|
||||
expect(recent_first_attempt.twilio_details).to eq(twilio_attributes.with_indifferent_access.to_yaml)
|
||||
expect(recent_first_attempt.responded_at).to be_present
|
||||
|
||||
expect(attempt.answer_index).to be_nil
|
||||
expect(attempt.twilio_details).to be_nil
|
||||
expect(attempt.responded_at).to be_nil
|
||||
|
||||
expect(recent_first_attempt.id).to be < attempt.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
173
spec/controllers/legacy/categories_controller_spec.rb
Normal file
173
spec/controllers/legacy/categories_controller_spec.rb
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe Legacy::CategoriesController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Category. As you add validations to Category, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{ name: 'Category', external_id: 'A' }
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{ name: '' }
|
||||
}
|
||||
|
||||
let(:district) {
|
||||
Legacy::District.create! name: 'District'
|
||||
}
|
||||
|
||||
# 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
|
||||
# CategoriesController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all categories as @categories" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:categories)).to eq([category])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested school and category as @school and @category" do
|
||||
school = Legacy::School.create! name: 'School', district: district
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
get :show, params: { school_id: school.id, id: category.to_param }, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
|
||||
it "redirects to root_path if school is not provided" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
get :show, params: { id: category.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new category as @category" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:category)).to be_a_new(Legacy::Category)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested category as @category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
get :edit, params: { id: category.to_param }, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Category" do
|
||||
expect {
|
||||
post :create, params: { category: valid_attributes }, session: valid_session
|
||||
}.to change(Legacy::Category, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created category as @category" do
|
||||
post :create, params: { category: valid_attributes }, session: valid_session
|
||||
expect(assigns(:category)).to be_a(Legacy::Category)
|
||||
expect(assigns(:category)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created category" do
|
||||
post :create, params: { category: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(Legacy::Category.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved category as @category" do
|
||||
post :create, params: { category: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:category)).to be_a_new(Legacy::Category)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: { category: 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: 'Category 2' }
|
||||
}
|
||||
|
||||
it "updates the requested category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
put :update, params: { id: category.to_param, category: new_attributes }, session: valid_session
|
||||
category.reload
|
||||
expect(category.name).to eq('Category 2')
|
||||
end
|
||||
|
||||
it "assigns the requested category as @category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
put :update, params: { id: category.to_param, category: valid_attributes }, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
|
||||
it "redirects to the category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
put :update, params: { id: category.to_param, category: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(category)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the category as @category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
put :update, params: { id: category.to_param, category: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:category)).to eq(category)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
put :update, params: { id: category.to_param, category: invalid_attributes }, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested category" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: { id: category.to_param }, session: valid_session
|
||||
}.to change(Legacy::Category, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the categories list" do
|
||||
category = Legacy::Category.create! valid_attributes
|
||||
delete :destroy, params: { id: category.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_categories_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
142
spec/controllers/legacy/districts_controller_spec.rb
Normal file
142
spec/controllers/legacy/districts_controller_spec.rb
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
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: 'Milford' }
|
||||
}
|
||||
|
||||
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
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:districts)).to eq(District.all.alphabetic)
|
||||
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
|
||||
end
|
||||
161
spec/controllers/legacy/question_lists_controller_spec.rb
Normal file
161
spec/controllers/legacy/question_lists_controller_spec.rb
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe QuestionListsController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# QuestionList. As you add validations to QuestionList, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{ name: 'Questions for Parents', question_id_array: ['', '1', '2', '3'] }
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{ question_id_array: [''] }
|
||||
}
|
||||
|
||||
# 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
|
||||
# QuestionListsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all question_lists as @question_lists" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:question_lists)).to eq([question_list])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :show, params: { id: question_list.to_param }, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new question_list as @question_list" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a_new(QuestionList)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :edit, params: { id: question_list.to_param }, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new QuestionList" do
|
||||
expect {
|
||||
post :create, params: { question_list: valid_attributes }, session: valid_session
|
||||
}.to change(QuestionList, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created question_list as @question_list" do
|
||||
post :create, params: { question_list: valid_attributes }, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a(QuestionList)
|
||||
expect(assigns(:question_list)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created question_list" do
|
||||
post :create, params: { question_list: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(QuestionList.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved question_list as @question_list" do
|
||||
post :create, params: { question_list: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a_new(QuestionList)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: { question_list: 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) {
|
||||
{ question_id_array: ['', '2', '3'] }
|
||||
}
|
||||
|
||||
it "updates the requested question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: { id: question_list.to_param, question_list: new_attributes }, session: valid_session
|
||||
question_list.reload
|
||||
expect(question_list.question_ids).to eq('2,3')
|
||||
end
|
||||
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: { id: question_list.to_param, question_list: valid_attributes }, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
|
||||
it "redirects to the question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: { id: question_list.to_param, question_list: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: { id: question_list.to_param, question_list: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: { id: question_list.to_param, question_list: invalid_attributes }, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: { id: question_list.to_param }, session: valid_session
|
||||
}.to change(QuestionList, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the question_lists list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
delete :destroy, params: { id: question_list.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_question_lists_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
177
spec/controllers/legacy/questions_controller_spec.rb
Normal file
177
spec/controllers/legacy/questions_controller_spec.rb
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe QuestionsController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Question. As you add validations to Question, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let (:category) { Legacy::Category.create!(name: 'Category') }
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
text: 'Question',
|
||||
option1: 'option1',
|
||||
option2: 'option2',
|
||||
option3: 'option3',
|
||||
option4: 'option4',
|
||||
option5: 'option5',
|
||||
category_id: category.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{ text: '' }
|
||||
}
|
||||
|
||||
# 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
|
||||
# QuestionsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all questions as @questions" do
|
||||
question = Question.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:questions)).to eq([question])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested question as @question" do
|
||||
school = School.create!(name: 'School')
|
||||
question = Question.create! valid_attributes
|
||||
get :show, params: { school_id: school.id, id: question.to_param }, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new question as @question" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:question)).to be_a_new(Question)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
get :edit, params: { id: question.to_param }, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Question" do
|
||||
expect {
|
||||
post :create, params: { question: valid_attributes }, session: valid_session
|
||||
}.to change(Question, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created question as @question" do
|
||||
post :create, params: { question: valid_attributes }, session: valid_session
|
||||
expect(assigns(:question)).to be_a(Question)
|
||||
expect(assigns(:question)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created question" do
|
||||
post :create, params: { question: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(Question.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved question as @question" do
|
||||
post :create, params: { question: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:question)).to be_a_new(Question)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: { question: 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) {
|
||||
{ text: 'Question2' }
|
||||
}
|
||||
|
||||
it "updates the requested question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: { id: question.to_param, question: new_attributes }, session: valid_session
|
||||
question.reload
|
||||
expect(question.text).to eq('Question2')
|
||||
end
|
||||
|
||||
it "assigns the requested question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: { id: question.to_param, question: valid_attributes }, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
|
||||
it "redirects to the question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: { id: question.to_param, question: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(question)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: { id: question.to_param, question: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: { id: question.to_param, question: invalid_attributes }, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested question" do
|
||||
question = Question.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: { id: question.to_param }, session: valid_session
|
||||
}.to change(Question, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the questions list" do
|
||||
question = Question.create! valid_attributes
|
||||
delete :destroy, params: { id: question.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_questions_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
179
spec/controllers/legacy/recipient_lists_controller_spec.rb
Normal file
179
spec/controllers/legacy/recipient_lists_controller_spec.rb
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe RecipientListsController, type: :controller do
|
||||
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# RecipientList. As you add validations to RecipientList, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
school_id: school.id,
|
||||
recipient_id_array: ['', '1', '2', '3'],
|
||||
name: 'Parents',
|
||||
description: 'List of parents.'
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{ school_id: school.id, 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
|
||||
# RecipientListsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all recipient_lists as @recipient_lists" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :index, params: { school_id: school.to_param }, session: valid_session
|
||||
expect(assigns(:recipient_lists)).to eq([recipient_list])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :show, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new recipient_list as @recipient_list" do
|
||||
get :new, params: { school_id: school.to_param }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :edit, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new RecipientList" do
|
||||
expect {
|
||||
post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
}.to change(RecipientList, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created recipient_list as @recipient_list" do
|
||||
post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a(RecipientList)
|
||||
expect(assigns(:recipient_list)).to be_persisted
|
||||
end
|
||||
|
||||
it 'stores recipient_ids properly' do
|
||||
post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient_list).recipient_ids).to eq('1,2,3')
|
||||
end
|
||||
|
||||
it "redirects to the created recipient_list" do
|
||||
post :create, params: { school_id: school.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_school_legacy_recipient_list_path(school, RecipientList.last))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved recipient_list as @recipient_list" do
|
||||
post :create, params: { school_id: school.to_param, recipient_list: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: { school_id: school.to_param, recipient_list: 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) {
|
||||
{ recipient_id_array: ['', '3', '4', '5'] }
|
||||
}
|
||||
|
||||
it "updates the requested recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: new_attributes }, session: valid_session
|
||||
recipient_list.reload
|
||||
expect(recipient_list.recipient_ids).to eq('3,4,5')
|
||||
end
|
||||
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
|
||||
it "redirects to the recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_school_legacy_recipient_list_url(school, recipient_list))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes }, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session
|
||||
}.to change(RecipientList, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the recipient_lists list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
delete :destroy, params: { school_id: school.to_param, id: recipient_list.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
172
spec/controllers/legacy/recipients_controller_spec.rb
Normal file
172
spec/controllers/legacy/recipients_controller_spec.rb
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe RecipientsController, type: :controller do
|
||||
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Recipient. As you add validations to Recipient, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
name: 'Recipient Name',
|
||||
phone: '111-222-3333',
|
||||
school_id: school.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) { { name: '', phone: '111-222-3333' } }
|
||||
|
||||
# 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
|
||||
# RecipientsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all recipients as @recipients" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :index, params: { school_id: school.to_param }, session: valid_session
|
||||
expect(assigns(:recipients)).to eq([recipient])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :show, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new recipient as @recipient" do
|
||||
get :new, params: { school_id: school.id }, session: valid_session
|
||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :edit, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Recipient" do
|
||||
expect {
|
||||
post :create, params: { school_id: school.to_param, recipient: valid_attributes }, session: valid_session
|
||||
}.to change(Recipient, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created recipient as @recipient" do
|
||||
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_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created recipient" do
|
||||
post :create, params: { school_id: school.to_param, recipient: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_school_legacy_recipient_path(school, Recipient.last))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved recipient as @recipient" do
|
||||
post :create, params: { school_id: school.to_param, recipient: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: { school_id: school.to_param, recipient: 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 recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: new_attributes }, session: valid_session
|
||||
recipient.reload
|
||||
expect(recipient.name).to eq('New Name')
|
||||
expect(recipient.phone).to eq('111-222-3333')
|
||||
end
|
||||
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
|
||||
it "redirects to the recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes }, session: valid_session
|
||||
expect(response).to redirect_to(legacy_school_legacy_recipient_url(school, recipient))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: { school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes }, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session
|
||||
}.to change(Recipient, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the recipients list" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
delete :destroy, params: { school_id: school.to_param, id: recipient.to_param }, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
184
spec/controllers/legacy/schedules_controller_spec.rb
Normal file
184
spec/controllers/legacy/schedules_controller_spec.rb
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
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.
|
||||
|
||||
module Legacy
|
||||
RSpec.describe SchedulesController, type: :controller do
|
||||
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
# 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',
|
||||
time: (8 * 60)
|
||||
}
|
||||
}
|
||||
|
||||
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) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
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 "updates the schedule's time to UTC from EST" do
|
||||
post :create, params: { school_id: school.id, schedule: valid_attributes }, session: valid_session
|
||||
expect(assigns(:schedule)).to be_a(Schedule)
|
||||
expect(assigns(:schedule).time).to eq(60 * 12)
|
||||
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
|
||||
end
|
||||
|
|
@ -18,16 +18,17 @@ require 'rails_helper'
|
|||
# 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
|
||||
module Legacy
|
||||
RSpec.describe SchoolsController, type: :controller do
|
||||
|
||||
let(:district) { District.create! name: 'District' }
|
||||
let!(:school) { School.create! name: 'school', district: district }
|
||||
let!(:user) { User.create(email: 'test@example.com', password: '123456') }
|
||||
let!(:user_school) { user.user_schools.create(school: school) }
|
||||
let(:district) { District.create! name: 'District' }
|
||||
let!(:school) { School.create! name: 'school', district: district }
|
||||
let!(:user) { User.create(email: 'test@example.com', password: '123456') }
|
||||
let!(:user_school) { user.user_schools.create(school: school) }
|
||||
|
||||
# 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.
|
||||
# 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', district: district}
|
||||
}
|
||||
|
|
@ -176,8 +177,9 @@ RSpec.describe SchoolsController, type: :controller do
|
|||
|
||||
it "redirects to the schools list" do
|
||||
delete :destroy, params: {id: school.to_param}
|
||||
expect(response).to redirect_to(schools_url)
|
||||
expect(response).to redirect_to(legacy_schools_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
13
spec/controllers/legacy/welcome_controller_spec.rb
Normal file
13
spec/controllers/legacy/welcome_controller_spec.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe WelcomeController, type: :controller do
|
||||
|
||||
describe "GET #index" do
|
||||
it "works" do
|
||||
get :index
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
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 QuestionListsController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# QuestionList. As you add validations to QuestionList, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{name: 'Questions for Parents', question_id_array: ['', '1', '2', '3']}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{question_id_array: ['']}
|
||||
}
|
||||
|
||||
# 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
|
||||
# QuestionListsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all question_lists as @question_lists" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:question_lists)).to eq([question_list])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :show, params: {id: question_list.to_param}, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new question_list as @question_list" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a_new(QuestionList)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
get :edit, params: {id: question_list.to_param}, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new QuestionList" do
|
||||
expect {
|
||||
post :create, params: {question_list: valid_attributes}, session: valid_session
|
||||
}.to change(QuestionList, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created question_list as @question_list" do
|
||||
post :create, params: {question_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a(QuestionList)
|
||||
expect(assigns(:question_list)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created question_list" do
|
||||
post :create, params: {question_list: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(QuestionList.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved question_list as @question_list" do
|
||||
post :create, params: {question_list: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:question_list)).to be_a_new(QuestionList)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {question_list: 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) {
|
||||
{question_id_array: ['', '2', '3']}
|
||||
}
|
||||
|
||||
it "updates the requested question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: {id: question_list.to_param, question_list: new_attributes}, session: valid_session
|
||||
question_list.reload
|
||||
expect(question_list.question_ids).to eq('2,3')
|
||||
end
|
||||
|
||||
it "assigns the requested question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: {id: question_list.to_param, question_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
|
||||
it "redirects to the question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: {id: question_list.to_param, question_list: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(question_list)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the question_list as @question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: {id: question_list.to_param, question_list: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:question_list)).to eq(question_list)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
put :update, params: {id: question_list.to_param, question_list: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested question_list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: question_list.to_param}, session: valid_session
|
||||
}.to change(QuestionList, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the question_lists list" do
|
||||
question_list = QuestionList.create! valid_attributes
|
||||
delete :destroy, params: {id: question_list.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(question_lists_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
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 QuestionsController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Question. As you add validations to Question, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let (:category) { Category.create!(name: 'Category') }
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
text: 'Question',
|
||||
option1: 'option1',
|
||||
option2: 'option2',
|
||||
option3: 'option3',
|
||||
option4: 'option4',
|
||||
option5: 'option5',
|
||||
category_id: category.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{text: ''}
|
||||
}
|
||||
|
||||
# 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
|
||||
# QuestionsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all questions as @questions" do
|
||||
question = Question.create! valid_attributes
|
||||
get :index, params: {}, session: valid_session
|
||||
expect(assigns(:questions)).to eq([question])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested question as @question" do
|
||||
school = School.create!(name: 'School')
|
||||
question = Question.create! valid_attributes
|
||||
get :show, params: {school_id: school.id, id: question.to_param}, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
expect(assigns(:school)).to eq(school)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new question as @question" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(assigns(:question)).to be_a_new(Question)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
get :edit, params: {id: question.to_param}, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Question" do
|
||||
expect {
|
||||
post :create, params: {question: valid_attributes}, session: valid_session
|
||||
}.to change(Question, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created question as @question" do
|
||||
post :create, params: {question: valid_attributes}, session: valid_session
|
||||
expect(assigns(:question)).to be_a(Question)
|
||||
expect(assigns(:question)).to be_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created question" do
|
||||
post :create, params: {question: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(Question.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved question as @question" do
|
||||
post :create, params: {question: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:question)).to be_a_new(Question)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {question: 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) {
|
||||
{text: 'Question2'}
|
||||
}
|
||||
|
||||
it "updates the requested question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: {id: question.to_param, question: new_attributes}, session: valid_session
|
||||
question.reload
|
||||
expect(question.text).to eq('Question2')
|
||||
end
|
||||
|
||||
it "assigns the requested question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: {id: question.to_param, question: valid_attributes}, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
|
||||
it "redirects to the question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: {id: question.to_param, question: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(question)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the question as @question" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: {id: question.to_param, question: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:question)).to eq(question)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
question = Question.create! valid_attributes
|
||||
put :update, params: {id: question.to_param, question: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested question" do
|
||||
question = Question.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: question.to_param}, session: valid_session
|
||||
}.to change(Question, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the questions list" do
|
||||
question = Question.create! valid_attributes
|
||||
delete :destroy, params: {id: question.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(questions_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
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 RecipientListsController, type: :controller do
|
||||
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# RecipientList. As you add validations to RecipientList, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
school_id: school.id,
|
||||
recipient_id_array: ['', '1', '2', '3'],
|
||||
name: 'Parents',
|
||||
description: 'List of parents.'
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) {
|
||||
{school_id: school.id, 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
|
||||
# RecipientListsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all recipient_lists as @recipient_lists" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :index, params: {school_id: school.to_param}, session: valid_session
|
||||
expect(assigns(:recipient_lists)).to eq([recipient_list])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :show, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new recipient_list as @recipient_list" do
|
||||
get :new, params: {school_id: school.to_param}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
get :edit, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new RecipientList" do
|
||||
expect {
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
}.to change(RecipientList, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created recipient_list as @recipient_list" do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a(RecipientList)
|
||||
expect(assigns(:recipient_list)).to be_persisted
|
||||
end
|
||||
|
||||
it 'stores recipient_ids properly' do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list).recipient_ids).to eq('1,2,3')
|
||||
end
|
||||
|
||||
it "redirects to the created recipient_list" do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school_recipient_list_path(school, RecipientList.last))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved recipient_list as @recipient_list" do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to be_a_new(RecipientList)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {school_id: school.to_param, recipient_list: 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) {
|
||||
{recipient_id_array: ['', '3', '4', '5']}
|
||||
}
|
||||
|
||||
it "updates the requested recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: new_attributes}, session: valid_session
|
||||
recipient_list.reload
|
||||
expect(recipient_list.recipient_ids).to eq('3,4,5')
|
||||
end
|
||||
|
||||
it "assigns the requested recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
|
||||
it "redirects to the recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school_recipient_list_url(school, recipient_list))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the recipient_list as @recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient_list)).to eq(recipient_list)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient_list.to_param, recipient_list: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested recipient_list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
|
||||
}.to change(RecipientList, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the recipient_lists list" do
|
||||
recipient_list = RecipientList.create! valid_attributes
|
||||
delete :destroy, params: {school_id: school.to_param, id: recipient_list.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
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 RecipientsController, type: :controller do
|
||||
|
||||
let!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# Recipient. As you add validations to Recipient, be sure to
|
||||
# adjust the attributes here as well.
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
name: 'Recipient Name',
|
||||
phone: '111-222-3333',
|
||||
school_id: school.id
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_attributes) { {name: '', phone: '111-222-3333'} }
|
||||
|
||||
# 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
|
||||
# RecipientsController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "GET #index" do
|
||||
it "assigns all recipients as @recipients" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :index, params: {school_id: school.to_param}, session: valid_session
|
||||
expect(assigns(:recipients)).to eq([recipient])
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :show, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a new recipient as @recipient" do
|
||||
get :new, params: {school_id: school.id}, session: valid_session
|
||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
get :edit, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new Recipient" do
|
||||
expect {
|
||||
post :create, params: {school_id: school.to_param, recipient: valid_attributes}, session: valid_session
|
||||
}.to change(Recipient, :count).by(1)
|
||||
end
|
||||
|
||||
it "assigns a newly created recipient as @recipient" do
|
||||
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_persisted
|
||||
end
|
||||
|
||||
it "redirects to the created recipient" do
|
||||
post :create, params: {school_id: school.to_param, recipient: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school_recipient_path(school, Recipient.last))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns a newly created but unsaved recipient as @recipient" do
|
||||
post :create, params: {school_id: school.to_param, recipient: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient)).to be_a_new(Recipient)
|
||||
end
|
||||
|
||||
it "re-renders the 'new' template" do
|
||||
post :create, params: {school_id: school.to_param, recipient: 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 recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient.to_param, recipient: new_attributes}, session: valid_session
|
||||
recipient.reload
|
||||
expect(recipient.name).to eq('New Name')
|
||||
expect(recipient.phone).to eq('111-222-3333')
|
||||
end
|
||||
|
||||
it "assigns the requested recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
|
||||
it "redirects to the recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient.to_param, recipient: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(school_recipient_url(school, recipient))
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "assigns the recipient as @recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes}, session: valid_session
|
||||
expect(assigns(:recipient)).to eq(recipient)
|
||||
end
|
||||
|
||||
it "re-renders the 'edit' template" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
put :update, params: {school_id: school.to_param, id: recipient.to_param, recipient: invalid_attributes}, session: valid_session
|
||||
expect(response).to render_template("edit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested recipient" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||
}.to change(Recipient, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the recipients list" do
|
||||
recipient = Recipient.create! valid_attributes
|
||||
delete :destroy, params: {school_id: school.to_param, id: recipient.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(school)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,182 +0,0 @@
|
|||
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!(:user) { User.create(email: 'test@test.com', password: '123456') }
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
# 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',
|
||||
time: (8 * 60)
|
||||
}
|
||||
}
|
||||
|
||||
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) { {} }
|
||||
|
||||
before :each do
|
||||
user.user_schools.create(school: school)
|
||||
sign_in user
|
||||
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 "updates the schedule's time to UTC from EST" do
|
||||
post :create, params: {school_id: school.id, schedule: valid_attributes}, session: valid_session
|
||||
expect(assigns(:schedule)).to be_a(Schedule)
|
||||
expect(assigns(:schedule).time).to eq(60 * 12)
|
||||
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
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe SqmCategoriesController, type: :controller do
|
||||
include BasicAuthHelper
|
||||
let(:school) { create(:school) }
|
||||
let(:district) { create(:district) }
|
||||
let!(:categories) {
|
||||
[create(:sqm_category, name: 'Second', sort_index: 2), create(:sqm_category, name: 'First', sort_index: 1)]
|
||||
}
|
||||
|
||||
it 'fetches categories sorted by sort_index' do
|
||||
login_as district
|
||||
category = categories.first
|
||||
get :show, params: { id: category.to_param, school_id: school.to_param, district_id: district.to_param }
|
||||
expect(assigns(:categories).map(&:name)).to eql ['First', 'Second']
|
||||
end
|
||||
end
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe WelcomeController, type: :controller do
|
||||
|
||||
describe "GET #index" do
|
||||
it "works" do
|
||||
get :index
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -16,7 +16,7 @@ FactoryBot.define do
|
|||
initialize_with { AcademicYear.find_or_initialize_by(range: range) }
|
||||
end
|
||||
|
||||
factory :sqm_category do
|
||||
factory :category, class: 'Category' do
|
||||
name { "A #{rand} category" }
|
||||
category_id { rand.to_s }
|
||||
description { "A description of a category" }
|
||||
|
|
@ -28,7 +28,7 @@ FactoryBot.define do
|
|||
name { "A subcategory" }
|
||||
subcategory_id { rand.to_s }
|
||||
description { "A description of a subcategory" }
|
||||
sqm_category
|
||||
category
|
||||
|
||||
factory :subcategory_with_measures do
|
||||
transient do
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ describe Seeder do
|
|||
|
||||
context 'the sqm framework' do
|
||||
before do
|
||||
school_culture_category = create(:sqm_category, category_id: '2', sort_index: -1)
|
||||
safety_subcategory = create(:subcategory, subcategory_id: '2A', sqm_category: school_culture_category)
|
||||
school_culture_category = create(:category, category_id: '2', sort_index: -1)
|
||||
safety_subcategory = create(:subcategory, subcategory_id: '2A', category: school_culture_category)
|
||||
student_physical_safety_measure = create(:measure, measure_id: '2A-i', subcategory: safety_subcategory)
|
||||
create(:survey_item, survey_item_id: 's-phys-q1', measure: student_physical_safety_measure)
|
||||
create(:admin_data_item, admin_data_item_id: 'a-phys-i1', measure: student_physical_safety_measure)
|
||||
|
|
@ -97,7 +97,7 @@ describe Seeder do
|
|||
it 'creates new objects as necessary' do
|
||||
expect {
|
||||
seeder.seed_sqm_framework sample_sqm_framework_csv
|
||||
}.to change { SqmCategory.count }.by(4)
|
||||
}.to change { Category.count }.by(4)
|
||||
.and change { Subcategory.count }.by(15)
|
||||
.and change { Measure.count }.by(31)
|
||||
.and change { SurveyItem.count }.by(136)
|
||||
|
|
@ -111,15 +111,15 @@ describe Seeder do
|
|||
|
||||
it 'updates category data' do
|
||||
seeder.seed_sqm_framework sample_sqm_framework_csv
|
||||
teachers_leadership = SqmCategory.find_by_name 'Teachers & Leadership'
|
||||
teachers_leadership = Category.find_by_name 'Teachers & Leadership'
|
||||
|
||||
expect(teachers_leadership.slug).to eq 'teachers-and-leadership'
|
||||
expect(teachers_leadership.description).to eq "This is a category description."
|
||||
end
|
||||
|
||||
it 'updates category sort index to match a predefined order' do
|
||||
teachers_leadership = SqmCategory.find_by_name 'Teachers & Leadership'
|
||||
school_culture = SqmCategory.find_by_name 'School Culture'
|
||||
teachers_leadership = Category.find_by_name 'Teachers & Leadership'
|
||||
school_culture = Category.find_by_name 'School Culture'
|
||||
|
||||
expect(teachers_leadership.sort_index).to eq 0
|
||||
expect(school_culture.sort_index).to eq 1
|
||||
|
|
|
|||
|
|
@ -1,350 +1,99 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe "survey:attempt_questions" do
|
||||
include_context "rake"
|
||||
module Legacy
|
||||
describe "survey:attempt_questions" do
|
||||
include_context "rake"
|
||||
|
||||
it 'should have environment as a prerequisite' do
|
||||
expect(subject.prerequisites).to include("environment")
|
||||
end
|
||||
|
||||
describe "basic flow" do
|
||||
let(:now) {
|
||||
n = DateTime.now
|
||||
n += 1.day until n.on_weekday?
|
||||
return n
|
||||
}
|
||||
|
||||
let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) }
|
||||
let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) }
|
||||
let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) }
|
||||
|
||||
it "finds all active schedules" do
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date)
|
||||
|
||||
expect(ready_recipient_schedule).to receive(:attempt_question)
|
||||
expect(active_schedule).to receive(:recipient_schedules)
|
||||
expect(Schedule).to receive(:active).and_return([active_schedule])
|
||||
subject.invoke
|
||||
it 'should have environment as a prerequisite' do
|
||||
expect(subject.prerequisites).to include("environment")
|
||||
end
|
||||
|
||||
it "works only on weekdays" do
|
||||
now = DateTime.now
|
||||
now += 1.day until now.on_weekend?
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date)
|
||||
describe "basic flow" do
|
||||
let(:now) {
|
||||
n = DateTime.now
|
||||
n += 1.day until n.on_weekday?
|
||||
return n
|
||||
}
|
||||
|
||||
expect(ready_recipient_schedule).to_not receive(:attempt_question)
|
||||
subject.invoke
|
||||
end
|
||||
end
|
||||
let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) }
|
||||
let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) }
|
||||
let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) }
|
||||
|
||||
xdescribe "complex flow" do
|
||||
let(:now) {
|
||||
n = DateTime.now
|
||||
n += 1.day until n.on_weekday?
|
||||
return n
|
||||
}
|
||||
it "finds all active schedules" do
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date)
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
expect(ready_recipient_schedule).to receive(:attempt_question)
|
||||
expect(active_schedule).to receive(:recipient_schedules)
|
||||
expect(Schedule).to receive(:active).and_return([active_schedule])
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:category) { Category.create(name: 'Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
frequency_hours: 24 * 7,
|
||||
start_date: Time.new,
|
||||
end_date: 1.year.from_now,
|
||||
time: 1200
|
||||
)
|
||||
end
|
||||
|
||||
describe 'First attempt not at specified time' do
|
||||
before :each do
|
||||
now = DateTime.new
|
||||
it "works only on weekdays" do
|
||||
now = DateTime.now
|
||||
now += 1.day until now.on_weekend?
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should not create any attempts' do
|
||||
expect(Attempt.count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'First attempt at specified time' do
|
||||
before :each do
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
Timecop.freeze(date)
|
||||
|
||||
it 'should create the first attempt for each recipient' do
|
||||
recipients.each do |recipient|
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
attempt = recipient.attempts.first
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
expect(ready_recipient_schedule).to_not receive(:attempt_question)
|
||||
subject.invoke
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Second Attempts' do
|
||||
before :each do
|
||||
recipients.each do |recipient|
|
||||
recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first
|
||||
recipient_schedule.attempt_question
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Immediate' do
|
||||
before :each do
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should do nothing' do
|
||||
recipients.each do |recipient|
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'A Week Later' do
|
||||
before :each do
|
||||
recipients[1].attempts.first.update(
|
||||
answer_index: 4,
|
||||
responded_at: Time.new
|
||||
)
|
||||
Timecop.freeze(now + 7) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should resend the first question if unanswered by a recipient' do
|
||||
[recipients[0], recipients[2]].each do |recipient|
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be > 1.day.ago
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'should create the second attempt with a new question for each recipient who has answered the first question' do
|
||||
recipient = recipients[1]
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(2)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
|
||||
first_attempt = recipient.attempts.first
|
||||
expect(first_attempt.question).to_not eq(attempt.question)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'And Then A Recipient Answers The First Attempt' do
|
||||
before :each do
|
||||
recipients[1].attempts.first.save_response(answer_index: 4)
|
||||
|
||||
Timecop.freeze(now + 7)
|
||||
recipients.each do |recipient|
|
||||
recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first
|
||||
recipient_schedule.attempt_question
|
||||
end
|
||||
|
||||
@existing_message_count = FakeSMS.messages.length
|
||||
|
||||
Timecop.freeze(now + 8)
|
||||
recipients[2].attempts.first.save_response(answer_index: 3)
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should create the second attempt with a new question for each recipient who just answered the first question' do
|
||||
recipient = recipients[2]
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(2)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
|
||||
first_attempt = recipient.attempts.first
|
||||
expect(first_attempt.question).to_not eq(attempt.question)
|
||||
end
|
||||
|
||||
it 'should not send anything to anyone else' do
|
||||
expect(FakeSMS.messages.length).to eq(@existing_message_count + 2)
|
||||
expect(recipients[0].attempts.count).to eq(1)
|
||||
expect(recipients[1].attempts.count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Multiple Students In A Family' do
|
||||
|
||||
before :each do
|
||||
3.times do |i|
|
||||
recipients[1].students.create(name: "Student#{i}")
|
||||
end
|
||||
end
|
||||
|
||||
let(:students_recipient) { recipients[1] }
|
||||
let(:students_recipient_schedule) {
|
||||
students_recipient.recipient_schedules.for_schedule(schedule).first
|
||||
xdescribe "complex flow" do
|
||||
let(:now) {
|
||||
n = DateTime.now
|
||||
n += 1.day until n.on_weekday?
|
||||
return n
|
||||
}
|
||||
|
||||
describe 'With A FOR_CHILD Question Is Asked' do
|
||||
let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) }
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:category) { Category.create(name: 'Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
frequency_hours: 24 * 7,
|
||||
start_date: Time.new,
|
||||
end_date: 1.year.from_now,
|
||||
time: 1200
|
||||
)
|
||||
end
|
||||
|
||||
describe 'First attempt not at specified time' do
|
||||
before :each do
|
||||
questions.first.update(for_recipient_students: true)
|
||||
now = DateTime.new
|
||||
now += 1.day until now.on_weekend?
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create one attempt per recipient regardless of students' do
|
||||
expect(FakeSMS.messages.length).to eq(6)
|
||||
recipients.each do |recipient|
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
it 'should not create any attempts' do
|
||||
expect(Attempt.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'should store queued questions when an attempt is made on first student' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_present
|
||||
queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/)
|
||||
expect(queued_question_ids.length).to eq(1)
|
||||
expect(queued_question_ids.first).to eq("#{questions[0].id}")
|
||||
end
|
||||
|
||||
it 'should set the next_attempt_at to now when attempt is made on first student' do
|
||||
students_recipient.attempts.last.save_response(answer_index: 3)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new)
|
||||
end
|
||||
|
||||
it 'should set the next_attempt_at in the future when an attempts are made on each student' do
|
||||
students_recipient.attempts.last.save_response(answer_index: 3)
|
||||
expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1)
|
||||
expect(students_recipient_schedule.reload.queued_question_ids).to be_present
|
||||
|
||||
attempt = students_recipient.attempts.last
|
||||
expect(attempt.student).to eq(students_recipient.students[1])
|
||||
|
||||
Timecop.freeze(date + 1.day)
|
||||
attempt.save_response(answer_index: 4)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day)
|
||||
|
||||
expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1)
|
||||
expect(students_recipient_schedule.reload.queued_question_ids).to be_nil
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours))
|
||||
|
||||
attempt = students_recipient.attempts.last
|
||||
expect(attempt.student).to eq(students_recipient.students[2])
|
||||
|
||||
Timecop.freeze(date + 2.days)
|
||||
attempt.save_response(answer_index: 2)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days)
|
||||
end
|
||||
|
||||
it 'should mention the students name in the text' do
|
||||
expect(FakeSMS.messages[2].body).to match(/\(for Student0\)/)
|
||||
end
|
||||
|
||||
it 'should not mention the students name in the text if the recipient has no student specified' do
|
||||
expect(FakeSMS.messages[0].body).to_not match(/\(for .*\)/)
|
||||
end
|
||||
|
||||
it 'resends the question about the same student if not responded to' do
|
||||
message_count = FakeSMS.messages.length
|
||||
expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(0)
|
||||
expect(FakeSMS.messages.length).to eq(message_count + 2)
|
||||
expect(FakeSMS.messages[message_count].body).to match(questions.first.text)
|
||||
expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/)
|
||||
end
|
||||
|
||||
it 'doesnt store any queued_question_ids when no students are present' do
|
||||
recipient_schedule = recipients[0].recipient_schedules.for_schedule(schedule).first
|
||||
expect(recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'With A General Question Is Asked' do
|
||||
describe 'First attempt at specified time' do
|
||||
before :each do
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should not queue up an questions regardless of how many students there are' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
|
||||
it 'should not mention the students name in the text' do
|
||||
FakeSMS.messages.each do |message|
|
||||
expect(message.body).to_not match(/\(for .*\)/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'One Student In A Family' do
|
||||
|
||||
before :each do
|
||||
recipients[1].students.create(name: "Only Student")
|
||||
end
|
||||
|
||||
let(:students_recipient) { recipients[1] }
|
||||
let(:students_recipient_schedule) {
|
||||
students_recipient.recipient_schedules.for_schedule(schedule).first
|
||||
}
|
||||
|
||||
describe 'With A FOR_CHILD Question Is Asked' do
|
||||
let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) }
|
||||
|
||||
before :each do
|
||||
questions.first.update(for_recipient_students: true)
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create one attempt per recipient regardless of students' do
|
||||
expect(FakeSMS.messages.length).to eq(6)
|
||||
it 'should create the first attempt for each recipient' do
|
||||
recipients.each do |recipient|
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'doesnt store any queued_question_ids' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Opted Out Recipient' do
|
||||
|
||||
before :each do
|
||||
recipients[1].update(opted_out: true)
|
||||
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create the first attempt for each recipient' do
|
||||
recipients.each_with_index do |recipient, index|
|
||||
recipient.reload
|
||||
if index == 1
|
||||
expect(recipient.attempts.count).to eq(0)
|
||||
expect(recipient.attempts.first).to be_nil
|
||||
else
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
attempt = recipient.attempts.first
|
||||
expect(attempt.sent_at).to be_present
|
||||
|
|
@ -352,7 +101,259 @@ describe "survey:attempt_questions" do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Second Attempts' do
|
||||
before :each do
|
||||
recipients.each do |recipient|
|
||||
recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first
|
||||
recipient_schedule.attempt_question
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Immediate' do
|
||||
before :each do
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should do nothing' do
|
||||
recipients.each do |recipient|
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'A Week Later' do
|
||||
before :each do
|
||||
recipients[1].attempts.first.update(
|
||||
answer_index: 4,
|
||||
responded_at: Time.new
|
||||
)
|
||||
Timecop.freeze(now + 7) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should resend the first question if unanswered by a recipient' do
|
||||
[recipients[0], recipients[2]].each do |recipient|
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be > 1.day.ago
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'should create the second attempt with a new question for each recipient who has answered the first question' do
|
||||
recipient = recipients[1]
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(2)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
|
||||
first_attempt = recipient.attempts.first
|
||||
expect(first_attempt.question).to_not eq(attempt.question)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'And Then A Recipient Answers The First Attempt' do
|
||||
before :each do
|
||||
recipients[1].attempts.first.save_response(answer_index: 4)
|
||||
|
||||
Timecop.freeze(now + 7)
|
||||
recipients.each do |recipient|
|
||||
recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first
|
||||
recipient_schedule.attempt_question
|
||||
end
|
||||
|
||||
@existing_message_count = FakeSMS.messages.length
|
||||
|
||||
Timecop.freeze(now + 8)
|
||||
recipients[2].attempts.first.save_response(answer_index: 3)
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should create the second attempt with a new question for each recipient who just answered the first question' do
|
||||
recipient = recipients[2]
|
||||
recipient.reload
|
||||
expect(recipient.attempts.count).to eq(2)
|
||||
attempt = recipient.attempts.last
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
|
||||
first_attempt = recipient.attempts.first
|
||||
expect(first_attempt.question).to_not eq(attempt.question)
|
||||
end
|
||||
|
||||
it 'should not send anything to anyone else' do
|
||||
expect(FakeSMS.messages.length).to eq(@existing_message_count + 2)
|
||||
expect(recipients[0].attempts.count).to eq(1)
|
||||
expect(recipients[1].attempts.count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Multiple Students In A Family' do
|
||||
|
||||
before :each do
|
||||
3.times do |i|
|
||||
recipients[1].students.create(name: "Student#{i}")
|
||||
end
|
||||
end
|
||||
|
||||
let(:students_recipient) { recipients[1] }
|
||||
let(:students_recipient_schedule) {
|
||||
students_recipient.recipient_schedules.for_schedule(schedule).first
|
||||
}
|
||||
|
||||
describe 'With A FOR_CHILD Question Is Asked' do
|
||||
let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) }
|
||||
|
||||
before :each do
|
||||
questions.first.update(for_recipient_students: true)
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create one attempt per recipient regardless of students' do
|
||||
expect(FakeSMS.messages.length).to eq(6)
|
||||
recipients.each do |recipient|
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should store queued questions when an attempt is made on first student' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_present
|
||||
queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/)
|
||||
expect(queued_question_ids.length).to eq(1)
|
||||
expect(queued_question_ids.first).to eq("#{questions[0].id}")
|
||||
end
|
||||
|
||||
it 'should set the next_attempt_at to now when attempt is made on first student' do
|
||||
students_recipient.attempts.last.save_response(answer_index: 3)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new)
|
||||
end
|
||||
|
||||
it 'should set the next_attempt_at in the future when an attempts are made on each student' do
|
||||
students_recipient.attempts.last.save_response(answer_index: 3)
|
||||
expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1)
|
||||
expect(students_recipient_schedule.reload.queued_question_ids).to be_present
|
||||
|
||||
attempt = students_recipient.attempts.last
|
||||
expect(attempt.student).to eq(students_recipient.students[1])
|
||||
|
||||
Timecop.freeze(date + 1.day)
|
||||
attempt.save_response(answer_index: 4)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day)
|
||||
|
||||
expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1)
|
||||
expect(students_recipient_schedule.reload.queued_question_ids).to be_nil
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours))
|
||||
|
||||
attempt = students_recipient.attempts.last
|
||||
expect(attempt.student).to eq(students_recipient.students[2])
|
||||
|
||||
Timecop.freeze(date + 2.days)
|
||||
attempt.save_response(answer_index: 2)
|
||||
expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days)
|
||||
end
|
||||
|
||||
it 'should mention the students name in the text' do
|
||||
expect(FakeSMS.messages[2].body).to match(/\(for Student0\)/)
|
||||
end
|
||||
|
||||
it 'should not mention the students name in the text if the recipient has no student specified' do
|
||||
expect(FakeSMS.messages[0].body).to_not match(/\(for .*\)/)
|
||||
end
|
||||
|
||||
it 'resends the question about the same student if not responded to' do
|
||||
message_count = FakeSMS.messages.length
|
||||
expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(0)
|
||||
expect(FakeSMS.messages.length).to eq(message_count + 2)
|
||||
expect(FakeSMS.messages[message_count].body).to match(questions.first.text)
|
||||
expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/)
|
||||
end
|
||||
|
||||
it 'doesnt store any queued_question_ids when no students are present' do
|
||||
recipient_schedule = recipients[0].recipient_schedules.for_schedule(schedule).first
|
||||
expect(recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'With A General Question Is Asked' do
|
||||
before :each do
|
||||
subject.invoke
|
||||
end
|
||||
|
||||
it 'should not queue up an questions regardless of how many students there are' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
|
||||
it 'should not mention the students name in the text' do
|
||||
FakeSMS.messages.each do |message|
|
||||
expect(message.body).to_not match(/\(for .*\)/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'One Student In A Family' do
|
||||
|
||||
before :each do
|
||||
recipients[1].students.create(name: "Only Student")
|
||||
end
|
||||
|
||||
let(:students_recipient) { recipients[1] }
|
||||
let(:students_recipient_schedule) {
|
||||
students_recipient.recipient_schedules.for_schedule(schedule).first
|
||||
}
|
||||
|
||||
describe 'With A FOR_CHILD Question Is Asked' do
|
||||
let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) }
|
||||
|
||||
before :each do
|
||||
questions.first.update(for_recipient_students: true)
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create one attempt per recipient regardless of students' do
|
||||
expect(FakeSMS.messages.length).to eq(6)
|
||||
recipients.each do |recipient|
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it 'doesnt store any queued_question_ids' do
|
||||
expect(students_recipient_schedule.queued_question_ids).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Opted Out Recipient' do
|
||||
|
||||
before :each do
|
||||
recipients[1].update(opted_out: true)
|
||||
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z"))
|
||||
Timecop.freeze(date) { subject.invoke }
|
||||
end
|
||||
|
||||
it 'should create the first attempt for each recipient' do
|
||||
recipients.each_with_index do |recipient, index|
|
||||
recipient.reload
|
||||
if index == 1
|
||||
expect(recipient.attempts.count).to eq(0)
|
||||
expect(recipient.attempts.first).to be_nil
|
||||
else
|
||||
expect(recipient.attempts.count).to eq(1)
|
||||
attempt = recipient.attempts.first
|
||||
expect(attempt.sent_at).to be_present
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Attempt, type: :model do
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipient) { school.recipients.create(name: 'name', phone: "#{1}" * 9) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}")
|
||||
end
|
||||
|
||||
let!(:category) { Category.create(name: 'Category') }
|
||||
let!(:question) { create_questions(1, category).first }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: "#{question.id}")
|
||||
end
|
||||
|
||||
let(:schedule) { Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) }
|
||||
|
||||
let(:recipient_schedule) do
|
||||
RecipientSchedule.create!(
|
||||
recipient: recipient,
|
||||
schedule: schedule,
|
||||
upcoming_question_ids: "#{question.id},3",
|
||||
attempted_question_ids: '2',
|
||||
last_attempt_at: 2.weeks.ago,
|
||||
next_attempt_at: Time.new
|
||||
)
|
||||
end
|
||||
|
||||
let!(:attempt) do
|
||||
recipient.attempts.create(
|
||||
schedule: schedule,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: question
|
||||
)
|
||||
end
|
||||
|
||||
describe 'after_save' do
|
||||
let!(:school_categories) { SchoolCategory.for(attempt.recipient.school, attempt.question.category) }
|
||||
|
||||
xit 'creates the associated school_category' do
|
||||
expect(school_categories.count).to eq(1)
|
||||
expect(school_categories.first.attempt_count).to eq(1)
|
||||
expect(school_categories.first.response_count).to eq(0)
|
||||
expect(school_categories.first.answer_index_total).to eq(0)
|
||||
end
|
||||
|
||||
describe 'after_update' do
|
||||
before :each do
|
||||
attempt.update(answer_index: 4)
|
||||
end
|
||||
|
||||
xit 'updates associated school_categories' do
|
||||
expect(school_categories.count).to eq(1)
|
||||
expect(school_categories.first.attempt_count).to eq(1)
|
||||
expect(school_categories.first.response_count).to eq(1)
|
||||
expect(school_categories.first.answer_index_total).to eq(4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'counters' do
|
||||
it 'are updated when an attempt is created' do
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(0)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is destroyed' do
|
||||
attempt.destroy
|
||||
expect(recipient.attempts_count).to eq(0)
|
||||
expect(recipient.responses_count).to eq(0)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is responded to' do
|
||||
attempt.update(answer_index: 2)
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is responded to with an open-ended response' do
|
||||
attempt.update(open_response_id: 1)
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send_message' do
|
||||
before :each do
|
||||
Timecop.freeze
|
||||
attempt.send_message
|
||||
end
|
||||
|
||||
it 'should contact the Twilio API' do
|
||||
expect(FakeSMS.messages.length).to eq(2)
|
||||
|
||||
expect(FakeSMS.messages.first.to).to eq('111111111')
|
||||
expect(FakeSMS.messages.first.body).to eq("Question 0:1")
|
||||
|
||||
expect(FakeSMS.messages.last.to).to eq('111111111')
|
||||
expect(FakeSMS.messages.last.body).to eq("Option 0:1 A: Reply 1\nOption 0:1 B: 2\nOption 0:1 C: 3\nOption 0:1 D: 4\nOption 0:1 E: 5")
|
||||
end
|
||||
|
||||
it 'should update sent_at' do
|
||||
expect(attempt.sent_at).to eq(Time.new)
|
||||
end
|
||||
|
||||
it 'should update the recipient phone number' do
|
||||
expect(attempt.recipient.reload.phone).to eq('+1111111111')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe District, type: :model do
|
||||
let(:district1) { District.create(name: 'District one', state_id: 32) }
|
||||
let(:district2) { District.new(name: 'District two', state_id: 32) }
|
||||
|
||||
context "when saving or creating" do
|
||||
it 'should return a slug' do
|
||||
expect(district1.slug).to eq 'district-one'
|
||||
|
||||
district2.save
|
||||
expect(district2.slug).to eq 'district-two'
|
||||
|
||||
first_district = District.find_by_slug('district-one')
|
||||
expect(first_district.slug).to eq 'district-one'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
114
spec/models/legacy/attempt_spec.rb
Normal file
114
spec/models/legacy/attempt_spec.rb
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
describe Attempt, type: :model do
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipient) { school.recipients.create(name: 'name', phone: "#{1}" * 9) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}")
|
||||
end
|
||||
|
||||
let!(:category) { Category.create(name: 'Category') }
|
||||
let!(:question) { create_questions(1, category).first }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: "#{question.id}")
|
||||
end
|
||||
|
||||
let(:schedule) { Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) }
|
||||
|
||||
let(:recipient_schedule) do
|
||||
RecipientSchedule.create!(
|
||||
recipient: recipient,
|
||||
schedule: schedule,
|
||||
upcoming_question_ids: "#{question.id},3",
|
||||
attempted_question_ids: '2',
|
||||
last_attempt_at: 2.weeks.ago,
|
||||
next_attempt_at: Time.new
|
||||
)
|
||||
end
|
||||
|
||||
let!(:attempt) do
|
||||
recipient.attempts.create(
|
||||
schedule: schedule,
|
||||
recipient_schedule: recipient_schedule,
|
||||
question: question
|
||||
)
|
||||
end
|
||||
|
||||
describe 'after_save' do
|
||||
let!(:school_categories) { SchoolCategory.for(attempt.recipient.school, attempt.question.category) }
|
||||
|
||||
xit 'creates the associated school_category' do
|
||||
expect(school_categories.count).to eq(1)
|
||||
expect(school_categories.first.attempt_count).to eq(1)
|
||||
expect(school_categories.first.response_count).to eq(0)
|
||||
expect(school_categories.first.answer_index_total).to eq(0)
|
||||
end
|
||||
|
||||
describe 'after_update' do
|
||||
before :each do
|
||||
attempt.update(answer_index: 4)
|
||||
end
|
||||
|
||||
xit 'updates associated school_categories' do
|
||||
expect(school_categories.count).to eq(1)
|
||||
expect(school_categories.first.attempt_count).to eq(1)
|
||||
expect(school_categories.first.response_count).to eq(1)
|
||||
expect(school_categories.first.answer_index_total).to eq(4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'counters' do
|
||||
it 'are updated when an attempt is created' do
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(0)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is destroyed' do
|
||||
attempt.destroy
|
||||
expect(recipient.attempts_count).to eq(0)
|
||||
expect(recipient.responses_count).to eq(0)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is responded to' do
|
||||
attempt.update(answer_index: 2)
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'are updated when an attempt is responded to with an open-ended response' do
|
||||
attempt.update(open_response_id: 1)
|
||||
expect(recipient.attempts_count).to eq(1)
|
||||
expect(recipient.responses_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send_message' do
|
||||
before :each do
|
||||
Timecop.freeze
|
||||
attempt.send_message
|
||||
end
|
||||
|
||||
it 'should contact the Twilio API' do
|
||||
expect(FakeSMS.messages.length).to eq(2)
|
||||
|
||||
expect(FakeSMS.messages.first.to).to eq('111111111')
|
||||
expect(FakeSMS.messages.first.body).to eq("Question 0:1")
|
||||
|
||||
expect(FakeSMS.messages.last.to).to eq('111111111')
|
||||
expect(FakeSMS.messages.last.body).to eq("Option 0:1 A: Reply 1\nOption 0:1 B: 2\nOption 0:1 C: 3\nOption 0:1 D: 4\nOption 0:1 E: 5")
|
||||
end
|
||||
|
||||
it 'should update sent_at' do
|
||||
expect(attempt.sent_at).to eq(Time.new)
|
||||
end
|
||||
|
||||
it 'should update the recipient phone number' do
|
||||
expect(attempt.recipient.reload.phone).to eq('+1111111111')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
21
spec/models/legacy/district_spec.rb
Normal file
21
spec/models/legacy/district_spec.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe District, type: :model do
|
||||
let(:district1) { District.create(name: 'District one', state_id: 32) }
|
||||
let(:district2) { District.new(name: 'District two', state_id: 32) }
|
||||
|
||||
context "when saving or creating" do
|
||||
it 'should return a slug' do
|
||||
expect(district1.slug).to eq 'district-one'
|
||||
|
||||
district2.save
|
||||
expect(district2.slug).to eq 'district-two'
|
||||
|
||||
first_district = District.find_by_slug('district-one')
|
||||
expect(first_district.slug).to eq 'district-one'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
55
spec/models/legacy/question_spec.rb
Normal file
55
spec/models/legacy/question_spec.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe Question, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 5) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Resources') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:category1questions) { create_questions(3, category1) }
|
||||
let!(:category2questions) { create_questions(3, category2) }
|
||||
let(:question) { category1questions.first }
|
||||
|
||||
let!(:attempt1) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3) }
|
||||
let!(:attempt2) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2) }
|
||||
let!(:attempt3) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[2]) }
|
||||
let!(:attempt4) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3) }
|
||||
let!(:attempt5) { Legacy::Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) }
|
||||
let!(:attempt6) { Legacy::Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) }
|
||||
let!(:attempt7) { Legacy::Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) }
|
||||
let!(:attempt8) { Legacy::Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) }
|
||||
let!(:attempt9) { Legacy::Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) }
|
||||
|
||||
describe 'aggregated_responses_for_school' do
|
||||
|
||||
let(:aggregated_responses) { question.aggregated_responses_for_school(school1) }
|
||||
|
||||
it 'aggregates all attempts with responses for the question for a given school' do
|
||||
expect(aggregated_responses.count).to eq(3)
|
||||
expect(aggregated_responses.responses.to_a).to eq([attempt1, attempt2, attempt4])
|
||||
expect(aggregated_responses.answer_index_total).to eq(8)
|
||||
end
|
||||
|
||||
it 'should calculate answer_index_average' do
|
||||
expect(aggregated_responses.answer_index_average).to eq(8.0 / 3)
|
||||
end
|
||||
|
||||
it 'should calculate the most popular answer' do
|
||||
expect(aggregated_responses.most_popular_answer).to eq(question.option3)
|
||||
end
|
||||
|
||||
it 'should provide access to the question and category' do
|
||||
expect(aggregated_responses.question).to eq(question)
|
||||
expect(aggregated_responses.category).to eq(question.category)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
55
spec/models/legacy/recipient_list_spec.rb
Normal file
55
spec/models/legacy/recipient_list_spec.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
describe RecipientList do
|
||||
describe "Save" do
|
||||
it "should convert the recipient_id_array into the recipient_ids attribute" do
|
||||
recipient_list = RecipientList.create(name: 'Name', recipient_id_array: ['', '1', '2', '3'])
|
||||
expect(recipient_list).to be_a(RecipientList)
|
||||
expect(recipient_list).to be_persisted
|
||||
expect(recipient_list.recipient_ids).to eq('1,2,3')
|
||||
|
||||
recipient_list.update(recipient_id_array: ['3', '', '4', '5', '6'])
|
||||
expect(recipient_list.reload.recipient_ids).to eq('3,4,5,6')
|
||||
end
|
||||
end
|
||||
|
||||
describe "when edited" do
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24 * 7
|
||||
)
|
||||
end
|
||||
|
||||
it 'should delete recipient_schedules if a recipient is removed' do
|
||||
modified_recipient_ids = recipients.map(&:id)[0, 2].join(',')
|
||||
expect do
|
||||
recipient_list.update(recipient_ids: modified_recipient_ids)
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(2)
|
||||
end
|
||||
|
||||
it 'should create recipient_schedules if a recipient is added' do
|
||||
new_recipients = create_recipients(school, 2)
|
||||
expect do
|
||||
recipient_list.update(recipient_ids: (recipients + new_recipients).map(&:id).join(','))
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
134
spec/models/legacy/recipient_schedule_spec.rb
Normal file
134
spec/models/legacy/recipient_schedule_spec.rb
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe RecipientSchedule, type: :model do
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipient) { create_recipients(school, 1).first }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipient.id.to_s)
|
||||
end
|
||||
|
||||
let(:category) { Category.create(name: 'Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24
|
||||
)
|
||||
end
|
||||
let!(:recipient_schedule) { schedule.recipient_schedules.for_recipient(recipient).first }
|
||||
|
||||
let!(:not_ready_recipient_schedule) do
|
||||
RecipientSchedule.create!(
|
||||
recipient: recipient,
|
||||
schedule: schedule,
|
||||
upcoming_question_ids: '1,3',
|
||||
attempted_question_ids: '2',
|
||||
last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours),
|
||||
next_attempt_at: 1.day.from_now + (60 * 60 * schedule.frequency_hours)
|
||||
)
|
||||
end
|
||||
|
||||
xdescribe 'ready' do
|
||||
before :each do
|
||||
now = DateTime.now
|
||||
date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT16:00:00%z'))
|
||||
Timecop.freeze(date)
|
||||
end
|
||||
|
||||
subject { schedule.recipient_schedules.ready }
|
||||
|
||||
it('should only provide recipient_schedules who are ready to send a message') do
|
||||
expect(subject.length).to eq(1)
|
||||
expect(subject.first).to eq(recipient_schedule)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'next_question' do
|
||||
it 'should provide the next question from the upcoming_question_ids list' do
|
||||
expect(recipient_schedule.next_question).to eq(questions.first)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'attempt_question' do
|
||||
before :each do
|
||||
Timecop.freeze
|
||||
end
|
||||
|
||||
describe 'with an opted out recipient' do
|
||||
before :each do
|
||||
recipient_schedule.recipient.update(opted_out: true)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should not do anything' do
|
||||
expect(attempt).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'right before a weekend' do
|
||||
before :each do
|
||||
friday_time = ActiveSupport::TimeZone['UTC'].parse('2017-04-21T20:00:00')
|
||||
Timecop.freeze
|
||||
recipient_schedule.update(next_attempt_at: friday_time)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should schedule the next attempt for after the weekend' do
|
||||
next_weekday_time = ActiveSupport::TimeZone['UTC'].parse('2017-04-24T20:00:00')
|
||||
expect(recipient_schedule.reload.next_attempt_at).to eq(next_weekday_time)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an opted in recipient' do
|
||||
before :each do
|
||||
date = ActiveSupport::TimeZone['UTC'].parse('2017-04-20T20:00:00')
|
||||
Timecop.freeze(date)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should make an attempt to ask the next question' do
|
||||
expect(attempt).to be_persisted
|
||||
expect(attempt.recipient).to eq(recipient)
|
||||
expect(attempt.schedule).to eq(schedule)
|
||||
expect(attempt.recipient_schedule).to eq(recipient_schedule)
|
||||
expect(attempt.question).to eq(questions.first)
|
||||
expect(attempt.sent_at.to_i).to eq(Time.new.to_i)
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
|
||||
it 'should update the upcoming_questions_ids' do
|
||||
expect(recipient_schedule.upcoming_question_ids).to eq(questions[1..2].map(&:id).join(','))
|
||||
end
|
||||
|
||||
it 'should update the attempted_question_ids' do
|
||||
expect(recipient_schedule.attempted_question_ids).to eq(questions.first.id.to_s)
|
||||
end
|
||||
|
||||
it 'should update last_attempt_at' do
|
||||
expect(recipient_schedule.last_attempt_at.to_i).to eq(Time.new.to_i)
|
||||
end
|
||||
|
||||
it 'should update next_attempt_at' do
|
||||
now = DateTime.now
|
||||
date = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].parse(now.strftime('%Y-%m-%dT16:00:00%z'))
|
||||
date += 1.day
|
||||
date += 1.day if date.on_weekend?
|
||||
|
||||
expect(recipient_schedule.reload.next_attempt_at).to eq(date.to_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
52
spec/models/legacy/recipient_spec.rb
Normal file
52
spec/models/legacy/recipient_spec.rb
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
describe Recipient do
|
||||
describe "Import" do
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
let(:data) { "name,phone\rJared,111-222-333\rLauren,222-333-4444\rAbby,333-444-5555\r" }
|
||||
let(:file) { instance_double('File', path: 'path') }
|
||||
|
||||
xit "should parse file contents and return a result" do
|
||||
expect(File).to receive(:open).with('path', universal_newline: false, headers: true) { StringIO.new(data) }
|
||||
Recipient.import(school, file)
|
||||
expect(Recipient.count).to eq(3)
|
||||
expect(Recipient.all.map(&:name)).to eq(['Jared', 'Lauren', 'Abby'])
|
||||
expect(Recipient.all.map(&:school).uniq).to eq([school])
|
||||
end
|
||||
end
|
||||
|
||||
describe "When Deleted" do
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24 * 7
|
||||
)
|
||||
end
|
||||
|
||||
it 'should delete all recipient_schedules and update all recipient_lists' do
|
||||
expect do
|
||||
recipients[1].destroy
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(2)
|
||||
|
||||
expect(recipient_list.recipient_ids).to eq("#{recipients[0].id},#{recipients[2].id}")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
64
spec/models/legacy/schedule_spec.rb
Normal file
64
spec/models/legacy/schedule_spec.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
describe Schedule do
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:kid_recipients) { create_recipients(school, 3) }
|
||||
let!(:kids_recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Kids', recipient_ids: kid_recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let(:default_schedule_params) {
|
||||
{
|
||||
school: school,
|
||||
recipient_list: recipient_list,
|
||||
question_list: question_list,
|
||||
name: 'Parents Schedule',
|
||||
description: 'Schedule for parent questions',
|
||||
start_date: 1.month.ago,
|
||||
end_date: 11.months.from_now,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
|
||||
let!(:active_schedule) do
|
||||
Schedule.create!(default_schedule_params)
|
||||
end
|
||||
|
||||
let!(:active_schedule_kids) do
|
||||
Schedule.create!(default_schedule_params.merge!(name: 'Kids Schedule', recipient_list: kids_recipient_list))
|
||||
end
|
||||
|
||||
let!(:old_schedule) {
|
||||
Schedule.create!(default_schedule_params.merge!(start_date: 13.month.ago, end_date: 1.months.ago))
|
||||
}
|
||||
|
||||
let!(:paused_schedule) {
|
||||
Schedule.create!(default_schedule_params.merge!(active: false))
|
||||
}
|
||||
|
||||
describe "active" do
|
||||
it 'finds active schedules' do
|
||||
active = Schedule.active
|
||||
expect(active.length).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a recipient_schedule for every recipient when created' do
|
||||
expect(active_schedule.recipient_schedules.length).to eq(3)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
75
spec/models/legacy/school_category_spec.rb
Normal file
75
spec/models/legacy/school_category_spec.rb
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe SchoolCategory, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 4) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Category 1') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:category1questions) { create_questions(3, category1) }
|
||||
let!(:category2questions) { create_questions(3, category2) }
|
||||
|
||||
let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2) }
|
||||
let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1]) }
|
||||
let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3) }
|
||||
let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) }
|
||||
let!(:attempt5) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) }
|
||||
let!(:attempt6) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) }
|
||||
let!(:attempt7) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) }
|
||||
let!(:attempt8) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) }
|
||||
|
||||
let!(:school_category1) { SchoolCategory.for(school1, category1).first }
|
||||
|
||||
describe 'aggregated_responses' do
|
||||
xit 'should provide the count and sum of all attempts' do
|
||||
expect(school_category1.aggregated_responses).to eq(
|
||||
attempt_count: 5,
|
||||
response_count: 4,
|
||||
answer_index_total: 15
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'answer_index_average' do
|
||||
xit 'should provide the average answer_index for all responses' do
|
||||
expect(school_category1.answer_index_average).to eq(15.0 / 4.0)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'sync_aggregated_responses' do
|
||||
|
||||
let!(:category3) { Category.create!(name: 'Category 3', parent_category: category1) }
|
||||
|
||||
let!(:category3questions) { create_questions(3, category3) }
|
||||
|
||||
let!(:attempt7) { Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4) }
|
||||
let!(:attempt8) { Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1) }
|
||||
let!(:attempt9) { Attempt.create!(question: category3questions[0], recipient: school1recipients[2]) }
|
||||
let!(:attempt10) { Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5) }
|
||||
let!(:attempt11) { Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5) }
|
||||
|
||||
let!(:school_category3) { SchoolCategory.for(school1, category3).first }
|
||||
|
||||
xit 'should update attributes and parent_category school_category attributes' do
|
||||
school_category3.sync_aggregated_responses
|
||||
|
||||
school_category3.reload
|
||||
expect(school_category3.attempt_count).to eq(4)
|
||||
expect(school_category3.response_count).to eq(3)
|
||||
expect(school_category3.answer_index_total).to eq(10)
|
||||
|
||||
school_category1.reload
|
||||
expect(school_category1.attempt_count).to eq(9)
|
||||
expect(school_category1.response_count).to eq(7)
|
||||
expect(school_category1.answer_index_total).to eq(25)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
7
spec/models/legacy/student_spec.rb
Normal file
7
spec/models/legacy/student_spec.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe Student, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
end
|
||||
7
spec/models/legacy/user_school_spec.rb
Normal file
7
spec/models/legacy/user_school_spec.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe UserSchool, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
end
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Question, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 5) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Resources') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:category1questions) { create_questions(3, category1) }
|
||||
let!(:category2questions) { create_questions(3, category2) }
|
||||
let(:question) { category1questions.first }
|
||||
|
||||
let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3)}
|
||||
let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2)}
|
||||
let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2])}
|
||||
let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3)}
|
||||
let!(:attempt5) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4)}
|
||||
let!(:attempt6) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt7) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt8) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3)}
|
||||
let!(:attempt9) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1)}
|
||||
|
||||
describe 'aggregated_responses_for_school' do
|
||||
|
||||
let(:aggregated_responses) { question.aggregated_responses_for_school(school1) }
|
||||
|
||||
it 'aggregates all attempts with responses for the question for a given school' do
|
||||
expect(aggregated_responses.count).to eq(3)
|
||||
expect(aggregated_responses.responses.to_a).to eq([attempt1, attempt2, attempt4])
|
||||
expect(aggregated_responses.answer_index_total).to eq(8)
|
||||
end
|
||||
|
||||
it 'should calculate answer_index_average' do
|
||||
expect(aggregated_responses.answer_index_average).to eq(8.0 / 3)
|
||||
end
|
||||
|
||||
it 'should calculate the most popular answer' do
|
||||
expect(aggregated_responses.most_popular_answer).to eq(question.option3)
|
||||
end
|
||||
|
||||
it 'should provide access to the question and category' do
|
||||
expect(aggregated_responses.question).to eq(question)
|
||||
expect(aggregated_responses.category).to eq(question.category)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe RecipientList do
|
||||
describe "Save" do
|
||||
it "should convert the recipient_id_array into the recipient_ids attribute" do
|
||||
recipient_list = RecipientList.create(name: 'Name', recipient_id_array: ['', '1', '2', '3'])
|
||||
expect(recipient_list).to be_a(RecipientList)
|
||||
expect(recipient_list).to be_persisted
|
||||
expect(recipient_list.recipient_ids).to eq('1,2,3')
|
||||
|
||||
recipient_list.update(recipient_id_array: ['3', '', '4', '5', '6'])
|
||||
expect(recipient_list.reload.recipient_ids).to eq('3,4,5,6')
|
||||
end
|
||||
end
|
||||
|
||||
describe "when edited" do
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24 * 7
|
||||
)
|
||||
end
|
||||
|
||||
it 'should delete recipient_schedules if a recipient is removed' do
|
||||
modified_recipient_ids = recipients.map(&:id)[0,2].join(',')
|
||||
expect do
|
||||
recipient_list.update(recipient_ids: modified_recipient_ids)
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(2)
|
||||
end
|
||||
|
||||
it 'should create recipient_schedules if a recipient is added' do
|
||||
new_recipients = create_recipients(school, 2)
|
||||
expect do
|
||||
recipient_list.update(recipient_ids: (recipients + new_recipients).map(&:id).join(','))
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RecipientSchedule, type: :model do
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipient) { create_recipients(school, 1).first }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}")
|
||||
end
|
||||
|
||||
let(:category) { Category.create(name: 'Category') }
|
||||
let!(:questions) { create_questions(3, category) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24
|
||||
)
|
||||
end
|
||||
let!(:recipient_schedule) { schedule.recipient_schedules.for_recipient(recipient).first }
|
||||
|
||||
let!(:not_ready_recipient_schedule) do
|
||||
RecipientSchedule.create!(
|
||||
recipient: recipient,
|
||||
schedule: schedule,
|
||||
upcoming_question_ids: '1,3',
|
||||
attempted_question_ids: '2',
|
||||
last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours),
|
||||
next_attempt_at: 1.day.from_now + (60 * 60 * schedule.frequency_hours)
|
||||
)
|
||||
end
|
||||
|
||||
xdescribe 'ready' do
|
||||
before :each do
|
||||
now = DateTime.now
|
||||
date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
|
||||
Timecop.freeze(date)
|
||||
end
|
||||
|
||||
subject { schedule.recipient_schedules.ready }
|
||||
|
||||
it ('should only provide recipient_schedules who are ready to send a message') do
|
||||
expect(subject.length).to eq(1)
|
||||
expect(subject.first).to eq(recipient_schedule)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'next_question' do
|
||||
it 'should provide the next question from the upcoming_question_ids list' do
|
||||
expect(recipient_schedule.next_question).to eq(questions.first)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'attempt_question' do
|
||||
before :each do
|
||||
Timecop.freeze
|
||||
end
|
||||
|
||||
describe 'with an opted out recipient' do
|
||||
before :each do
|
||||
recipient_schedule.recipient.update(opted_out: true)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should not do anything' do
|
||||
expect(attempt).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'right before a weekend' do
|
||||
before :each do
|
||||
friday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-21T20:00:00')
|
||||
Timecop.freeze()
|
||||
recipient_schedule.update(next_attempt_at: friday_time)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should schedule the next attempt for after the weekend' do
|
||||
next_weekday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-24T20:00:00')
|
||||
expect(recipient_schedule.reload.next_attempt_at).to eq(next_weekday_time)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with an opted in recipient' do
|
||||
before :each do
|
||||
date = ActiveSupport::TimeZone["UTC"].parse('2017-04-20T20:00:00')
|
||||
Timecop.freeze(date)
|
||||
end
|
||||
|
||||
let!(:attempt) { recipient_schedule.attempt_question }
|
||||
|
||||
it 'should make an attempt to ask the next question' do
|
||||
expect(attempt).to be_persisted
|
||||
expect(attempt.recipient).to eq(recipient)
|
||||
expect(attempt.schedule).to eq(schedule)
|
||||
expect(attempt.recipient_schedule).to eq(recipient_schedule)
|
||||
expect(attempt.question).to eq(questions.first)
|
||||
expect(attempt.sent_at.to_i).to eq(Time.new.to_i)
|
||||
expect(attempt.answer_index).to be_nil
|
||||
end
|
||||
|
||||
it 'should update the upcoming_questions_ids' do
|
||||
expect(recipient_schedule.upcoming_question_ids).to eq(questions[1..2].map(&:id).join(','))
|
||||
end
|
||||
|
||||
it 'should update the attempted_question_ids' do
|
||||
expect(recipient_schedule.attempted_question_ids).to eq(questions.first.id.to_s)
|
||||
end
|
||||
|
||||
it 'should update last_attempt_at' do
|
||||
expect(recipient_schedule.last_attempt_at.to_i).to eq(Time.new.to_i)
|
||||
end
|
||||
|
||||
it 'should update next_attempt_at' do
|
||||
now = DateTime.now
|
||||
date = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].parse(now.strftime("%Y-%m-%dT16:00:00%z"))
|
||||
date += 1.day
|
||||
date += 1.day if date.on_weekend?
|
||||
|
||||
expect(recipient_schedule.reload.next_attempt_at).to eq(date.to_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Recipient do
|
||||
describe "Import" do
|
||||
let(:school) { School.create!(name: 'School') }
|
||||
let(:data) { "name,phone\rJared,111-222-333\rLauren,222-333-4444\rAbby,333-444-5555\r" }
|
||||
let(:file) { instance_double('File', path: 'path') }
|
||||
|
||||
xit "should parse file contents and return a result" do
|
||||
expect(File).to receive(:open).with('path', universal_newline: false, headers: true) { StringIO.new(data) }
|
||||
Recipient.import(school, file)
|
||||
expect(Recipient.count).to eq(3)
|
||||
expect(Recipient.all.map(&:name)).to eq(['Jared', 'Lauren', 'Abby'])
|
||||
expect(Recipient.all.map(&:school).uniq).to eq([school])
|
||||
end
|
||||
end
|
||||
|
||||
describe "When Deleted" do
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:schedule) do
|
||||
Schedule.create!(
|
||||
name: 'Parent Schedule',
|
||||
recipient_list_id: recipient_list.id,
|
||||
question_list: question_list,
|
||||
random: false,
|
||||
frequency_hours: 24 * 7
|
||||
)
|
||||
end
|
||||
|
||||
it 'should delete all recipient_schedules and update all recipient_lists' do
|
||||
expect do
|
||||
recipients[1].destroy
|
||||
end.to change { schedule.recipient_schedules.count }.from(3).to(2)
|
||||
|
||||
expect(recipient_list.recipient_ids).to eq("#{recipients[0].id},#{recipients[2].id}")
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Schedule do
|
||||
|
||||
let!(:school) { School.create!(name: 'School') }
|
||||
|
||||
let!(:recipients) { create_recipients(school, 3) }
|
||||
let!(:recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:kid_recipients) { create_recipients(school, 3) }
|
||||
let!(:kids_recipient_list) do
|
||||
school.recipient_lists.create!(name: 'Kids', recipient_ids: kid_recipients.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let!(:questions) { create_questions(3) }
|
||||
let!(:question_list) do
|
||||
QuestionList.create!(name: 'Questions', question_ids: questions.map(&:id).join(','))
|
||||
end
|
||||
|
||||
let(:default_schedule_params) {
|
||||
{
|
||||
school: school,
|
||||
recipient_list: recipient_list,
|
||||
question_list: question_list,
|
||||
name: 'Parents Schedule',
|
||||
description: 'Schedule for parent questions',
|
||||
start_date: 1.month.ago,
|
||||
end_date: 11.months.from_now,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
|
||||
let!(:active_schedule) do
|
||||
Schedule.create!(default_schedule_params)
|
||||
end
|
||||
|
||||
let!(:active_schedule_kids) do
|
||||
Schedule.create!(default_schedule_params.merge!(name: 'Kids Schedule', recipient_list: kids_recipient_list))
|
||||
end
|
||||
|
||||
let!(:old_schedule) {
|
||||
Schedule.create!(default_schedule_params.merge!(start_date: 13.month.ago, end_date: 1.months.ago))
|
||||
}
|
||||
|
||||
let!(:paused_schedule) {
|
||||
Schedule.create!(default_schedule_params.merge!(active: false))
|
||||
}
|
||||
|
||||
describe "active" do
|
||||
it 'finds active schedules' do
|
||||
active = Schedule.active
|
||||
expect(active.length).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a recipient_schedule for every recipient when created' do
|
||||
expect(active_schedule.recipient_schedules.length).to eq(3)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchoolCategory, type: :model do
|
||||
|
||||
let!(:school1) { School.create!(name: 'School 1') }
|
||||
let!(:school2) { School.create!(name: 'School 2') }
|
||||
|
||||
let!(:school1recipients) { create_recipients(school1, 4) }
|
||||
let!(:school2recipients) { create_recipients(school2, 4) }
|
||||
|
||||
let!(:category1) { Category.create!(name: 'Category 1') }
|
||||
let!(:category2) { Category.create!(name: 'Category 2') }
|
||||
|
||||
let!(:category1questions) { create_questions(3, category1) }
|
||||
let!(:category2questions) { create_questions(3, category2) }
|
||||
|
||||
let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2)}
|
||||
let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1])}
|
||||
let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3)}
|
||||
let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4)}
|
||||
let!(:attempt5) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt6) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5)}
|
||||
let!(:attempt7) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3)}
|
||||
let!(:attempt8) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1)}
|
||||
|
||||
let!(:school_category1) { SchoolCategory.for(school1, category1).first }
|
||||
|
||||
describe 'aggregated_responses' do
|
||||
xit 'should provide the count and sum of all attempts' do
|
||||
expect(school_category1.aggregated_responses).to eq(
|
||||
attempt_count: 5,
|
||||
response_count: 4,
|
||||
answer_index_total: 15
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'answer_index_average' do
|
||||
xit 'should provide the average answer_index for all responses' do
|
||||
expect(school_category1.answer_index_average).to eq(15.0/4.0)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'sync_aggregated_responses' do
|
||||
|
||||
let!(:category3) { Category.create!(name: 'Category 3', parent_category: category1) }
|
||||
|
||||
let!(:category3questions) { create_questions(3, category3) }
|
||||
|
||||
let!(:attempt7) { Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4)}
|
||||
let!(:attempt8) { Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1)}
|
||||
let!(:attempt9) { Attempt.create!(question: category3questions[0], recipient: school1recipients[2])}
|
||||
let!(:attempt10) { Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5)}
|
||||
let!(:attempt11) { Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5)}
|
||||
|
||||
let!(:school_category3) { SchoolCategory.for(school1, category3).first }
|
||||
|
||||
|
||||
xit 'should update attributes and parent_category school_category attributes' do
|
||||
school_category3.sync_aggregated_responses
|
||||
|
||||
school_category3.reload
|
||||
expect(school_category3.attempt_count).to eq(4)
|
||||
expect(school_category3.response_count).to eq(3)
|
||||
expect(school_category3.answer_index_total).to eq(10)
|
||||
|
||||
school_category1.reload
|
||||
expect(school_category1.attempt_count).to eq(9)
|
||||
expect(school_category1.response_count).to eq(7)
|
||||
expect(school_category1.answer_index_total).to eq(25)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Student, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
# FIXME remove this when seeds.rb is under test
|
||||
xdescribe SurveyItem, type: :model do
|
||||
it('has all the questions') do
|
||||
expect(SurveyItem.count).to eq 137
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserSchool, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
|
@ -5,32 +5,32 @@ describe CategoryPresenter do
|
|||
subcategory1 = Subcategory.new(name: 'A subcategory')
|
||||
subcategory2 = Subcategory.new(name: 'Another subcategory')
|
||||
|
||||
category = SqmCategory.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category')
|
||||
category = Category.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category')
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
let(:teachers_and_leadership_presenter) do
|
||||
category = create(:sqm_category, name: 'Teachers & Leadership')
|
||||
category = create(:category, name: 'Teachers & Leadership')
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
let(:school_culture_presenter) do
|
||||
category = create(:sqm_category, name: "School Culture")
|
||||
category = create(:category, name: "School Culture")
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
let(:resources_presenter) do
|
||||
category = create(:sqm_category, name: "Resources")
|
||||
category = create(:category, name: "Resources")
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
let(:academic_learning_presenter) do
|
||||
category = create(:sqm_category, name: "Academic Learning")
|
||||
category = create(:category, name: "Academic Learning")
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
let(:community_and_wellbeing_presenter) do
|
||||
category = create(:sqm_category, name: "Community & Wellbeing")
|
||||
category = create(:category, name: "Community & Wellbeing")
|
||||
return CategoryPresenter.new(category: category)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe CategoriesController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/categories").to route_to("categories#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/categories/new").to route_to("categories#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/categories/1").to route_to("categories#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/categories/1/edit").to route_to("categories#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/categories").to route_to("categories#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/categories/1").to route_to("categories#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/categories/1").to route_to("categories#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/categories/1").to route_to("categories#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
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
|
||||
41
spec/routing/legacy/categories_routing_spec.rb
Normal file
41
spec/routing/legacy/categories_routing_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe CategoriesController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/categories").to route_to("legacy/categories#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/categories/new").to route_to("legacy/categories#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/categories/1").to route_to("legacy/categories#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/categories/1/edit").to route_to("legacy/categories#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/categories").to route_to("legacy/categories#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/categories/1").to route_to("legacy/categories#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/categories/1").to route_to("legacy/categories#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/categories/1").to route_to("legacy/categories#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
41
spec/routing/legacy/districts_routing_spec.rb
Normal file
41
spec/routing/legacy/districts_routing_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe DistrictsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/districts").to route_to("legacy/districts#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/districts/new").to route_to("legacy/districts#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/districts/1").to route_to("legacy/districts#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/districts/1/edit").to route_to("legacy/districts#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/districts").to route_to("legacy/districts#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/districts/1").to route_to("legacy/districts#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/districts/1").to route_to("legacy/districts#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/districts/1").to route_to("legacy/districts#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
41
spec/routing/legacy/question_lists_routing_spec.rb
Normal file
41
spec/routing/legacy/question_lists_routing_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe Legacy::QuestionListsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/question_lists").to route_to("legacy/question_lists#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/question_lists/new").to route_to("legacy/question_lists#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/question_lists/1").to route_to("legacy/question_lists#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/question_lists/1/edit").to route_to("legacy/question_lists#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/question_lists").to route_to("legacy/question_lists#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/question_lists/1").to route_to("legacy/question_lists#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
41
spec/routing/legacy/questions_routing_spec.rb
Normal file
41
spec/routing/legacy/questions_routing_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe QuestionsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/questions").to route_to("legacy/questions#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/questions/new").to route_to("legacy/questions#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/questions/1").to route_to("legacy/questions#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/questions/1/edit").to route_to("legacy/questions#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/questions").to route_to("legacy/questions#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/questions/1").to route_to("legacy/questions#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/questions/1").to route_to("legacy/questions#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/questions/1").to route_to("legacy/questions#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
47
spec/routing/legacy/recipient_lists_routing_spec.rb
Normal file
47
spec/routing/legacy/recipient_lists_routing_spec.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe RecipientListsController, 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}/recipient_lists").to route_to("legacy/recipient_lists#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("legacy/recipient_lists#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#show", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("legacy/recipient_lists#edit", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("legacy/recipient_lists#create", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
47
spec/routing/legacy/recipients_routing_spec.rb
Normal file
47
spec/routing/legacy/recipients_routing_spec.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe RecipientsController, 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}/recipients").to route_to("legacy/recipients#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/new").to route_to("legacy/recipients#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#show", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("legacy/recipients#edit", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "schools/#{@school.id}/recipients").to route_to("legacy/recipients#create", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
47
spec/routing/legacy/schedules_routing_spec.rb
Normal file
47
spec/routing/legacy/schedules_routing_spec.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
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("legacy/schedules#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/schedules/new").to route_to("legacy/schedules#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/schedules/1").to route_to("legacy/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("legacy/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("legacy/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("legacy/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("legacy/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("legacy/schedules#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
41
spec/routing/legacy/schools_routing_spec.rb
Normal file
41
spec/routing/legacy/schools_routing_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
require "rails_helper"
|
||||
|
||||
module Legacy
|
||||
RSpec.describe SchoolsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/schools").to route_to("legacy/schools#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/schools/new").to route_to("legacy/schools#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/schools/1").to route_to("legacy/schools#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/schools/1/edit").to route_to("legacy/schools#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/schools").to route_to("legacy/schools#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/schools/1").to route_to("legacy/schools#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/schools/1").to route_to("legacy/schools#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/schools/1").to route_to("legacy/schools#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe QuestionListsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/question_lists").to route_to("question_lists#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/question_lists/new").to route_to("question_lists#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/question_lists/1").to route_to("question_lists#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/question_lists/1/edit").to route_to("question_lists#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/question_lists").to route_to("question_lists#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/question_lists/1").to route_to("question_lists#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/question_lists/1").to route_to("question_lists#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/question_lists/1").to route_to("question_lists#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe QuestionsController, type: :routing do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
expect(:get => "/questions").to route_to("questions#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/questions/new").to route_to("questions#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/questions/1").to route_to("questions#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/questions/1/edit").to route_to("questions#edit", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/questions").to route_to("questions#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/questions/1").to route_to("questions#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/questions/1").to route_to("questions#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/questions/1").to route_to("questions#destroy", :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe RecipientListsController, 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}/recipient_lists").to route_to("recipient_lists#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("recipient_lists#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#show", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("recipient_lists#edit", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("recipient_lists#create", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe RecipientsController, 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}/recipients").to route_to("recipients#index", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/new").to route_to("recipients#new", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/1").to route_to("recipients#show", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("recipients#edit", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "schools/#{@school.id}/recipients").to route_to("recipients#create", school_id: @school.id.to_s)
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("recipients#destroy", school_id: @school.id.to_s, :id => "1")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
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
|
||||
|
|
@ -169,7 +169,7 @@ end
|
|||
def create_questions(count, category=nil)
|
||||
questions = []
|
||||
count.times do |i|
|
||||
questions << Question.create(
|
||||
questions << Legacy::Question.create(
|
||||
text: "Question #{i}:#{count}",
|
||||
option1: "Option #{i}:#{count} A",
|
||||
option2: "Option #{i}:#{count} B",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ describe 'District Admin', js: true do
|
|||
let(:school) { School.find_by_slug 'winchester-high-school' }
|
||||
let(:school_in_same_district) { School.find_by_slug 'muraco-elementary-school' }
|
||||
|
||||
let(:category) { SqmCategory.find_by_name('Teachers & Leadership') }
|
||||
let(:category) { Category.find_by_name('Teachers & Leadership') }
|
||||
let(:subcategory) { Subcategory.find_by_name('Teachers & The Teaching Environment') }
|
||||
let(:measures_for_subcategory) { Measure.where(subcategory: subcategory) }
|
||||
let(:survey_items_for_subcategory) { SurveyItem.where(measure: measures_for_subcategory) }
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe 'SQM Application' do
|
|||
let(:district) { create(:district) }
|
||||
let(:school) { create(:school, district: district) }
|
||||
let(:academic_year) { create(:academic_year) }
|
||||
let(:category) { create(:sqm_category) }
|
||||
let(:category) { create(:category) }
|
||||
let(:measure) { create(:measure) }
|
||||
|
||||
before :each do
|
||||
|
|
@ -51,6 +51,6 @@ describe 'SQM Application' do
|
|||
end
|
||||
|
||||
def browse_path
|
||||
district_school_sqm_category_path(district, school, category, year: academic_year.range)
|
||||
district_school_category_path(district, school, category, year: academic_year.range)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "categories/edit", type: :view do
|
||||
before(:each) do
|
||||
@category = assign(:category, Category.create!(
|
||||
:name => "MyString",
|
||||
:blurb => "MyString",
|
||||
:description => "MyText",
|
||||
:external_id => "MyString",
|
||||
:parent_category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit category form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", category_path(@category), "post" do
|
||||
|
||||
assert_select "input#category_name[name=?]", "category[name]"
|
||||
|
||||
assert_select "input#category_blurb[name=?]", "category[blurb]"
|
||||
|
||||
assert_select "textarea#category_description[name=?]", "category[description]"
|
||||
|
||||
assert_select "input#category_external_id[name=?]", "category[external_id]"
|
||||
|
||||
assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "categories/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:categories, [
|
||||
Category.create!(
|
||||
:name => "Name",
|
||||
:blurb => "Blurb",
|
||||
:description => "MyText",
|
||||
:external_id => "External",
|
||||
:parent_category_id => 2
|
||||
),
|
||||
Category.create!(
|
||||
:name => "Name",
|
||||
:blurb => "Blurb",
|
||||
:description => "MyText",
|
||||
:external_id => "External",
|
||||
:parent_category_id => 2
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of categories" do
|
||||
render(template: "categories/index")
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Blurb".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "MyText".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "External".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 2.to_s, :count => 2
|
||||
end
|
||||
end
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "categories/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:category, Category.new(
|
||||
:name => "MyString",
|
||||
:blurb => "MyString",
|
||||
:description => "MyText",
|
||||
:external_id => "MyString",
|
||||
:parent_category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new category form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", categories_path, "post" do
|
||||
|
||||
assert_select "input#category_name[name=?]", "category[name]"
|
||||
|
||||
assert_select "input#category_blurb[name=?]", "category[blurb]"
|
||||
|
||||
assert_select "textarea#category_description[name=?]", "category[description]"
|
||||
|
||||
assert_select "input#category_external_id[name=?]", "category[external_id]"
|
||||
|
||||
assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,20 +1,78 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "categories/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create(name: 'School'))
|
||||
@category = assign(:category, Category.create!(
|
||||
:name => "Category",
|
||||
:description => "MyText",
|
||||
:parent_category => Category.create(name: 'Teachers And The Teaching Environment')
|
||||
))
|
||||
@school_category = assign(:school_category, SchoolCategory.create(school: @school, category: @category))
|
||||
describe 'categories/show.html.erb' do
|
||||
before :each do
|
||||
academic_year = create(:academic_year, range: '1989-90')
|
||||
school = create(:school, name: 'Best School')
|
||||
|
||||
category = create(:category, name: 'Some Category', description: 'Some description of the category')
|
||||
category_presenter = CategoryPresenter.new(category: category)
|
||||
|
||||
subcategory1 = create(:subcategory, category: category, name: 'A subcategory', description: 'Some description of the subcategory')
|
||||
subcategory2 = create(:subcategory_with_measures, category: category, name: 'Another subcategory', description: 'Another description of the subcategory')
|
||||
|
||||
measure1 = create(:measure, subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5)
|
||||
survey_item1 = create(:student_survey_item, measure: measure1)
|
||||
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1)
|
||||
|
||||
measure2 = create(:measure, name: 'The second measure name', description: 'The second measure description', subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5)
|
||||
student_survey_item = create(:student_survey_item, measure: measure2, prompt: "Some prompt for student data")
|
||||
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item, academic_year: academic_year, school: school, likert_score: 5)
|
||||
|
||||
teacher_survey_item = create(:teacher_survey_item, measure: measure2, prompt: "Some prompt for teacher data")
|
||||
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item, academic_year: academic_year, school: school, likert_score: 3)
|
||||
|
||||
admin_data_item = create(:admin_data_item, measure: measure2, description: "Some admin data item description")
|
||||
assign :category, category_presenter
|
||||
|
||||
assign :categories, [category_presenter]
|
||||
assign :school, school
|
||||
assign :district, create(:district)
|
||||
assign :academic_year, academic_year
|
||||
|
||||
render
|
||||
end
|
||||
|
||||
xit "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Category/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
expect(rendered).to match(/Teachers And The Teaching Environment/)
|
||||
it 'renders the category name and description' do
|
||||
expect(rendered).to match /Some Category/
|
||||
expect(rendered).to match /Some description of the category/
|
||||
end
|
||||
|
||||
context 'for each subcategory' do
|
||||
it 'renders the subcategory name' do
|
||||
expect(rendered).to match /A subcategory/
|
||||
expect(rendered).to match /Another subcategory/
|
||||
end
|
||||
|
||||
it 'renders the subcategory description' do
|
||||
expect(rendered).to match /Some description of the subcategory/
|
||||
expect(rendered).to match /Another description of the subcategory/
|
||||
end
|
||||
|
||||
it 'renders the zone title and fill color for the gauge graph' do
|
||||
expect(rendered).to match /Growth/
|
||||
expect(rendered).to match /fill-growth/
|
||||
end
|
||||
end
|
||||
|
||||
context 'for each measure' do
|
||||
it 'renders the measure name' do
|
||||
expect(rendered).to match /The second measure name/
|
||||
end
|
||||
|
||||
it 'renders the measure description' do
|
||||
expect(rendered).to match /The second measure description/
|
||||
end
|
||||
|
||||
it 'renders a gauge graph and the zone title color' do
|
||||
expect(rendered).to match /Ideal/
|
||||
expect(rendered).to match /fill-ideal/
|
||||
end
|
||||
|
||||
it 'renders the prompts for survey items and admin data that make up the measure' do
|
||||
expect(rendered).to match /Some prompt for student data/
|
||||
expect(rendered).to match /Some prompt for teacher data/
|
||||
expect(rendered).to match /Some admin data item description/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "districts/show", type: :view do
|
||||
before(:each) do
|
||||
@district = assign(:district, District.create!(
|
||||
:name => "Milford",
|
||||
:state_id => 2
|
||||
))
|
||||
|
||||
schools = []
|
||||
3.times { |i| schools << @district.schools.create!(name: "School #{i}")}
|
||||
@schools = assign(:schools, schools)
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render(template: "districts/show")
|
||||
expect(rendered).to match(/Milford/)
|
||||
expect(rendered).to match(/2/)
|
||||
3.times do |i|
|
||||
expect(rendered).to match(/School #{i}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,7 +5,7 @@ describe 'home/index.html.erb' do
|
|||
|
||||
before :each do
|
||||
assign :districts, [create(:district), create(:district)]
|
||||
assign :categories, [CategoryPresenter.new(category: create(:sqm_category))]
|
||||
assign :categories, [CategoryPresenter.new(category: create(:category))]
|
||||
render
|
||||
end
|
||||
|
||||
|
|
|
|||
32
spec/views/legacy/categories/edit.html.erb_spec.rb
Normal file
32
spec/views/legacy/categories/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/categories/edit", type: :view do
|
||||
before(:each) do
|
||||
@category = assign(:category, Category.create!(
|
||||
:name => "MyString",
|
||||
:blurb => "MyString",
|
||||
:description => "MyText",
|
||||
:external_id => "MyString",
|
||||
:parent_category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit category form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_category_path(@category), "post" do
|
||||
|
||||
assert_select "input#category_name[name=?]", "category[name]"
|
||||
|
||||
assert_select "input#category_blurb[name=?]", "category[blurb]"
|
||||
|
||||
assert_select "textarea#category_description[name=?]", "category[description]"
|
||||
|
||||
assert_select "input#category_external_id[name=?]", "category[external_id]"
|
||||
|
||||
assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
spec/views/legacy/categories/index.html.erb_spec.rb
Normal file
33
spec/views/legacy/categories/index.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/categories/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:categories, [
|
||||
Category.create!(
|
||||
:name => "Name",
|
||||
:blurb => "Blurb",
|
||||
:description => "MyText",
|
||||
:external_id => "External",
|
||||
:parent_category_id => 2
|
||||
),
|
||||
Category.create!(
|
||||
:name => "Name",
|
||||
:blurb => "Blurb",
|
||||
:description => "MyText",
|
||||
:external_id => "External",
|
||||
:parent_category_id => 2
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of categories" do
|
||||
render(template: "legacy/categories/index")
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Blurb".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "MyText".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "External".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 2.to_s, :count => 2
|
||||
end
|
||||
end
|
||||
end
|
||||
32
spec/views/legacy/categories/new.html.erb_spec.rb
Normal file
32
spec/views/legacy/categories/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/categories/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:category, Category.new(
|
||||
:name => "MyString",
|
||||
:blurb => "MyString",
|
||||
:description => "MyText",
|
||||
:external_id => "MyString",
|
||||
:parent_category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new category form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_categories_path, "post" do
|
||||
|
||||
assert_select "input#category_name[name=?]", "category[name]"
|
||||
|
||||
assert_select "input#category_blurb[name=?]", "category[blurb]"
|
||||
|
||||
assert_select "textarea#category_description[name=?]", "category[description]"
|
||||
|
||||
assert_select "input#category_external_id[name=?]", "category[external_id]"
|
||||
|
||||
assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
spec/views/legacy/categories/show.html.erb_spec.rb
Normal file
20
spec/views/legacy/categories/show.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "categories/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create(name: 'School'))
|
||||
@category = assign(:category, Category.create!(
|
||||
:name => "Category",
|
||||
:description => "MyText",
|
||||
:parent_category => Category.create(name: 'Teachers And The Teaching Environment')
|
||||
))
|
||||
@school_category = assign(:school_category, SchoolCategory.create(school: @school, category: @category))
|
||||
end
|
||||
|
||||
xit "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Category/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
expect(rendered).to match(/Teachers And The Teaching Environment/)
|
||||
end
|
||||
end
|
||||
23
spec/views/legacy/districts/edit.html.erb_spec.rb
Normal file
23
spec/views/legacy/districts/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/districts/edit", type: :view do
|
||||
before(:each) do
|
||||
@district = assign(:district, Legacy::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
|
||||
end
|
||||
23
spec/views/legacy/districts/new.html.erb_spec.rb
Normal file
23
spec/views/legacy/districts/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/districts/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:district, Legacy::District.new(
|
||||
:name => "MyString",
|
||||
:state_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new district form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_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
|
||||
end
|
||||
25
spec/views/legacy/districts/show.html.erb_spec.rb
Normal file
25
spec/views/legacy/districts/show.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/districts/show", type: :view do
|
||||
before(:each) do
|
||||
@district = assign(:district, Legacy::District.create!(
|
||||
:name => "Milford",
|
||||
:state_id => 2
|
||||
))
|
||||
|
||||
schools = []
|
||||
3.times { |i| schools << @district.schools.create!(name: "School #{i}") }
|
||||
@schools = assign(:schools, schools)
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render(template: "legacy/districts/show")
|
||||
expect(rendered).to match(/Milford/)
|
||||
expect(rendered).to match(/2/)
|
||||
3.times do |i|
|
||||
expect(rendered).to match(/School #{i}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
26
spec/views/legacy/question_lists/edit.html.erb_spec.rb
Normal file
26
spec/views/legacy/question_lists/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/question_lists/edit", type: :view do
|
||||
before(:each) do
|
||||
@question_list = assign(:question_list, QuestionList.create!(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:question_ids => "MyText"
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit question_list form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_question_list_path(@question_list), "post" do
|
||||
|
||||
assert_select "input#question_list_name[name=?]", "question_list[name]"
|
||||
|
||||
assert_select "textarea#question_list_description[name=?]", "question_list[description]"
|
||||
|
||||
assert_select "input[name=?]", "question_list[question_id_array][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
spec/views/legacy/question_lists/index.html.erb_spec.rb
Normal file
28
spec/views/legacy/question_lists/index.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/question_lists/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:question_lists, [
|
||||
QuestionList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:question_ids => "1,2,3"
|
||||
),
|
||||
QuestionList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:question_ids => "2,3,4"
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of question_lists" do
|
||||
render(template: "legacy/question_lists/index")
|
||||
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 => "1,2,3".to_s, :count => 1
|
||||
assert_select "tr>td", :text => "2,3,4".to_s, :count => 1
|
||||
end
|
||||
end
|
||||
end
|
||||
26
spec/views/legacy/question_lists/new.html.erb_spec.rb
Normal file
26
spec/views/legacy/question_lists/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/question_lists/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:question_list, QuestionList.new(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:question_ids => "MyText"
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new question_list form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_question_lists_path, "post" do
|
||||
|
||||
assert_select "input#question_list_name[name=?]", "question_list[name]"
|
||||
|
||||
assert_select "textarea#question_list_description[name=?]", "question_list[description]"
|
||||
|
||||
assert_select "input[name=?]", "question_list[question_id_array][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
spec/views/legacy/question_lists/show.html.erb_spec.rb
Normal file
20
spec/views/legacy/question_lists/show.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/question_lists/show", type: :view do
|
||||
before(:each) do
|
||||
@question_list = assign(:question_list, QuestionList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:question_ids => "MyText"
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render(template: "legacy/question_lists/show")
|
||||
expect(rendered).to match(/Name/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
end
|
||||
end
|
||||
end
|
||||
38
spec/views/legacy/questions/edit.html.erb_spec.rb
Normal file
38
spec/views/legacy/questions/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/questions/edit", type: :view do
|
||||
before(:each) do
|
||||
@question = assign(:question, Question.create!(
|
||||
:text => "MyString",
|
||||
:option1 => "MyString",
|
||||
:option2 => "MyString",
|
||||
:option3 => "MyString",
|
||||
:option4 => "MyString",
|
||||
:option5 => "MyString",
|
||||
:category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit question form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_question_path(@question), "post" do
|
||||
|
||||
assert_select "input#question_text[name=?]", "question[text]"
|
||||
|
||||
assert_select "input#question_option1[name=?]", "question[option1]"
|
||||
|
||||
assert_select "input#question_option2[name=?]", "question[option2]"
|
||||
|
||||
assert_select "input#question_option3[name=?]", "question[option3]"
|
||||
|
||||
assert_select "input#question_option4[name=?]", "question[option4]"
|
||||
|
||||
assert_select "input#question_option5[name=?]", "question[option5]"
|
||||
|
||||
assert_select "input#question_category_id[name=?]", "question[category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
40
spec/views/legacy/questions/index.html.erb_spec.rb
Normal file
40
spec/views/legacy/questions/index.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/questions/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:questions, [
|
||||
Question.create!(
|
||||
:text => "Text",
|
||||
:option1 => "Option1",
|
||||
:option2 => "Option2",
|
||||
:option3 => "Option3",
|
||||
:option4 => "Option4",
|
||||
:option5 => "Option5",
|
||||
:category => Category.create(name: "Category 1")
|
||||
),
|
||||
Question.create!(
|
||||
:text => "Text",
|
||||
:option1 => "Option1",
|
||||
:option2 => "Option2",
|
||||
:option3 => "Option3",
|
||||
:option4 => "Option4",
|
||||
:option5 => "Option5",
|
||||
:category => Category.create(name: "Category 2")
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of questions" do
|
||||
render(template: "legacy/questions/index")
|
||||
assert_select "tr>td", :text => "Text".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Option1".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Option2".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Option3".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Option4".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Option5".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Category 1", :count => 1
|
||||
assert_select "tr>td", :text => "Category 2", :count => 1
|
||||
end
|
||||
end
|
||||
end
|
||||
38
spec/views/legacy/questions/new.html.erb_spec.rb
Normal file
38
spec/views/legacy/questions/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/questions/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:question, Question.new(
|
||||
:text => "MyString",
|
||||
:option1 => "MyString",
|
||||
:option2 => "MyString",
|
||||
:option3 => "MyString",
|
||||
:option4 => "MyString",
|
||||
:option5 => "MyString",
|
||||
:category_id => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new question form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_questions_path, "post" do
|
||||
|
||||
assert_select "input#question_text[name=?]", "question[text]"
|
||||
|
||||
assert_select "input#question_option1[name=?]", "question[option1]"
|
||||
|
||||
assert_select "input#question_option2[name=?]", "question[option2]"
|
||||
|
||||
assert_select "input#question_option3[name=?]", "question[option3]"
|
||||
|
||||
assert_select "input#question_option4[name=?]", "question[option4]"
|
||||
|
||||
assert_select "input#question_option5[name=?]", "question[option5]"
|
||||
|
||||
assert_select "input#question_category_id[name=?]", "question[category_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
30
spec/views/legacy/questions/show.html.erb_spec.rb
Normal file
30
spec/views/legacy/questions/show.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/questions/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
@question = assign(:question, Question.create!(
|
||||
:text => "Question Text",
|
||||
:option1 => "Option1",
|
||||
:option2 => "Option2",
|
||||
:option3 => "Option3",
|
||||
:option4 => "Option4",
|
||||
:option5 => "Option5",
|
||||
:category => Category.create!(name: 'Category Name')
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render(template: "legacy/questions/show")
|
||||
expect(rendered).to match(/School/)
|
||||
expect(rendered).to match(/Question Text/)
|
||||
expect(rendered).to match(/Option1/)
|
||||
expect(rendered).to match(/Option2/)
|
||||
expect(rendered).to match(/Option3/)
|
||||
expect(rendered).to match(/Option4/)
|
||||
expect(rendered).to match(/Option5/)
|
||||
expect(rendered).to match(/Category Name/)
|
||||
end
|
||||
end
|
||||
end
|
||||
31
spec/views/legacy/recipient_lists/edit.html.erb_spec.rb
Normal file
31
spec/views/legacy/recipient_lists/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipient_lists/edit", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
:name => "School"
|
||||
))
|
||||
|
||||
@recipient_list = assign(:recipient_list, RecipientList.create!(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:recipient_ids => "1,2,3",
|
||||
:school_id => @school.id
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit recipient_list form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_list_path(@school, @recipient_list), "post" do
|
||||
|
||||
assert_select "input#recipient_list_name[name=?]", "recipient_list[name]"
|
||||
|
||||
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
|
||||
|
||||
assert_select "input[name=?]", "recipient_list[recipient_id_array][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
32
spec/views/legacy/recipient_lists/index.html.erb_spec.rb
Normal file
32
spec/views/legacy/recipient_lists/index.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipient_lists/index", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
assign(:recipient_lists, [
|
||||
RecipientList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:recipient_ids => "1,2,3",
|
||||
:school_id => @school.id
|
||||
),
|
||||
RecipientList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:recipient_ids => "2,3,4",
|
||||
:school_id => @school.id
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of recipient_lists" 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 => "1,2,3".to_s, :count => 1
|
||||
assert_select "tr>td", :text => "2,3,4".to_s, :count => 1
|
||||
end
|
||||
end
|
||||
end
|
||||
28
spec/views/legacy/recipient_lists/new.html.erb_spec.rb
Normal file
28
spec/views/legacy/recipient_lists/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipient_lists/new", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
@recipient_list = assign(:recipient_list, RecipientList.new(
|
||||
:name => "MyString",
|
||||
:description => "MyText",
|
||||
:recipient_ids => "MyText",
|
||||
:school_id => @school.id
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new recipient_list form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_lists_path(@school, @recipient_list), "post" do
|
||||
assert_select "input#recipient_list_name[name=?]", "recipient_list[name]"
|
||||
|
||||
assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]"
|
||||
|
||||
assert_select "input[name=?]", "recipient_list[recipient_id_array][]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
spec/views/legacy/recipient_lists/show.html.erb_spec.rb
Normal file
28
spec/views/legacy/recipient_lists/show.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipient_lists/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(name: 'School'))
|
||||
|
||||
recipients = ['Jared Cosulich', 'Lauren Cosulich'].collect do |name|
|
||||
@school.recipients.create!(name: name)
|
||||
end
|
||||
|
||||
@recipient_list = assign(:recipient_list, RecipientList.create!(
|
||||
:name => "Name",
|
||||
:description => "MyText",
|
||||
:recipient_id_array => recipients.map(&:id),
|
||||
:school_id => @school.id
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/Name/)
|
||||
expect(rendered).to match(/MyText/)
|
||||
expect(rendered).to match(/Jared Cosulich/)
|
||||
expect(rendered).to match(/Lauren Cosulich/)
|
||||
end
|
||||
end
|
||||
end
|
||||
45
spec/views/legacy/recipients/edit.html.erb_spec.rb
Normal file
45
spec/views/legacy/recipients/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipients/edit", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:recipient, School.create!(# TODO does this need to be :school?
|
||||
:name => "School"
|
||||
))
|
||||
|
||||
@recipient = assign(:recipient, Recipient.create!(
|
||||
:name => "MyString",
|
||||
:phone => "MyString",
|
||||
:gender => "MyString",
|
||||
:race => "MyString",
|
||||
:ethnicity => "MyString",
|
||||
:home_language_id => 1,
|
||||
:income => "MyString",
|
||||
:opted_out => false,
|
||||
:school_id => @school.id
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit recipient form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_path(@school, @recipient), "post" do
|
||||
|
||||
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
||||
|
||||
assert_select "input#recipient_phone[name=?]", "recipient[phone]"
|
||||
|
||||
assert_select "input#recipient_gender[name=?]", "recipient[gender]"
|
||||
|
||||
assert_select "input#recipient_race[name=?]", "recipient[race]"
|
||||
|
||||
assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]"
|
||||
|
||||
assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]"
|
||||
|
||||
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "recipients/index", type: :view do
|
||||
RSpec.describe "legacy/recipients/index", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
@school = assign(:school, Legacy::School.create!(
|
||||
name: 'School'
|
||||
))
|
||||
|
||||
assign(:recipients, [
|
||||
Recipient.create!(
|
||||
Legacy::Recipient.create!(
|
||||
:name => "Name",
|
||||
:phone => "Phone",
|
||||
:gender => "Gender",
|
||||
|
|
@ -18,7 +18,7 @@ RSpec.describe "recipients/index", type: :view do
|
|||
:opted_out => false,
|
||||
:school_id => @school.id
|
||||
),
|
||||
Recipient.create!(
|
||||
Legacy::Recipient.create!(
|
||||
:name => "Name",
|
||||
:phone => "Phone",
|
||||
:gender => "Gender",
|
||||
|
|
@ -33,7 +33,7 @@ RSpec.describe "recipients/index", type: :view do
|
|||
end
|
||||
|
||||
it "renders a list of recipients" do
|
||||
render(template: "recipients/index")
|
||||
render(template: "legacy/recipients/index")
|
||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Phone".to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Gender".to_s, :count => 2
|
||||
45
spec/views/legacy/recipients/new.html.erb_spec.rb
Normal file
45
spec/views/legacy/recipients/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/recipients/new", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
name: 'School'
|
||||
))
|
||||
|
||||
@recipient = assign(:recipient, Recipient.new(
|
||||
:name => "MyString",
|
||||
:phone => "MyString",
|
||||
:gender => "MyString",
|
||||
:race => "MyString",
|
||||
:ethnicity => "MyString",
|
||||
:home_language_id => 1,
|
||||
:income => "MyString",
|
||||
:opted_out => false,
|
||||
:school_id => @school.to_param
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new recipient form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", legacy_school_legacy_recipients_path(@school, @recipient), "post" do
|
||||
|
||||
assert_select "input#recipient_name[name=?]", "recipient[name]"
|
||||
|
||||
assert_select "input#recipient_phone[name=?]", "recipient[phone]"
|
||||
|
||||
assert_select "input#recipient_gender[name=?]", "recipient[gender]"
|
||||
|
||||
assert_select "input#recipient_race[name=?]", "recipient[race]"
|
||||
|
||||
assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]"
|
||||
|
||||
assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]"
|
||||
|
||||
assert_select "input#recipient_income[name=?]", "recipient[income]"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "recipients/show", type: :view do
|
||||
RSpec.describe "legacy/recipients/show", type: :view do
|
||||
before(:each) do
|
||||
@school = assign(:school, School.create!(
|
||||
@school = assign(:school, Legacy::School.create!(
|
||||
name: 'School'
|
||||
))
|
||||
|
||||
@recipient = assign(:recipient, Recipient.create!(
|
||||
@recipient = assign(:recipient, Legacy::Recipient.create!(
|
||||
:name => "Name",
|
||||
:phone => "Phone",
|
||||
:gender => "Gender",
|
||||
45
spec/views/legacy/schedules/edit.html.erb_spec.rb
Normal file
45
spec/views/legacy/schedules/edit.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/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=?]", legacy_school_legacy_schedule_path(@school, @schedule), "post" do
|
||||
|
||||
assert_select "input#schedule_name[name=?]", "schedule[name]"
|
||||
|
||||
assert_select "textarea#schedule_description[name=?]", "schedule[description]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[frequency_hours]"
|
||||
|
||||
assert_select "input#schedule_active[name=?]", "schedule[active]"
|
||||
|
||||
assert_select "input#schedule_random[name=?]", "schedule[random]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[recipient_list_id]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[question_list_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
45
spec/views/legacy/schedules/new.html.erb_spec.rb
Normal file
45
spec/views/legacy/schedules/new.html.erb_spec.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module Legacy
|
||||
RSpec.describe "legacy/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=?]", legacy_school_legacy_schedules_path(@school), "post" do
|
||||
|
||||
assert_select "input#schedule_name[name=?]", "schedule[name]"
|
||||
|
||||
assert_select "textarea#schedule_description[name=?]", "schedule[description]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[frequency_hours]"
|
||||
|
||||
assert_select "input#schedule_active[name=?]", "schedule[active]"
|
||||
|
||||
assert_select "input#schedule_random[name=?]", "schedule[random]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[recipient_list_id]"
|
||||
|
||||
assert_select "select[name=?]", "schedule[question_list_id]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue