mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 15:38:21 -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue