diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb deleted file mode 100644 index 07e0061a..00000000 --- a/app/controllers/admin_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AdminController < ApplicationController - - def index - end - -end diff --git a/app/controllers/attempts_controller.rb b/app/controllers/attempts_controller.rb deleted file mode 100644 index 10d35a51..00000000 --- a/app/controllers/attempts_controller.rb +++ /dev/null @@ -1,94 +0,0 @@ -class AttemptsController < ApplicationController - # before_action :set_attempt, only: [:edit, :update] - protect_from_forgery :except => [:twilio] - - def twilio - recipient = Recipient.where(phone: twilio_params['From']).first - attempt = recipient.attempts.last_sent.first - - all_twilio_details = (attempt.twilio_details || '').split('~!~') - all_twilio_details << twilio_params.to_h.to_yaml - - attempt.save_response( - answer_index: twilio_params[:Body].to_i > 0 ? twilio_params[:Body].to_i : nil, - twilio_details: all_twilio_details.join('~!~') - ) - - unless (['start', 'resume', 'restart', 'yes', 'go'].index(twilio_params[:Body].downcase).nil?) - recipient.update(opted_out: false) - render plain: 'Thank you, you will now begin receiving messages again.' - return - end - - unless (['stop', 'cancel', 'quit', 'no'].index(twilio_params[:Body].downcase).nil?) - recipient.update(opted_out: true) - render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.' - return - end - - unless (['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil?) - render plain: 'Thank you, this question has been skipped.' - return - end - - response_message = ["We've registered your response of \"#{attempt.response}\"."] - - answer_count = Attempt.for_question(attempt.question).for_school(recipient.school).with_answer.count - if answer_count > 1 - response_message << "#{answer_count} people have responded to this question so far. To see all responses visit:" - else - response_message << 'You are the first person to respond to this question. Once more people have responded you will be able to see all responses at:' - end - response_message << school_category_url(attempt.recipient.school, attempt.question.category) - - render plain: response_message.join(' ') - end - - # # GET /attempts/1/edit - # def edit - # end - # - # # PATCH/PUT /attempts/1 - # # PATCH/PUT /attempts/1.json - # def update - # attempt_params = {} - # if twilio_params.present? - # attempt_params.merge!( - # answer_index: twilio_params[:Body].to_i, - # twilio_details: twilio_params.to_h.to_yaml - # ) - # end - # - # respond_to do |format| - # if @attempt.update(attempt_params) - # format.html { render plain: 'Thank you!' } - # format.json { render :show, status: :ok, location: @attempt } - # else - # format.html { render :edit } - # format.json { render json: @attempt.errors, status: :unprocessable_entity } - # end - # end - # end - - # # DELETE /attempts/1 - # # DELETE /attempts/1.json - # def destroy - # @attempt.destroy - # respond_to do |format| - # format.html { redirect_to attempts_url, notice: 'attempt was successfully destroyed.' } - # format.json { head :no_content } - # end - # end - - private - # Use callbacks to share common setup or constraints between actions. - def set_attempt - @attempt = Attempt.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def twilio_params - {"Body"=>"5", ""=>"US", "To"=>"+16172023890", "ToZip"=>"02135", "NumSegments"=>"1", "MessageSid"=>"SMe37977e625b7f0b429339e752dddefef", "AccountSid"=>"AC57dc8a5a6d75addb9528e730e92f66b2", "From"=>"+16502693205", "ApiVersion"=>"2010-04-01"} - params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia) - end -end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 4900a994..28648b63 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,104 +1,9 @@ -class CategoriesController < ApplicationController - before_action :set_school, only: [:show] - before_action :set_category, only: [:show, :edit, :update, :destroy] +class CategoriesController < SqmApplicationController - # GET /categories - # GET /categories.json - def index - @categories = Category.all - end - - # GET /categories/1 - # GET /categories/1.json def show - district = @school.district - authenticate(district.name.downcase, "#{district.name.downcase}!") - - school_categories = SchoolCategory.for(@school, @category) - @years = school_categories.map(&:year).map(&:to_i).sort - @year = (params[:year] || @years.last || "2019").to_i - - if school_categories.empty? - school_categories = [SchoolCategory.new(school: @school, category: @category, year: @year)] - end - - @school_category = school_categories.select { |sc| sc.year.to_s == @year.to_s }.first - @child_school_categories = SchoolCategory.for_parent_category(@school, @category).in(@year).valid.to_a - missing_categories = Category.for_parent(@category) - @child_school_categories.map(&:category) - missing_categories.each do |category| - next if category.benchmark.present? - @child_school_categories << category.school_categories.new(school: @school) - end - - if district.name == "Boston" - @child_school_categories = @child_school_categories.reject { |csc| csc.admin? } - end - - @questions = @category.questions.created_in(@year) - end - - # GET /categories/new - def new - @category = Category.new - end + @categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) } - # GET /categories/1/edit - def edit + @category = CategoryPresenter.new(category: Category.find_by_slug(params[:id])) end - # POST /categories - # POST /categories.json - def create - @category = Category.new(category_params) - - respond_to do |format| - if @category.save - format.html { redirect_to @category, notice: 'Category was successfully created.' } - format.json { render :show, status: :created, location: @category } - else - format.html { render :new } - format.json { render json: @category.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /categories/1 - # PATCH/PUT /categories/1.json - def update - respond_to do |format| - if @category.update(category_params) - format.html { redirect_to @category, notice: 'Category was successfully updated.' } - format.json { render :show, status: :ok, location: @category } - else - format.html { render :edit } - format.json { render json: @category.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /categories/1 - # DELETE /categories/1.json - def destroy - @category.destroy - respond_to do |format| - format.html { redirect_to categories_url, notice: 'Category was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - def set_school - redirect_to root_path and return false unless params.include?(:school_id) - @school = School.friendly.find(params[:school_id]) - redirect_to root_path and return false if @school.nil? - end - - def set_category - @category = Category.friendly.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def category_params - params.require(:category).permit(:name, :blurb, :description, :external_id, :parent_category_id) - end end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index b0f65164..d4f1fc35 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,7 +2,7 @@ class DashboardController < SqmApplicationController def index @variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure)) - @category_presenters = SqmCategory.sorted.map { |sqm_category| CategoryPresenter.new(category: sqm_category) } + @category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category: category) } end private diff --git a/app/controllers/districts_controller.rb b/app/controllers/districts_controller.rb deleted file mode 100644 index aacc239a..00000000 --- a/app/controllers/districts_controller.rb +++ /dev/null @@ -1,76 +0,0 @@ -class DistrictsController < ApplicationController - before_action :set_district, only: [:show, :edit, :update, :destroy] - - # GET /districts - # GET /districts.json - def index - @districts = District.all.alphabetic - end - - # GET /districts/1 - # GET /districts/1.json - def show - authenticate(@district.name.downcase, "#{@district.name.downcase}!") - @schools = @district.schools.alphabetic - end - - # GET /districts/new - def new - @district = District.new - end - - # GET /districts/1/edit - def edit - end - - # POST /districts - # POST /districts.json - def create - @district = District.new(district_params) - - respond_to do |format| - if @district.save - format.html { redirect_to @district, notice: 'District was successfully created.' } - format.json { render :show, status: :created, location: @district } - else - format.html { render :new } - format.json { render json: @district.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /districts/1 - # PATCH/PUT /districts/1.json - def update - respond_to do |format| - if @district.update(district_params) - format.html { redirect_to @district, notice: 'District was successfully updated.' } - format.json { render :show, status: :ok, location: @district } - else - format.html { render :edit } - format.json { render json: @district.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /districts/1 - # DELETE /districts/1.json - def destroy - @district.destroy - respond_to do |format| - format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_district - @district = District.find_by_slug(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def district_params - params.require(:district).permit(:name, :state_id) - end -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index a05e39f6..743557b0 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,6 +3,6 @@ class HomeController < ActionController::Base @districts = District.all.order(:name) @schools = School.all - @categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) } + @categories = Category.sorted.map { |category| CategoryPresenter.new(category: category) } end end diff --git a/app/controllers/legacy/admin_controller.rb b/app/controllers/legacy/admin_controller.rb new file mode 100644 index 00000000..4e7f572f --- /dev/null +++ b/app/controllers/legacy/admin_controller.rb @@ -0,0 +1,8 @@ +module Legacy + class AdminController < ApplicationController + + def index + end + + end +end diff --git a/app/controllers/legacy/attempts_controller.rb b/app/controllers/legacy/attempts_controller.rb new file mode 100644 index 00000000..4a682e68 --- /dev/null +++ b/app/controllers/legacy/attempts_controller.rb @@ -0,0 +1,97 @@ +module Legacy + class AttemptsController < ApplicationController + # before_action :set_attempt, only: [:edit, :update] + protect_from_forgery :except => [:twilio] + + def twilio + recipient = Recipient.where(phone: twilio_params['From']).first + attempt = recipient.attempts.last_sent.first + + all_twilio_details = (attempt.twilio_details || '').split('~!~') + all_twilio_details << twilio_params.to_h.to_yaml + + attempt.save_response( + answer_index: twilio_params[:Body].to_i > 0 ? twilio_params[:Body].to_i : nil, + twilio_details: all_twilio_details.join('~!~') + ) + + unless (['start', 'resume', 'restart', 'yes', 'go'].index(twilio_params[:Body].downcase).nil?) + recipient.update(opted_out: false) + render plain: 'Thank you, you will now begin receiving messages again.' + return + end + + unless (['stop', 'cancel', 'quit', 'no'].index(twilio_params[:Body].downcase).nil?) + recipient.update(opted_out: true) + render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.' + return + end + + unless (['skip', 'i dont know', "i don't know", 'next'].index(twilio_params[:Body].downcase).nil?) + render plain: 'Thank you, this question has been skipped.' + return + end + + response_message = ["We've registered your response of \"#{attempt.response}\"."] + + answer_count = Attempt.for_question(attempt.question).for_school(recipient.school).with_answer.count + if answer_count > 1 + response_message << "#{answer_count} people have responded to this question so far. To see all responses visit:" + else + response_message << 'You are the first person to respond to this question. Once more people have responded you will be able to see all responses at:' + end + response_message << legacy_school_legacy_category_url(attempt.recipient.school, attempt.question.category) + + render plain: response_message.join(' ') + end + + # # GET /attempts/1/edit + # def edit + # end + # + # # PATCH/PUT /attempts/1 + # # PATCH/PUT /attempts/1.json + # def update + # attempt_params = {} + # if twilio_params.present? + # attempt_params.merge!( + # answer_index: twilio_params[:Body].to_i, + # twilio_details: twilio_params.to_h.to_yaml + # ) + # end + # + # respond_to do |format| + # if @attempt.update(attempt_params) + # format.html { render plain: 'Thank you!' } + # format.json { render :show, status: :ok, location: @attempt } + # else + # format.html { render :edit } + # format.json { render json: @attempt.errors, status: :unprocessable_entity } + # end + # end + # end + + # # DELETE /attempts/1 + # # DELETE /attempts/1.json + # def destroy + # @attempt.destroy + # respond_to do |format| + # format.html { redirect_to attempts_url, notice: 'attempt was successfully destroyed.' } + # format.json { head :no_content } + # end + # end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_attempt + @attempt = Attempt.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def twilio_params + { "Body" => "5", "" => "US", "To" => "+16172023890", "ToZip" => "02135", "NumSegments" => "1", "MessageSid" => "SMe37977e625b7f0b429339e752dddefef", "AccountSid" => "AC57dc8a5a6d75addb9528e730e92f66b2", "From" => "+16502693205", "ApiVersion" => "2010-04-01" } + params.permit(:FromCountry, :FromState, :FromZip, :FromCity, :ToCountry, :ToState, :SmsStatus, :SmsSid, :SmsMessageSid, :MessageSid, :AccountSid, :MessagingServiceSid, :From, :To, :Body, :NumMedia) + end + end +end diff --git a/app/controllers/legacy/categories_controller.rb b/app/controllers/legacy/categories_controller.rb new file mode 100644 index 00000000..0232652b --- /dev/null +++ b/app/controllers/legacy/categories_controller.rb @@ -0,0 +1,107 @@ +module Legacy + class CategoriesController < ApplicationController + before_action :set_school, only: [:show] + before_action :set_category, only: [:show, :edit, :update, :destroy] + + # GET /categories + # GET /categories.json + def index + @categories = Category.all + end + + # GET /categories/1 + # GET /categories/1.json + def show + district = @school.district + authenticate(district.name.downcase, "#{district.name.downcase}!") + + school_categories = SchoolCategory.for(@school, @category) + @years = school_categories.map(&:year).map(&:to_i).sort + @year = (params[:year] || @years.last || "2019").to_i + + if school_categories.empty? + school_categories = [SchoolCategory.new(school: @school, category: @category, year: @year)] + end + + @school_category = school_categories.select { |sc| sc.year.to_s == @year.to_s }.first + @child_school_categories = SchoolCategory.for_parent_category(@school, @category).in(@year).valid.to_a + missing_categories = Category.for_parent(@category) - @child_school_categories.map(&:category) + missing_categories.each do |category| + next if category.benchmark.present? + @child_school_categories << category.school_categories.new(school: @school) + end + + if district.name == "Boston" + @child_school_categories = @child_school_categories.reject { |csc| csc.admin? } + end + + @questions = @category.questions.created_in(@year) + end + + # GET /categories/new + def new + @category = Category.new + end + + # GET /categories/1/edit + def edit + end + + # POST /categories + # POST /categories.json + def create + @category = Category.new(category_params) + + respond_to do |format| + if @category.save + format.html { redirect_to @category, notice: 'Category was successfully created.' } + format.json { render :show, status: :created, location: @category } + else + format.html { render :new } + format.json { render json: @category.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /categories/1 + # PATCH/PUT /categories/1.json + def update + respond_to do |format| + if @category.update(category_params) + format.html { redirect_to @category, notice: 'Category was successfully updated.' } + format.json { render :show, status: :ok, location: @category } + else + format.html { render :edit } + format.json { render json: @category.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /categories/1 + # DELETE /categories/1.json + def destroy + @category.destroy + respond_to do |format| + format.html { redirect_to legacy_categories_url, notice: 'Category was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + def set_school + redirect_to root_path and return false unless params.include?(:school_id) + @school = School.friendly.find(params[:school_id]) + redirect_to root_path and return false if @school.nil? + end + + def set_category + @category = Category.friendly.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def category_params + params.require(:category).permit(:name, :blurb, :description, :external_id, :parent_category_id) + end + end +end diff --git a/app/controllers/legacy/districts_controller.rb b/app/controllers/legacy/districts_controller.rb new file mode 100644 index 00000000..e4c988b6 --- /dev/null +++ b/app/controllers/legacy/districts_controller.rb @@ -0,0 +1,79 @@ +module Legacy + class DistrictsController < ApplicationController + before_action :set_district, only: [:show, :edit, :update, :destroy] + + # GET /districts + # GET /districts.json + def index + @districts = District.all.alphabetic + end + + # GET /districts/1 + # GET /districts/1.json + def show + authenticate(@district.name.downcase, "#{@district.name.downcase}!") + @schools = @district.schools.alphabetic + end + + # GET /districts/new + def new + @district = District.new + end + + # GET /districts/1/edit + def edit + end + + # POST /districts + # POST /districts.json + def create + @district = District.new(district_params) + + respond_to do |format| + if @district.save + format.html { redirect_to @district, notice: 'District was successfully created.' } + format.json { render :show, status: :created, location: @district } + else + format.html { render :new } + format.json { render json: @district.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /districts/1 + # PATCH/PUT /districts/1.json + def update + respond_to do |format| + if @district.update(district_params) + format.html { redirect_to @district, notice: 'District was successfully updated.' } + format.json { render :show, status: :ok, location: @district } + else + format.html { render :edit } + format.json { render json: @district.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /districts/1 + # DELETE /districts/1.json + def destroy + @district.destroy + respond_to do |format| + format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_district + @district = District.find_by_slug(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def district_params + params.require(:district).permit(:name, :state_id) + end + end +end diff --git a/app/controllers/legacy/question_lists_controller.rb b/app/controllers/legacy/question_lists_controller.rb new file mode 100644 index 00000000..1d3914c8 --- /dev/null +++ b/app/controllers/legacy/question_lists_controller.rb @@ -0,0 +1,77 @@ +module Legacy + class QuestionListsController < ApplicationController + before_action :set_question_list, only: [:show, :edit, :update, :destroy] + + # GET /question_lists + # GET /question_lists.json + def index + @question_lists = QuestionList.all + end + + # GET /question_lists/1 + # GET /question_lists/1.json + def show + end + + # GET /question_lists/new + def new + @question_list = QuestionList.new + end + + # GET /question_lists/1/edit + def edit + end + + # POST /question_lists + # POST /question_lists.json + def create + @question_list = QuestionList.new(question_list_params) + + respond_to do |format| + if @question_list.save + format.html { redirect_to @question_list, notice: 'Question list was successfully created.' } + format.json { render :show, status: :created, location: @question_list } + else + format.html { render :new } + format.json { render json: @question_list.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /question_lists/1 + # PATCH/PUT /question_lists/1.json + def update + respond_to do |format| + if @question_list.update(question_list_params) + format.html { redirect_to @question_list, notice: 'Question list was successfully updated.' } + format.json { render :show, status: :ok, location: @question_list } + else + format.html { render :edit } + format.json { render json: @question_list.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /question_lists/1 + # DELETE /question_lists/1.json + def destroy + @question_list.destroy + respond_to do |format| + format.html { redirect_to legacy_question_lists_url, notice: 'Question list was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_question_list + @question_list = QuestionList.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def question_list_params + params.require(:question_list).permit(:name, :description, question_id_array: []) + end + end +end diff --git a/app/controllers/legacy/questions_controller.rb b/app/controllers/legacy/questions_controller.rb new file mode 100644 index 00000000..c7b369ff --- /dev/null +++ b/app/controllers/legacy/questions_controller.rb @@ -0,0 +1,90 @@ +module Legacy + class QuestionsController < ApplicationController + before_action :authenticate_user!, except: [:show] + before_action :verify_super_admin, except: [:show] + before_action :set_school, only: [:show] + before_action :set_question, only: [:show, :edit, :update, :destroy] + + # GET /questions + # GET /questions.json + def index + @questions = Question.all + end + + # GET /questions/1 + # GET /questions/1.json + def show + end + + # GET /questions/new + def new + @question = Question.new + end + + # GET /questions/1/edit + def edit + end + + # POST /questions + # POST /questions.json + def create + @question = Question.new(question_params) + + respond_to do |format| + if @question.save + format.html { redirect_to @question, notice: 'Question was successfully created.' } + format.json { render :show, status: :created, location: @question } + else + format.html { render :new } + format.json { render json: @question.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /questions/1 + # PATCH/PUT /questions/1.json + def update + respond_to do |format| + if @question.update(question_params) + format.html { redirect_to @question, notice: 'Question was successfully updated.' } + format.json { render :show, status: :ok, location: @question } + else + format.html { render :edit } + format.json { render json: @question.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /questions/1 + # DELETE /questions/1.json + def destroy + @question.destroy + respond_to do |format| + format.html { redirect_to legacy_questions_url, notice: 'Question was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + def set_school + redirect_to root_path and return false unless params.include?(:school_id) + @school = School.friendly.find(params[:school_id]) + redirect_to root_path and return false if @school.nil? + end + + # Use callbacks to share common setup or constraints between actions. + def set_question + @question = Question.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def question_params + params.require(:question).permit(:text, :option1, :option2, :option3, :option4, :option5, :category_id) + end + + def verify_super_admin + user_signed_in? && current_user.super_admin? + end + end +end diff --git a/app/controllers/legacy/recipient_lists_controller.rb b/app/controllers/legacy/recipient_lists_controller.rb new file mode 100644 index 00000000..e8b8969e --- /dev/null +++ b/app/controllers/legacy/recipient_lists_controller.rb @@ -0,0 +1,69 @@ +module Legacy + class RecipientListsController < ApplicationController + before_action :authenticate_user! + before_action :set_school + before_action :verify_admin + before_action :set_recipient_list, only: [:show, :edit, :update, :destroy] + + # GET schools/1/recipient_lists + def index + @recipient_lists = @school.recipient_lists + end + + # GET schools/1/recipient_lists/1 + def show + end + + # GET schools/1/recipient_lists/new + def new + @recipient_list = @school.recipient_lists.build + end + + # GET schools/1/recipient_lists/1/edit + def edit + end + + # POST schools/1/recipient_lists + def create + @recipient_list = @school.recipient_lists.build(recipient_list_params) + + if @recipient_list.save + redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully created.') + else + render action: 'new' + end + end + + # PUT schools/1/recipient_lists/1 + def update + if @recipient_list.update(recipient_list_params) + redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully updated.') + else + render action: 'edit' + end + end + + # DELETE schools/1/recipient_lists/1 + def destroy + @recipient_list.destroy + + redirect_to @school + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_school + @school = School.friendly.find(params[:school_id]) + end + + def set_recipient_list + @recipient_list = @school.recipient_lists.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def recipient_list_params + params.require(:recipient_list).permit(:name, :description, recipient_id_array: []) + end + end +end diff --git a/app/controllers/legacy/recipients_controller.rb b/app/controllers/legacy/recipients_controller.rb new file mode 100644 index 00000000..1e864a9b --- /dev/null +++ b/app/controllers/legacy/recipients_controller.rb @@ -0,0 +1,92 @@ +module Legacy + class RecipientsController < ApplicationController + before_action :authenticate_user! + before_action :set_school + before_action :verify_admin + before_action :set_recipient, only: [:show, :edit, :update, :destroy] + + # GET /recipients + # GET /recipients.json + def index + @recipients = @school.recipients.all + end + + # GET /recipients/1 + # GET /recipients/1.json + def show + end + + # GET /recipients/new + def new + @recipient = @school.recipients.new + end + + # GET /recipients/1/edit + def edit + end + + # POST /recipients + # POST /recipients.json + def create + @recipient = @school.recipients.new(recipient_params) + + respond_to do |format| + if @recipient.save + format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' } + format.json { render :show, status: :created, location: @recipient } + else + format.html { render :new } + format.json { render json: @recipient.errors, status: :unprocessable_entity } + end + end + end + + def import + render and return if request.get? + + Recipient.import(@school, params[:file]) + redirect_to @school, notice: "Recipients imported." + end + + # PATCH/PUT /recipients/1 + # PATCH/PUT /recipients/1.json + def update + respond_to do |format| + if @recipient.update(recipient_params) + format.html { redirect_to legacy_school_legacy_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' } + format.json { render :show, status: :ok, location: @recipient } + else + format.html { render :edit } + format.json { render json: @recipient.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /recipients/1 + # DELETE /recipients/1.json + def destroy + @recipient.destroy + respond_to do |format| + format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_school + @school = School.friendly.find(params[:school_id]) + end + + # Use callbacks to share common setup or constraints between actions. + def set_recipient + @recipient = @school.recipients.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def recipient_params + params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id) + end + end +end diff --git a/app/controllers/legacy/schedules_controller.rb b/app/controllers/legacy/schedules_controller.rb new file mode 100644 index 00000000..15b1d1dc --- /dev/null +++ b/app/controllers/legacy/schedules_controller.rb @@ -0,0 +1,71 @@ +module Legacy + class SchedulesController < ApplicationController + before_action :authenticate_user!, except: [:show] + before_action :set_school + before_action :verify_admin + before_action :set_schedule, only: [:show, :edit, :update, :destroy] + before_action :set_time, only: [:create, :update] + + # GET schools/1/schedules/1 + def show + end + + # GET schools/1/schedules/new + def new + @schedule = @school.schedules.build + end + + # GET schools/1/schedules/1/edit + def edit + end + + # POST schools/1/schedules + def create + @schedule = @school.schedules.build(schedule_params) + + if @schedule.save + redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.') + else + render action: 'new' + end + end + + # PUT schools/1/schedules/1 + def update + if @schedule.update(schedule_params) + redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.') + else + render action: 'edit' + end + end + + # DELETE schools/1/schedules/1 + def destroy + @schedule.destroy + + redirect_to @school + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_school + @school = School.friendly.find(params[:school_id]) + end + + def set_schedule + @schedule = @school.schedules.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def schedule_params + params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id) + end + + def set_time + return unless schedule_params.include?(:time) + params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER) + end + + end +end diff --git a/app/controllers/legacy/schools_controller.rb b/app/controllers/legacy/schools_controller.rb new file mode 100644 index 00000000..e86deba8 --- /dev/null +++ b/app/controllers/legacy/schools_controller.rb @@ -0,0 +1,97 @@ +module Legacy + class SchoolsController < ApplicationController + before_action :authenticate_user!, except: [:show] + before_action :set_school, only: [:admin, :show, :edit, :update, :destroy] + before_action :verify_admin, except: [:show, :create, :new] + + # GET /schools/1 + # GET /schools/1.json + def show + @district = @school.district + authenticate(@district.name.downcase, "#{@district.name.downcase}!") + + @years = [2017, 2018, 2019] + @year = (params[:year] || @years.last).to_i + + if @district.name == "Boston" + @categories = Category.joins(:questions) + @school_categories = SchoolCategory.where(school: @school).where(category: @categories).in(@year).to_a + else + @categories = Category.root + @school_categories = @school.school_categories.for_parent_category(@school, nil).valid.in(@year).sort + end + + missing_categories = @categories - @school_categories.map(&:category) + missing_categories.each do |category| + @school_categories << category.school_categories.new(school: @school, year: @year) + end + + @school_categories = @school_categories.select { |sc| sc.year.to_i == @year } + end + + def admin + end + + # GET /schools/new + def new + @school = School.new + end + + # GET /schools/1/edit + def edit + end + + # POST /schools + # POST /schools.json + def create + @school = School.new(school_params) + + respond_to do |format| + if @school.save + format.html { redirect_to @school, notice: 'School was successfully created.' } + format.json { render :show, status: :created, location: @school } + else + format.html { render :new } + format.json { render json: @school.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /schools/1 + # PATCH/PUT /schools/1.json + def update + respond_to do |format| + if @school.update(school_params) + format.html { redirect_to @school, notice: 'School was successfully updated.' } + format.json { render :show, status: :ok, location: @school } + else + format.html { render :edit } + format.json { render json: @school.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /schools/1 + # DELETE /schools/1.json + def destroy + @school.destroy + respond_to do |format| + format.html { redirect_to legacy_schools_url, notice: 'School was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_school + @school = School.friendly.find(params[:id] || params[:school_id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def school_params + params.require(:school).permit(:name, :district_id) + end + + end +end diff --git a/app/controllers/legacy/users_controller.rb b/app/controllers/legacy/users_controller.rb new file mode 100644 index 00000000..56dd2edf --- /dev/null +++ b/app/controllers/legacy/users_controller.rb @@ -0,0 +1,16 @@ +module Legacy + class UsersController < ApplicationController + def show; end + + # private + # # Use callbacks to share common setup or constraints between actions. + # def set_district + # @district = District.find(params[:id]) + # end + # + # # Never trust parameters from the scary internet, only allow the white list through. + # def district_params + # params.require(:district).permit(:name, :state_id) + # end + end +end diff --git a/app/controllers/legacy/welcome_controller.rb b/app/controllers/legacy/welcome_controller.rb new file mode 100644 index 00000000..9fe15c62 --- /dev/null +++ b/app/controllers/legacy/welcome_controller.rb @@ -0,0 +1,10 @@ +module Legacy + class WelcomeController < ApplicationController + + def index + @districts = District.all.alphabetic + @schools = School.all.alphabetic + end + + end +end diff --git a/app/controllers/question_lists_controller.rb b/app/controllers/question_lists_controller.rb deleted file mode 100644 index daf90aac..00000000 --- a/app/controllers/question_lists_controller.rb +++ /dev/null @@ -1,74 +0,0 @@ -class QuestionListsController < ApplicationController - before_action :set_question_list, only: [:show, :edit, :update, :destroy] - - # GET /question_lists - # GET /question_lists.json - def index - @question_lists = QuestionList.all - end - - # GET /question_lists/1 - # GET /question_lists/1.json - def show - end - - # GET /question_lists/new - def new - @question_list = QuestionList.new - end - - # GET /question_lists/1/edit - def edit - end - - # POST /question_lists - # POST /question_lists.json - def create - @question_list = QuestionList.new(question_list_params) - - respond_to do |format| - if @question_list.save - format.html { redirect_to @question_list, notice: 'Question list was successfully created.' } - format.json { render :show, status: :created, location: @question_list } - else - format.html { render :new } - format.json { render json: @question_list.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /question_lists/1 - # PATCH/PUT /question_lists/1.json - def update - respond_to do |format| - if @question_list.update(question_list_params) - format.html { redirect_to @question_list, notice: 'Question list was successfully updated.' } - format.json { render :show, status: :ok, location: @question_list } - else - format.html { render :edit } - format.json { render json: @question_list.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /question_lists/1 - # DELETE /question_lists/1.json - def destroy - @question_list.destroy - respond_to do |format| - format.html { redirect_to question_lists_url, notice: 'Question list was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_question_list - @question_list = QuestionList.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def question_list_params - params.require(:question_list).permit(:name, :description, question_id_array: []) - end -end diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb deleted file mode 100644 index 9cec82c4..00000000 --- a/app/controllers/questions_controller.rb +++ /dev/null @@ -1,87 +0,0 @@ -class QuestionsController < ApplicationController - before_action :authenticate_user!, except: [:show] - before_action :verify_super_admin, except: [:show] - before_action :set_school, only: [:show] - before_action :set_question, only: [:show, :edit, :update, :destroy] - - # GET /questions - # GET /questions.json - def index - @questions = Question.all - end - - # GET /questions/1 - # GET /questions/1.json - def show - end - - # GET /questions/new - def new - @question = Question.new - end - - # GET /questions/1/edit - def edit - end - - # POST /questions - # POST /questions.json - def create - @question = Question.new(question_params) - - respond_to do |format| - if @question.save - format.html { redirect_to @question, notice: 'Question was successfully created.' } - format.json { render :show, status: :created, location: @question } - else - format.html { render :new } - format.json { render json: @question.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /questions/1 - # PATCH/PUT /questions/1.json - def update - respond_to do |format| - if @question.update(question_params) - format.html { redirect_to @question, notice: 'Question was successfully updated.' } - format.json { render :show, status: :ok, location: @question } - else - format.html { render :edit } - format.json { render json: @question.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /questions/1 - # DELETE /questions/1.json - def destroy - @question.destroy - respond_to do |format| - format.html { redirect_to questions_url, notice: 'Question was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - def set_school - redirect_to root_path and return false unless params.include?(:school_id) - @school = School.friendly.find(params[:school_id]) - redirect_to root_path and return false if @school.nil? - end - - # Use callbacks to share common setup or constraints between actions. - def set_question - @question = Question.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def question_params - params.require(:question).permit(:text, :option1, :option2, :option3, :option4, :option5, :category_id) - end - - def verify_super_admin - user_signed_in? && current_user.super_admin? - end -end diff --git a/app/controllers/recipient_lists_controller.rb b/app/controllers/recipient_lists_controller.rb deleted file mode 100644 index 33f7ba36..00000000 --- a/app/controllers/recipient_lists_controller.rb +++ /dev/null @@ -1,66 +0,0 @@ -class RecipientListsController < ApplicationController - before_action :authenticate_user! - before_action :set_school - before_action :verify_admin - before_action :set_recipient_list, only: [:show, :edit, :update, :destroy] - - # GET schools/1/recipient_lists - def index - @recipient_lists = @school.recipient_lists - end - - # GET schools/1/recipient_lists/1 - def show - end - - # GET schools/1/recipient_lists/new - def new - @recipient_list = @school.recipient_lists.build - end - - # GET schools/1/recipient_lists/1/edit - def edit - end - - # POST schools/1/recipient_lists - def create - @recipient_list = @school.recipient_lists.build(recipient_list_params) - - if @recipient_list.save - redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully created.') - else - render action: 'new' - end - end - - # PUT schools/1/recipient_lists/1 - def update - if @recipient_list.update(recipient_list_params) - redirect_to([@recipient_list.school, @recipient_list], notice: 'Recipient list was successfully updated.') - else - render action: 'edit' - end - end - - # DELETE schools/1/recipient_lists/1 - def destroy - @recipient_list.destroy - - redirect_to @school - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_school - @school = School.friendly.find(params[:school_id]) - end - - def set_recipient_list - @recipient_list = @school.recipient_lists.find(params[:id]) - end - - # Only allow a trusted parameter "white list" through. - def recipient_list_params - params.require(:recipient_list).permit(:name, :description, recipient_id_array: []) - end -end diff --git a/app/controllers/recipients_controller.rb b/app/controllers/recipients_controller.rb deleted file mode 100644 index cb54e318..00000000 --- a/app/controllers/recipients_controller.rb +++ /dev/null @@ -1,89 +0,0 @@ -class RecipientsController < ApplicationController - before_action :authenticate_user! - before_action :set_school - before_action :verify_admin - before_action :set_recipient, only: [:show, :edit, :update, :destroy] - - # GET /recipients - # GET /recipients.json - def index - @recipients = @school.recipients.all - end - - # GET /recipients/1 - # GET /recipients/1.json - def show - end - - # GET /recipients/new - def new - @recipient = @school.recipients.new - end - - # GET /recipients/1/edit - def edit - end - - # POST /recipients - # POST /recipients.json - def create - @recipient = @school.recipients.new(recipient_params) - - respond_to do |format| - if @recipient.save - format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' } - format.json { render :show, status: :created, location: @recipient } - else - format.html { render :new } - format.json { render json: @recipient.errors, status: :unprocessable_entity } - end - end - end - - def import - render and return if request.get? - - Recipient.import(@school, params[:file]) - redirect_to @school, notice: "Recipients imported." - end - - # PATCH/PUT /recipients/1 - # PATCH/PUT /recipients/1.json - def update - respond_to do |format| - if @recipient.update(recipient_params) - format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' } - format.json { render :show, status: :ok, location: @recipient } - else - format.html { render :edit } - format.json { render json: @recipient.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /recipients/1 - # DELETE /recipients/1.json - def destroy - @recipient.destroy - respond_to do |format| - format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_school - @school = School.friendly.find(params[:school_id]) - end - - # Use callbacks to share common setup or constraints between actions. - def set_recipient - @recipient = @school.recipients.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def recipient_params - params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id) - end -end diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb deleted file mode 100644 index c89ed9a8..00000000 --- a/app/controllers/schedules_controller.rb +++ /dev/null @@ -1,68 +0,0 @@ -class SchedulesController < ApplicationController - before_action :authenticate_user!, except: [:show] - before_action :set_school - before_action :verify_admin - before_action :set_schedule, only: [:show, :edit, :update, :destroy] - before_action :set_time, only: [:create, :update] - - # GET schools/1/schedules/1 - def show - end - - # GET schools/1/schedules/new - def new - @schedule = @school.schedules.build - end - - # GET schools/1/schedules/1/edit - def edit - end - - # POST schools/1/schedules - def create - @schedule = @school.schedules.build(schedule_params) - - if @schedule.save - redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully created.') - else - render action: 'new' - end - end - - # PUT schools/1/schedules/1 - def update - if @schedule.update(schedule_params) - redirect_to([@schedule.school, @schedule], notice: 'Schedule was successfully updated.') - else - render action: 'edit' - end - end - - # DELETE schools/1/schedules/1 - def destroy - @schedule.destroy - - redirect_to @school - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_school - @school = School.friendly.find(params[:school_id]) - end - - def set_schedule - @schedule = @school.schedules.find(params[:id]) - end - - # Only allow a trusted parameter "white list" through. - def schedule_params - params.require(:schedule).permit(:name, :description, :school_id, :frequency_hours, :start_date, :end_date, :time, :active, :random, :recipient_list_id, :question_list_id) - end - - def set_time - return unless schedule_params.include?(:time) - params[:schedule][:time] = schedule_params[:time].to_i + (4 * 60) # Go from EST to UTC (NEEDS TO BETTER) - end - -end diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb deleted file mode 100644 index e6d7fb58..00000000 --- a/app/controllers/schools_controller.rb +++ /dev/null @@ -1,95 +0,0 @@ -class SchoolsController < ApplicationController - before_action :authenticate_user!, except: [:show] - before_action :set_school, only: [:admin, :show, :edit, :update, :destroy] - before_action :verify_admin, except: [:show, :create, :new] - - - # GET /schools/1 - # GET /schools/1.json - def show - @district = @school.district - authenticate(@district.name.downcase, "#{@district.name.downcase}!") - - @years = [2017, 2018, 2019] - @year = (params[:year] || @years.last).to_i - - if @district.name == "Boston" - @categories = Category.joins(:questions) - @school_categories = SchoolCategory.where(school: @school).where(category: @categories).in(@year).to_a - else - @categories = Category.root - @school_categories = @school.school_categories.for_parent_category(@school, nil).valid.in(@year).sort - end - - missing_categories = @categories - @school_categories.map(&:category) - missing_categories.each do |category| - @school_categories << category.school_categories.new(school: @school, year: @year) - end - - @school_categories = @school_categories.select { |sc| sc.year.to_i == @year } - end - - def admin - end - - # GET /schools/new - def new - @school = School.new - end - - # GET /schools/1/edit - def edit - end - - # POST /schools - # POST /schools.json - def create - @school = School.new(school_params) - - respond_to do |format| - if @school.save - format.html { redirect_to @school, notice: 'School was successfully created.' } - format.json { render :show, status: :created, location: @school } - else - format.html { render :new } - format.json { render json: @school.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /schools/1 - # PATCH/PUT /schools/1.json - def update - respond_to do |format| - if @school.update(school_params) - format.html { redirect_to @school, notice: 'School was successfully updated.' } - format.json { render :show, status: :ok, location: @school } - else - format.html { render :edit } - format.json { render json: @school.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /schools/1 - # DELETE /schools/1.json - def destroy - @school.destroy - respond_to do |format| - format.html { redirect_to schools_url, notice: 'School was successfully destroyed.' } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_school - @school = School.friendly.find(params[:id] || params[:school_id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def school_params - params.require(:school).permit(:name, :district_id) - end - -end diff --git a/app/controllers/sqm_categories_controller.rb b/app/controllers/sqm_categories_controller.rb deleted file mode 100644 index 5d44d520..00000000 --- a/app/controllers/sqm_categories_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SqmCategoriesController < SqmApplicationController - - def show - @categories = SqmCategory.sorted.map { |category| CategoryPresenter.new(category: category) } - - @category = CategoryPresenter.new(category: SqmCategory.find_by_slug(params[:id])) - end - -end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb deleted file mode 100644 index c22a8f36..00000000 --- a/app/controllers/users_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -class UsersController < ApplicationController - - def show - end - - - # private - # # Use callbacks to share common setup or constraints between actions. - # def set_district - # @district = District.find(params[:id]) - # end - # - # # Never trust parameters from the scary internet, only allow the white list through. - # def district_params - # params.require(:district).permit(:name, :state_id) - # end -end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb deleted file mode 100644 index b9e5550d..00000000 --- a/app/controllers/welcome_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class WelcomeController < ApplicationController - - def index - @districts = District.all.alphabetic - @schools = School.all.alphabetic - end - -end diff --git a/app/lib/seeder.rb b/app/lib/seeder.rb index b0ad029b..13c0ba3e 100644 --- a/app/lib/seeder.rb +++ b/app/lib/seeder.rb @@ -25,7 +25,7 @@ class Seeder def seed_sqm_framework csv_file CSV.parse(File.read(csv_file), headers: true) do |row| category_id = row['Category ID'].strip - category = SqmCategory.find_or_create_by!(category_id: category_id) + category = Category.find_or_create_by!(category_id: category_id) category_slugs = { '1' => 'teachers-and-leadership', '2' => 'school-culture', @@ -36,7 +36,7 @@ class Seeder category.update! name: row['Category'].strip, description: row['Category Description'].strip, slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id) subcategory_id = row['Subcategory ID'].strip - subcategory = Subcategory.find_or_create_by! subcategory_id: subcategory_id, sqm_category: category + subcategory = Subcategory.find_or_create_by! subcategory_id: subcategory_id, category: category subcategory.update! name: row['Subcategory'].strip, description: row['Subcategory Description'].strip measure_id = row['Measure ID'].strip diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba8..75fe3837 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,4 @@ +# TODO move this to legacy, probably? class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/attempt.rb b/app/models/attempt.rb deleted file mode 100644 index 5a833c24..00000000 --- a/app/models/attempt.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'twilio-ruby' - -class Attempt < ApplicationRecord - - belongs_to :schedule - belongs_to :recipient - belongs_to :recipient_schedule - belongs_to :question - belongs_to :student - - after_save :update_school_categories - after_commit :update_counts - - scope :for_question, -> (question) { where(question_id: question.id) } - scope :for_recipient, -> (recipient) { where(recipient_id: recipient.id) } - scope :for_student, -> (student) { where(student_id: student.id) } - scope :for_category, -> (category) { joins(:question).merge(Question.for_category(category)) } - scope :for_school, -> (school) { joins(:recipient).merge(Recipient.for_school(school)) } - scope :with_answer, -> { where('answer_index is not null or open_response_id is not null')} - scope :with_no_answer, -> { where('answer_index is null and open_response_id is null')} - scope :not_yet_responded, -> { where(responded_at: nil) } - scope :last_sent, -> { order(sent_at: :desc) } - scope :created_in, -> (year) { where('extract(year from attempts.created_at) = ?', year) } - - def messages - child_specific = student.present? ? " (for #{student.name})" : '' - - cancel_text = "\nSkip question: skip\nStop all questions: stop" - - [ - "#{question.text}#{child_specific}", - "#{question.option1}: Reply 1\n#{question.option2}: 2\n#{question.option3}: 3\n#{question.option4}: 4\n#{question.option5}: 5" - ] - end - - def send_message - twilio_number = ENV['TWILIO_NUMBER'] - client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'] - - sids = [] - messages.each do |message| - sids << client.messages.create( - from: twilio_number, - to: recipient.phone, - body: message - ).sid - end - - update(sent_at: Time.new, twilio_sid: sids.join(',')) - recipient.update(phone: client.messages.get(sids.last).to) - end - - def response - return 'No Answer Yet' if answer_index.blank? - question.options[answer_index_with_reverse - 1] - end - - def save_response(answer_index: nil, twilio_details: nil, responded_at: Time.new) - update( - answer_index: answer_index, - twilio_details: twilio_details, - responded_at: responded_at - ) - - if recipient_schedule.queued_question_ids.present? - recipient_schedule.update(next_attempt_at: Time.new) - end - end - - def answer_index_with_reverse - return 6 - answer_index if question.reverse? - return answer_index - end - - private - - def update_school_categories - return if ENV['BULK_PROCESS'] - school_category = SchoolCategory.for(recipient.school, question.category).first - if school_category.nil? - school_category = SchoolCategory.create(school: recipient.school, category: question.category) - end - school_category.sync_aggregated_responses - end - - def update_counts - return if ENV['BULK_PROCESS'] - recipient.update_counts - end - -end diff --git a/app/models/category.rb b/app/models/category.rb index 5b2338f5..73b4e400 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,93 +1,9 @@ -class Category < ApplicationRecord - - has_many :questions - belongs_to :parent_category, class_name: 'Category', foreign_key: :parent_category_id - has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id - has_many :school_categories - - validates :name, presence: true - - scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) } - scope :likert, -> { where("benchmark is null") } - +class Category < ActiveRecord::Base include FriendlyId - friendly_id :name, :use => [:slugged] - - def path - p = self - items = [p] - items << p while (p = p.try(:parent_category)) - items.uniq.compact.reverse - end - - def root_identifier - path.first.name.downcase.gsub(/\s/, '-') - end - - def root_index - Category.root_identifiers.index(root_identifier) || 0 - end - - def self.root_identifiers - [ - "teachers-and-the-teaching-environment", - "school-culture", - "resources", - "academic-learning", - "community-and-wellbeing", - "pilot-family-questions" - ] - end - - def self.root - Category.where(parent_category: nil).select { |c| self.root_identifiers.index(c.slug) } - end - - def custom_zones - return [] if zones.nil? - zones.split(",").map(&:to_f) - end - - def zone_widths - return nil if zones.nil? - - widths = custom_zones.each_with_index.map do |zone, index| - (zone - (index == 0 ? 0 : custom_zones[index - 1])).round(2) - end - - widths[4] = widths[4] + (5 - widths.sum) - return widths - end - - def sync_child_zones - likert_child_categories = child_categories.likert - return unless likert_child_categories.present? - total_zones = [0,0,0,0,0] - valid_child_categories = 0 - likert_child_categories.each do |cc| - if cc.zones.nil? - cc.sync_child_zones - end - - if cc.zones.nil? - puts "NO ZONES: #{name} -> #{cc.name}" - else - valid_child_categories += 1 - - puts "ZONES: #{name} | #{cc.name} | #{cc.zones}" - - cc.custom_zones.each_with_index do |zone, index| - puts "ZONE: #{name} | #{zone} | #{index}" - total_zones[index] += zone - end - end - end + friendly_id :name, use: [:slugged] - if valid_child_categories > 0 - average_zones = total_zones.map { |zone| zone / valid_child_categories } - puts "TOTAL: #{name} | #{total_zones} | #{valid_child_categories} | #{average_zones} | #{zone_widths}" - update(zones: average_zones.join(",")) - end - end + scope :sorted, ->() { order(:sort_index) } + has_many :subcategories + has_many :measures, through: :subcategories end diff --git a/app/models/district.rb b/app/models/district.rb index 9f5b063d..49873b2d 100644 --- a/app/models/district.rb +++ b/app/models/district.rb @@ -12,5 +12,4 @@ class District < ApplicationRecord before_save do self.slug ||= name.parameterize end - end diff --git a/app/models/legacy.rb b/app/models/legacy.rb new file mode 100644 index 00000000..4938c0f1 --- /dev/null +++ b/app/models/legacy.rb @@ -0,0 +1,5 @@ +module Legacy + def self.table_name_prefix + 'legacy_' + end +end diff --git a/app/models/legacy/attempt.rb b/app/models/legacy/attempt.rb new file mode 100644 index 00000000..c6849a9e --- /dev/null +++ b/app/models/legacy/attempt.rb @@ -0,0 +1,93 @@ +require 'twilio-ruby' + +module Legacy + class Attempt < ApplicationRecord + + belongs_to :schedule + belongs_to :recipient + belongs_to :recipient_schedule + belongs_to :question + belongs_to :student + + after_save :update_school_categories + after_commit :update_counts + + scope :for_question, -> (question) { where(question_id: question.id) } + scope :for_recipient, -> (recipient) { where(recipient_id: recipient.id) } + scope :for_student, -> (student) { where(student_id: student.id) } + scope :for_category, -> (category) { joins(:question).merge(Question.for_category(category)) } + scope :for_school, -> (school) { joins(:recipient).merge(Legacy::Recipient.for_school(school)) } + scope :with_answer, -> { where('answer_index is not null or open_response_id is not null') } + scope :with_no_answer, -> { where('answer_index is null and open_response_id is null') } + scope :not_yet_responded, -> { where(responded_at: nil) } + scope :last_sent, -> { order(sent_at: :desc) } + scope :created_in, -> (year) { where('extract(year from legacy_attempts.created_at) = ?', year) } + + def messages + child_specific = student.present? ? " (for #{student.name})" : '' + + cancel_text = "\nSkip question: skip\nStop all questions: stop" + + [ + "#{question.text}#{child_specific}", + "#{question.option1}: Reply 1\n#{question.option2}: 2\n#{question.option3}: 3\n#{question.option4}: 4\n#{question.option5}: 5" + ] + end + + def send_message + twilio_number = ENV['TWILIO_NUMBER'] + client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'] + + sids = [] + messages.each do |message| + sids << client.messages.create( + from: twilio_number, + to: recipient.phone, + body: message + ).sid + end + + update(sent_at: Time.new, twilio_sid: sids.join(',')) + recipient.update(phone: client.messages.get(sids.last).to) + end + + def response + return 'No Answer Yet' if answer_index.blank? + question.options[answer_index_with_reverse - 1] + end + + def save_response(answer_index: nil, twilio_details: nil, responded_at: Time.new) + update( + answer_index: answer_index, + twilio_details: twilio_details, + responded_at: responded_at + ) + + if recipient_schedule.queued_question_ids.present? + recipient_schedule.update(next_attempt_at: Time.new) + end + end + + def answer_index_with_reverse + return 6 - answer_index if question.reverse? + return answer_index + end + + private + + def update_school_categories + return if ENV['BULK_PROCESS'] + school_category = SchoolCategory.for(recipient.school, question.category).first + if school_category.nil? + school_category = SchoolCategory.create(school: recipient.school, category: question.category) + end + school_category.sync_aggregated_responses + end + + def update_counts + return if ENV['BULK_PROCESS'] + recipient.update_counts + end + + end +end diff --git a/app/models/legacy/category.rb b/app/models/legacy/category.rb new file mode 100644 index 00000000..e7b9264d --- /dev/null +++ b/app/models/legacy/category.rb @@ -0,0 +1,95 @@ +module Legacy + class Category < ApplicationRecord + + has_many :questions + belongs_to :parent_category, class_name: 'Legacy::Category', foreign_key: :parent_category_id + has_many :child_categories, class_name: 'Legacy::Category', foreign_key: :parent_category_id + has_many :school_categories + + validates :name, presence: true + + scope :for_parent, -> (category = nil) { where(parent_category_id: category.try(:id)) } + scope :likert, -> { where("benchmark is null") } + + include FriendlyId + friendly_id :name, :use => [:slugged] + + def path + p = self + items = [p] + items << p while (p = p.try(:parent_category)) + items.uniq.compact.reverse + end + + def root_identifier + path.first.name.downcase.gsub(/\s/, '-') + end + + def root_index + Category.root_identifiers.index(root_identifier) || 0 + end + + def self.root_identifiers + [ + "teachers-and-the-teaching-environment", + "school-culture", + "resources", + "academic-learning", + "community-and-wellbeing", + "pilot-family-questions" + ] + end + + def self.root + Category.where(parent_category: nil).select { |c| self.root_identifiers.index(c.slug) } + end + + def custom_zones + return [] if zones.nil? + zones.split(",").map(&:to_f) + end + + def zone_widths + return nil if zones.nil? + + widths = custom_zones.each_with_index.map do |zone, index| + (zone - (index == 0 ? 0 : custom_zones[index - 1])).round(2) + end + + widths[4] = widths[4] + (5 - widths.sum) + return widths + end + + def sync_child_zones + likert_child_categories = child_categories.likert + return unless likert_child_categories.present? + total_zones = [0, 0, 0, 0, 0] + valid_child_categories = 0 + likert_child_categories.each do |cc| + if cc.zones.nil? + cc.sync_child_zones + end + + if cc.zones.nil? + puts "NO ZONES: #{name} -> #{cc.name}" + else + valid_child_categories += 1 + + puts "ZONES: #{name} | #{cc.name} | #{cc.zones}" + + cc.custom_zones.each_with_index do |zone, index| + puts "ZONE: #{name} | #{zone} | #{index}" + total_zones[index] += zone + end + end + end + + if valid_child_categories > 0 + average_zones = total_zones.map { |zone| zone / valid_child_categories } + puts "TOTAL: #{name} | #{total_zones} | #{valid_child_categories} | #{average_zones} | #{zone_widths}" + update(zones: average_zones.join(",")) + end + end + + end +end diff --git a/app/models/legacy/district.rb b/app/models/legacy/district.rb new file mode 100644 index 00000000..e49a2f03 --- /dev/null +++ b/app/models/legacy/district.rb @@ -0,0 +1,17 @@ +module Legacy + class District < ApplicationRecord + has_many :schools + + validates :name, presence: true + + scope :alphabetic, -> { order(name: :asc) } + + include FriendlyId + + friendly_id :name, use: [:slugged] + + before_save do + self.slug ||= name.parameterize + end + end +end diff --git a/app/models/legacy/question.rb b/app/models/legacy/question.rb new file mode 100644 index 00000000..0ec09b9e --- /dev/null +++ b/app/models/legacy/question.rb @@ -0,0 +1,72 @@ +AggregatedResponses = Struct.new( + :question, + :category, + :responses, + :count, + :answer_index_total, + :answer_index_average, + :most_popular_answer, + :zscore +) + +module Legacy + class Question < ApplicationRecord + belongs_to :category + + has_many :attempts + + validates :text, presence: true + validates :option1, presence: true + validates :option2, presence: true + validates :option3, presence: true + validates :option4, presence: true + validates :option5, presence: true + + scope :for_category, -> (category) { where(category: category) } + scope :created_in, -> (year) { where("extract(year from #{self.table_name}.created_at) = ?", year) } + + enum target_group: [:unknown, :for_students, :for_teachers, :for_parents] + + def source + target_group.gsub('for_', '') + end + + def options + [option1, option2, option3, option4, option5] + end + + def options_with_reverse + return options.reverse if reverse? + options + end + + def option_index(answer) + options_with_reverse.map(&:downcase).map(&:strip).index(answer.downcase.strip) + end + + def aggregated_responses_for_school(school) + school_responses = attempts.for_school(school).with_answer.order(id: :asc) + return unless school_responses.present? + + response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index_with_reverse } + histogram = school_responses.group_by(&:answer_index_with_reverse) + + most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0] + most_popular_answer = options_with_reverse[most_popular_answer_index - 1] + + AggregatedResponses.new( + self, + category, + school_responses, + school_responses.length, + response_answer_total, + response_answer_total.to_f / school_responses.length.to_f, + most_popular_answer + ) + end + + def normalized_text + text.gsub("[science/math/English/social studies]", "") + end + end +end diff --git a/app/models/legacy/question_list.rb b/app/models/legacy/question_list.rb new file mode 100644 index 00000000..ef2df464 --- /dev/null +++ b/app/models/legacy/question_list.rb @@ -0,0 +1,28 @@ +module Legacy + class QuestionList < ApplicationRecord + + validates :name, presence: true + validates :question_ids, presence: true + + attr_accessor :question_id_array + before_validation :convert_question_id_array + after_initialize :set_question_id_array + + def questions + question_id_array.collect { |id| Question.where(id: id).first }.compact + end + + private + + def convert_question_id_array + return if question_id_array.blank? + self.question_ids = question_id_array.reject { |id| id.to_s.empty? }.join(',') + end + + def set_question_id_array + return if question_ids.blank? + self.question_id_array = question_ids.split(',').map(&:to_i) + end + + end +end diff --git a/app/models/legacy/recipient.rb b/app/models/legacy/recipient.rb new file mode 100644 index 00000000..6f8366ae --- /dev/null +++ b/app/models/legacy/recipient.rb @@ -0,0 +1,52 @@ +require 'csv' + +module Legacy + class Recipient < ApplicationRecord + belongs_to :school + validates_associated :school + + has_many :recipient_schedules + has_many :attempts + + has_many :students + + validates :name, presence: true + + scope :for_school, -> (school) { where(school: school) } + scope :created_in, -> (year) { where('extract(year from recipients.created_at) = ?', year) } + + before_destroy :sync_lists + + def self.import(school, file) + CSV.foreach(file.path, headers: true) do |row| + school.recipients.create!(row.to_hash) + # recipient_hash = row.to_hash + # recipient = school.recipients.where(phone: recipient_hash["phone"]) + # + # if recipient.count == 1 + # recipient.first.update(recipient_hash) + # else + # school.recipients.create!(recipient_hash) + # end + end + end + + def update_counts + update( + attempts_count: attempts.count, + responses_count: attempts.with_answer.count + ) + end + + private + + def sync_lists + school.recipient_lists.each do |recipient_list| + next if recipient_list.recipient_id_array.index(id).nil? + updated_ids = recipient_list.recipient_id_array - [id] + recipient_list.update(recipient_id_array: updated_ids) + end + end + + end +end diff --git a/app/models/recipient_list.rb b/app/models/legacy/recipient_list.rb similarity index 68% rename from app/models/recipient_list.rb rename to app/models/legacy/recipient_list.rb index f51970fb..d3835477 100644 --- a/app/models/recipient_list.rb +++ b/app/models/legacy/recipient_list.rb @@ -1,21 +1,22 @@ -class RecipientList < ApplicationRecord - belongs_to :school - has_many :schedules +module Legacy + class RecipientList < ApplicationRecord + belongs_to :school + has_many :schedules - validates_associated :school - validates :name, presence: true + validates_associated :school + validates :name, presence: true - attr_accessor :recipient_id_array - before_validation :convert_recipient_id_array - after_initialize :set_recipient_id_array + attr_accessor :recipient_id_array + before_validation :convert_recipient_id_array + after_initialize :set_recipient_id_array - after_save :sync_recipient_schedules + after_save :sync_recipient_schedules - def recipients - recipient_id_array.collect { |id| school.recipients.where(id: id).first } - end + def recipients + recipient_id_array.collect { |id| school.recipients.where(id: id).first } + end - private + private def convert_recipient_id_array return if recipient_id_array.blank? || (recipient_ids_was != recipient_ids) @@ -44,4 +45,5 @@ class RecipientList < ApplicationRecord end end + end end diff --git a/app/models/legacy/recipient_schedule.rb b/app/models/legacy/recipient_schedule.rb new file mode 100644 index 00000000..c205ef26 --- /dev/null +++ b/app/models/legacy/recipient_schedule.rb @@ -0,0 +1,169 @@ +module Legacy + class RecipientSchedule < ApplicationRecord + + belongs_to :recipient + belongs_to :schedule + has_many :attempts + + validates_associated :recipient + validates_associated :schedule + validates :next_attempt_at, presence: true + + scope :ready, -> { where('next_attempt_at <= ?', Time.new) } + scope :for_recipient, -> (recipient_or_recipient_id) { + id = recipient_or_recipient_id.is_a?(Recipient) ? + recipient_or_recipient_id.id : + recipient_or_recipient_id + where(recipient_id: id) + } + scope :for_schedule, -> (schedule_or_schedule_id) { + id = schedule_or_schedule_id.is_a?(Schedule) ? + schedule_or_schedule_id.id : + schedule_or_schedule_id + where(schedule_id: id) + } + + def next_question + if queued_question_ids.present? + next_question_id = queued_question_ids.split(/,/).first + else + next_question_id = upcoming_question_ids.split(/,/).first + end + Question.where(id: next_question_id).first + end + + def upcoming_question_id_array + upcoming_question_ids.try(:split, /,/) || [] + end + + def attempted_question_id_array + attempted_question_ids.try(:split, /,/) || [] + end + + def queued_question_id_array + queued_question_ids.try(:split, /,/) || [] + end + + def attempt_question_for_recipient_students(send_message: true, question: next_question) + return if recipient.opted_out? + return if question.nil? + + if !question.for_recipient_students? + return attempt_question(question: question) + end + + missing_students = [] + recipient_attempts = attempts.for_recipient(recipient).for_question(question) + recipient.students.each do |student| + if recipient_attempts.for_student(student).empty? + missing_students << student + end + end + + attempt = recipient.attempts.create( + schedule: schedule, + recipient_schedule: self, + question: question, + student: missing_students.first + ) + + if send_message && attempt.send_message + upcoming = upcoming_question_id_array + queued = queued_question_id_array + attempted = attempted_question_id_array + + if question.present? + question_id = [question.id.to_s] + upcoming = upcoming - question_id + if missing_students.length > 1 + queued += question_id + else + attempted += question_id + queued -= question_id + end + end + + update( + upcoming_question_ids: upcoming.empty? ? nil : upcoming.join(','), + attempted_question_ids: attempted.empty? ? nil : attempted.join(','), + queued_question_ids: queued.empty? ? nil : queued.join(','), + last_attempt_at: attempt.sent_at, + next_attempt_at: next_valid_attempt_time + ) + end + return attempt + end + + def attempt_question(send_message: true, question: next_question) + return if recipient.opted_out? + unanswered_attempt = recipient.attempts.not_yet_responded.last + + return if question.nil? && unanswered_attempt.nil? + + if unanswered_attempt.nil? + if question.for_recipient_students? + return attempt_question_for_recipient_students(question: question) + end + + attempt = recipient.attempts.create( + schedule: schedule, + recipient_schedule: self, + question: question + ) + end + + if send_message && (unanswered_attempt || attempt).send_message + upcoming = upcoming_question_id_array + queued = queued_question_id_array + attempted = attempted_question_id_array + + if question.present? + question_id = [question.id.to_s] + upcoming = upcoming - question_id + if unanswered_attempt.nil? + attempted += question_id + queued -= question_id + else + queued += question_id + end + end + + update( + upcoming_question_ids: upcoming.empty? ? nil : upcoming.join(','), + attempted_question_ids: attempted.empty? ? nil : attempted.join(','), + queued_question_ids: queued.empty? ? nil : queued.join(','), + last_attempt_at: (unanswered_attempt || attempt).sent_at, + next_attempt_at: next_valid_attempt_time + ) + end + return (unanswered_attempt || attempt) + end + + def next_valid_attempt_time + local_time = (next_attempt_at + (60 * 60 * schedule.frequency_hours)).in_time_zone('Eastern Time (US & Canada)') + local_time += 1.day while local_time.on_weekend? + return local_time + end + + def self.create_for_recipient(recipient_or_recipient_id, schedule, next_attempt_at = nil) + if next_attempt_at.nil? + next_attempt_at = Time.at(schedule.start_date.to_time.to_i + (60 * schedule.time)) + next_attempt_at += 1.day while next_attempt_at.on_weekend? + end + + question_ids = schedule.question_list.question_ids.split(/,/) + question_ids = question_ids.shuffle if schedule.random? + + recipient_id = recipient_or_recipient_id.is_a?(Recipient) ? + recipient_or_recipient_id.id : + recipient_or_recipient_id + + schedule.recipient_schedules.create( + recipient_id: recipient_id, + upcoming_question_ids: question_ids.join(','), + next_attempt_at: next_attempt_at + ) + end + + end +end diff --git a/app/models/legacy/schedule.rb b/app/models/legacy/schedule.rb new file mode 100644 index 00000000..fb5ac34a --- /dev/null +++ b/app/models/legacy/schedule.rb @@ -0,0 +1,33 @@ +module Legacy + class Schedule < ApplicationRecord + belongs_to :school + belongs_to :recipient_list + belongs_to :question_list + has_many :recipient_schedules + + validates :name, presence: true + validates :recipient_list, presence: true + validates :question_list, presence: true + + before_validation :set_start_date + after_create :create_recipient_schedules + + scope :active, -> { + where(active: true).where("start_date <= ? and end_date > ?", Date.today, Date.today) + } + + private + + def set_start_date + return if start_date.present? + self.start_date = Date.today + end + + def create_recipient_schedules + recipient_list.recipients.each do |recipient| + RecipientSchedule.create_for_recipient(recipient, self) + end + end + + end +end diff --git a/app/models/legacy/school.rb b/app/models/legacy/school.rb new file mode 100644 index 00000000..6092914b --- /dev/null +++ b/app/models/legacy/school.rb @@ -0,0 +1,89 @@ +module Legacy + class School < ApplicationRecord + has_many :schedules, dependent: :destroy + has_many :recipient_lists, dependent: :destroy + belongs_to :district + has_many :recipients, dependent: :destroy + has_many :school_categories, dependent: :destroy + has_many :user_schools, dependent: :destroy + + validates :name, presence: true + + scope :alphabetic, -> { order(name: :asc) } + + include FriendlyId + friendly_id :name, use: [:slugged] + + def self.find_by_district_code_and_school_code(district_code, school_code) + School + .joins(:district) + .where(districts: { qualtrics_code: district_code }) + .find_by_qualtrics_code(school_code) + end + + def available_responders_for(question) + if question.for_students? + student_count || 1 + elsif question.for_teachers? + teacher_count || 1 + else + 1 + end + end + + def merge_into(school_name) + school = district.schools.where(name: school_name).first + if school.nil? + puts "Unable to find school named #{school_name} in district (#{district.name})" + return + end + puts "Merging #{name} (#{id}) in to #{school.name} (#{school.id})" + schedules.update_all(school_id: school.id) + recipient_lists.update_all(school_id: school.id) + recipients.update_all(school_id: school.id) + school_categories.each do |school_category| + school_category.update(school_id: school.id) + existing_school_category = school.school_categories.for(school_category.school, + school_category.category).in(school_category.year) + if existing_school_category.present? + if existing_school_category.attempt_count == 0 && existing_school_category.zscore.nil? + existing_school_category.destroy + else + school_category.destroy + end + end + end + + reload + + user_schools.update_all(school_id: school.id) + + school.school_categories.map(&:sync_aggregated_responses) + + base_categories = Category.joins(:questions).to_a.flatten.uniq + base_categories.each do |category| + SchoolCategory.for(school, category).each do |school_category| + year = school_category.year + dup_school_categories = SchoolCategory.for(school, category).in(year) + next unless dup_school_categories.count > 1 + + dup_school_categories.each { |dsc| dsc.destroy unless dsc.id == school_category.id } + school_category.sync_aggregated_responses + parent = category.parent_category + until parent.nil? + SchoolCategory.for(school, parent).in(year).valid.each do |parent_school_category| + parent_dup_school_categories = SchoolCategory.for(school, parent).in(year) + if parent_dup_school_categories.count > 1 + parent_dup_school_categories.each { |pdsc| pdsc.destroy unless pdsc.id == parent_school_category.id } + parent_school_category.sync_aggregated_responses + end + end + parent = parent.parent_category + end + end + end + + destroy + end + end +end diff --git a/app/models/legacy/school_category.rb b/app/models/legacy/school_category.rb new file mode 100644 index 00000000..7a68bb53 --- /dev/null +++ b/app/models/legacy/school_category.rb @@ -0,0 +1,106 @@ +module Legacy + class SchoolCategory < ApplicationRecord + + MIN_RESPONSE_COUNT = 10 + + belongs_to :school + belongs_to :category + + has_many :school_questions + + validates_associated :school + validates_associated :category + + scope :for, -> (school, category) { where(school: school).where(category: category) } + scope :for_parent_category, -> (school, category = nil) { where(school: school).joins(:category).merge(Category.for_parent(category)) } + scope :in, -> (year) { where(year: year) } + + scope :valid, -> { where("zscore is not null or valid_child_count is not null") } + + def admin? + child_categories = category.child_categories + return false if child_categories.blank? + child_categories.each { |cc| return false if cc.benchmark.blank? } + return true + end + + def root_index + category.root_index + end + + def answer_index_average + answer_index_total.to_f / response_count.to_f + end + + def aggregated_responses + attempt_data = Legacy::Attempt. + created_in(year). + for_category(category). + for_school(school). + select('count(legacy_attempts.id) as attempt_count'). + select('count(legacy_attempts.answer_index) as response_count'). + select('sum(case when legacy_questions.reverse then 6 - legacy_attempts.answer_index else legacy_attempts.answer_index end) as answer_index_total')[0] + + return { + attempt_count: attempt_data.attempt_count || 0, + response_count: attempt_data.response_count || 0, + answer_index_total: attempt_data.answer_index_total || 0, + zscore: attempt_data.answer_index_total.nil? ? + (attempt_data.response_count > MIN_RESPONSE_COUNT ? zscore : nil) : + (attempt_data.response_count > MIN_RESPONSE_COUNT ? + (attempt_data.answer_index_total.to_f / attempt_data.response_count.to_f - 3.to_f) : + nil) + } + end + + def chained_aggregated_responses + return {} if nonlikert.present? + + _aggregated_responses = aggregated_responses + + child_school_categories = [] + if category.child_categories.length > 0 + child_school_categories = category.child_categories.collect do |cc| + SchoolCategory.for(school, cc).in(year).valid + end.flatten.compact + + return {} if child_school_categories.blank? + end + + average_zscore = nil + zscore_categories = child_school_categories.select { |csc| csc.zscore.present? && !csc.zscore.nan? } + if zscore_categories.length > 0 + total_zscore = zscore_categories.inject(0) { |total, zc| total + zc.zscore } + average_zscore = total_zscore / zscore_categories.length + end + + return { + attempt_count: + _aggregated_responses[:attempt_count] + + child_school_categories.inject(0) { |total, csc| total + (csc.attempt_count || 0) }, + response_count: + _aggregated_responses[:response_count] + + child_school_categories.inject(0) { |total, csc| total + (csc.response_count || 0) }, + answer_index_total: + _aggregated_responses[:answer_index_total] + + child_school_categories.inject(0) { |total, csc| total + (csc.answer_index_total || 0) }, + zscore: average_zscore.present? ? average_zscore : _aggregated_responses[:zscore] + } + end + + def sync_aggregated_responses + # This doesn't seem to be taking into account valid_child_count or Boston's "Community and Wellbeing" category which should be suppressed if the "Health" category is the only child category visible. + + return if ENV['BULK_PROCESS'] + update(chained_aggregated_responses) + return if response_count == 0 && zscore.nil? + if category.parent_category.present? + parent_school_category = SchoolCategory.for(school, category.parent_category).in(year).first + if parent_school_category.nil? + parent_school_category = SchoolCategory.create(school: school, category: category.parent_category, year: year) + end + parent_school_category.sync_aggregated_responses + end + end + end +end diff --git a/app/models/legacy/school_question.rb b/app/models/legacy/school_question.rb new file mode 100644 index 00000000..3fbbdb38 --- /dev/null +++ b/app/models/legacy/school_question.rb @@ -0,0 +1,35 @@ +module Legacy + class SchoolQuestion < ApplicationRecord + + belongs_to :school + belongs_to :question + belongs_to :school_category + + validates_associated :school + validates_associated :question + validates_associated :school_category + + scope :for, -> (school, question) { where(school_id: school.id, question_id: question.id) } + scope :in, -> (year) { where(year: year) } + + def sync_attempts + attempt_data = Attempt. + joins(:question). + created_in(school_category.year). + for_question(question). + for_school(school). + select('count(attempts.answer_index) as response_count'). + select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] + + available_responders = school.available_responders_for(question) + + update( + attempt_count: available_responders, + response_count: attempt_data.response_count, + response_rate: attempt_data.response_count.to_f / available_responders.to_f, + response_total: attempt_data.answer_index_total + ) + end + + end +end diff --git a/app/models/legacy/student.rb b/app/models/legacy/student.rb new file mode 100644 index 00000000..ef541004 --- /dev/null +++ b/app/models/legacy/student.rb @@ -0,0 +1,5 @@ +module Legacy + class Student < ApplicationRecord + belongs_to :recipient + end +end diff --git a/app/models/legacy/user.rb b/app/models/legacy/user.rb new file mode 100644 index 00000000..42a8b297 --- /dev/null +++ b/app/models/legacy/user.rb @@ -0,0 +1,23 @@ +module Legacy + class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + + has_many :user_schools + + def schools + districts = user_schools.map(&:district).compact.uniq + (user_schools.map(&:school) + districts.map(&:schools)).flatten.compact.uniq + end + + def admin?(school) + schools.index(school).present? + end + + def super_admin? + [1].index(id).present? + end + end +end diff --git a/app/models/legacy/user_school.rb b/app/models/legacy/user_school.rb new file mode 100644 index 00000000..003191ce --- /dev/null +++ b/app/models/legacy/user_school.rb @@ -0,0 +1,9 @@ +module Legacy + class UserSchool < ApplicationRecord + + belongs_to :user + belongs_to :school + belongs_to :district + + end +end diff --git a/app/models/question.rb b/app/models/question.rb deleted file mode 100644 index 884ac99e..00000000 --- a/app/models/question.rb +++ /dev/null @@ -1,70 +0,0 @@ -AggregatedResponses = Struct.new( - :question, - :category, - :responses, - :count, - :answer_index_total, - :answer_index_average, - :most_popular_answer, - :zscore -) - -class Question < ApplicationRecord - belongs_to :category - - has_many :attempts - - validates :text, presence: true - validates :option1, presence: true - validates :option2, presence: true - validates :option3, presence: true - validates :option4, presence: true - validates :option5, presence: true - - scope :for_category, -> (category) { where(category: category) } - scope :created_in, -> (year) { where('extract(year from questions.created_at) = ?', year) } - - enum target_group: [:unknown, :for_students, :for_teachers, :for_parents] - - def source - target_group.gsub('for_', '') - end - - def options - [option1, option2, option3, option4, option5] - end - - def options_with_reverse - return options.reverse if reverse? - options - end - - def option_index(answer) - options_with_reverse.map(&:downcase).map(&:strip).index(answer.downcase.strip) - end - - def aggregated_responses_for_school(school) - school_responses = attempts.for_school(school).with_answer.order(id: :asc) - return unless school_responses.present? - - response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index_with_reverse } - histogram = school_responses.group_by(&:answer_index_with_reverse) - - most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0] - most_popular_answer = options_with_reverse[most_popular_answer_index - 1] - - AggregatedResponses.new( - self, - category, - school_responses, - school_responses.length, - response_answer_total, - response_answer_total.to_f / school_responses.length.to_f, - most_popular_answer - ) - end - - def normalized_text - text.gsub("[science/math/English/social studies]", "") - end -end diff --git a/app/models/question_list.rb b/app/models/question_list.rb deleted file mode 100644 index ee19dd7c..00000000 --- a/app/models/question_list.rb +++ /dev/null @@ -1,26 +0,0 @@ -class QuestionList < ApplicationRecord - - validates :name, presence: true - validates :question_ids, presence: true - - attr_accessor :question_id_array - before_validation :convert_question_id_array - after_initialize :set_question_id_array - - def questions - question_id_array.collect { |id| Question.where(id: id).first }.compact - end - - private - - def convert_question_id_array - return if question_id_array.blank? - self.question_ids = question_id_array.reject { |id| id.to_s.empty? }.join(',') - end - - def set_question_id_array - return if question_ids.blank? - self.question_id_array = question_ids.split(',').map(&:to_i) - end - -end diff --git a/app/models/recipient.rb b/app/models/recipient.rb deleted file mode 100644 index b8a4a59f..00000000 --- a/app/models/recipient.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'csv' - -class Recipient < ApplicationRecord - belongs_to :school - validates_associated :school - - has_many :recipient_schedules - has_many :attempts - - has_many :students - - validates :name, presence: true - - scope :for_school, -> (school) { where(school: school) } - scope :created_in, -> (year) { where('extract(year from recipients.created_at) = ?', year) } - - before_destroy :sync_lists - - def self.import(school, file) - CSV.foreach(file.path, headers: true) do |row| - school.recipients.create!(row.to_hash) - # recipient_hash = row.to_hash - # recipient = school.recipients.where(phone: recipient_hash["phone"]) - # - # if recipient.count == 1 - # recipient.first.update(recipient_hash) - # else - # school.recipients.create!(recipient_hash) - # end - end - end - - def update_counts - update( - attempts_count: attempts.count, - responses_count: attempts.with_answer.count - ) - end - - private - - def sync_lists - school.recipient_lists.each do |recipient_list| - next if recipient_list.recipient_id_array.index(id).nil? - updated_ids = recipient_list.recipient_id_array - [id] - recipient_list.update(recipient_id_array: updated_ids) - end - end - -end diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb deleted file mode 100644 index fe73d6bb..00000000 --- a/app/models/recipient_schedule.rb +++ /dev/null @@ -1,168 +0,0 @@ -class RecipientSchedule < ApplicationRecord - - belongs_to :recipient - belongs_to :schedule - has_many :attempts - - validates_associated :recipient - validates_associated :schedule - validates :next_attempt_at, presence: true - - scope :ready, -> { where('next_attempt_at <= ?', Time.new) } - scope :for_recipient, -> (recipient_or_recipient_id) { - id = recipient_or_recipient_id.is_a?(Recipient) ? - recipient_or_recipient_id.id : - recipient_or_recipient_id - where(recipient_id: id) - } - scope :for_schedule, -> (schedule_or_schedule_id) { - id = schedule_or_schedule_id.is_a?(Schedule) ? - schedule_or_schedule_id.id : - schedule_or_schedule_id - where(schedule_id: id) - } - - def next_question - if queued_question_ids.present? - next_question_id = queued_question_ids.split(/,/).first - else - next_question_id = upcoming_question_ids.split(/,/).first - end - Question.where(id: next_question_id).first - end - - def upcoming_question_id_array - upcoming_question_ids.try(:split, /,/) || [] - end - - def attempted_question_id_array - attempted_question_ids.try(:split, /,/) || [] - end - - def queued_question_id_array - queued_question_ids.try(:split, /,/) || [] - end - - def attempt_question_for_recipient_students(send_message: true, question: next_question) - return if recipient.opted_out? - return if question.nil? - - if !question.for_recipient_students? - return attempt_question(question: question) - end - - missing_students = [] - recipient_attempts = attempts.for_recipient(recipient).for_question(question) - recipient.students.each do |student| - if recipient_attempts.for_student(student).empty? - missing_students << student - end - end - - attempt = recipient.attempts.create( - schedule: schedule, - recipient_schedule: self, - question: question, - student: missing_students.first - ) - - if send_message && attempt.send_message - upcoming = upcoming_question_id_array - queued = queued_question_id_array - attempted = attempted_question_id_array - - if question.present? - question_id = [question.id.to_s] - upcoming = upcoming - question_id - if missing_students.length > 1 - queued += question_id - else - attempted += question_id - queued -= question_id - end - end - - update( - upcoming_question_ids: upcoming.empty? ? nil : upcoming.join(','), - attempted_question_ids: attempted.empty? ? nil : attempted.join(','), - queued_question_ids: queued.empty? ? nil : queued.join(','), - last_attempt_at: attempt.sent_at, - next_attempt_at: next_valid_attempt_time - ) - end - return attempt - end - - def attempt_question(send_message: true, question: next_question) - return if recipient.opted_out? - unanswered_attempt = recipient.attempts.not_yet_responded.last - - return if question.nil? && unanswered_attempt.nil? - - if unanswered_attempt.nil? - if question.for_recipient_students? - return attempt_question_for_recipient_students(question: question) - end - - attempt = recipient.attempts.create( - schedule: schedule, - recipient_schedule: self, - question: question - ) - end - - if send_message && (unanswered_attempt || attempt).send_message - upcoming = upcoming_question_id_array - queued = queued_question_id_array - attempted = attempted_question_id_array - - if question.present? - question_id = [question.id.to_s] - upcoming = upcoming - question_id - if unanswered_attempt.nil? - attempted += question_id - queued -= question_id - else - queued += question_id - end - end - - update( - upcoming_question_ids: upcoming.empty? ? nil : upcoming.join(','), - attempted_question_ids: attempted.empty? ? nil : attempted.join(','), - queued_question_ids: queued.empty? ? nil : queued.join(','), - last_attempt_at: (unanswered_attempt || attempt).sent_at, - next_attempt_at: next_valid_attempt_time - ) - end - return (unanswered_attempt || attempt) - end - - def next_valid_attempt_time - local_time = (next_attempt_at + (60 * 60 * schedule.frequency_hours)).in_time_zone('Eastern Time (US & Canada)') - local_time += 1.day while local_time.on_weekend? - return local_time - end - - def self.create_for_recipient(recipient_or_recipient_id, schedule, next_attempt_at=nil) - if next_attempt_at.nil? - next_attempt_at = Time.at(schedule.start_date.to_time.to_i + (60 * schedule.time)) - next_attempt_at += 1.day while next_attempt_at.on_weekend? - end - - question_ids = schedule.question_list.question_ids.split(/,/) - question_ids = question_ids.shuffle if schedule.random? - - recipient_id = recipient_or_recipient_id.is_a?(Recipient) ? - recipient_or_recipient_id.id : - recipient_or_recipient_id - - schedule.recipient_schedules.create( - recipient_id: recipient_id, - upcoming_question_ids: question_ids.join(','), - next_attempt_at: next_attempt_at - ) - end - - -end diff --git a/app/models/schedule.rb b/app/models/schedule.rb deleted file mode 100644 index de181db4..00000000 --- a/app/models/schedule.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Schedule < ApplicationRecord - belongs_to :school - belongs_to :recipient_list - belongs_to :question_list - has_many :recipient_schedules - - validates :name, presence: true - validates :recipient_list, presence: true - validates :question_list, presence: true - - before_validation :set_start_date - after_create :create_recipient_schedules - - scope :active, -> { - where(active: true).where("start_date <= ? and end_date > ?", Date.today, Date.today) - } - - private - - def set_start_date - return if start_date.present? - self.start_date = Date.today - end - - def create_recipient_schedules - recipient_list.recipients.each do |recipient| - RecipientSchedule.create_for_recipient(recipient, self) - end - end - -end diff --git a/app/models/school.rb b/app/models/school.rb index 13d65c5e..74efc564 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -1,87 +1,17 @@ class School < ApplicationRecord - has_many :schedules, dependent: :destroy - has_many :recipient_lists, dependent: :destroy belongs_to :district - has_many :recipients, dependent: :destroy - has_many :school_categories, dependent: :destroy - has_many :user_schools, dependent: :destroy validates :name, presence: true scope :alphabetic, -> { order(name: :asc) } include FriendlyId - friendly_id :name, :use => [:slugged] + friendly_id :name, use: [:slugged] def self.find_by_district_code_and_school_code(district_code, school_code) School .joins(:district) - .where(districts: {qualtrics_code: district_code}) + .where(districts: { qualtrics_code: district_code }) .find_by_qualtrics_code(school_code) end - - def available_responders_for(question) - if question.for_students? - return student_count || 1 - elsif question.for_teachers? - return teacher_count || 1 - else - return 1 - end - end - - def merge_into(school_name) - school = district.schools.where(name: school_name).first - if school.nil? - puts "Unable to find school named #{school_name} in district (#{district.name})" - return - end - puts "Merging #{name} (#{id}) in to #{school.name} (#{school.id})" - schedules.update_all(school_id: school.id) - recipient_lists.update_all(school_id: school.id) - recipients.update_all(school_id: school.id) - school_categories.each do |school_category| - school_category.update(school_id: school.id) - existing_school_category = school.school_categories.for(school_category.school, school_category.category).in(school_category.year) - if existing_school_category.present? - if existing_school_category.attempt_count == 0 && existing_school_category.zscore.nil? - existing_school_category.destroy - else - school_category.destroy - end - end - end - - reload - - user_schools.update_all(school_id: school.id) - - school.school_categories.map(&:sync_aggregated_responses) - - base_categories = Category.joins(:questions).to_a.flatten.uniq - base_categories.each do |category| - SchoolCategory.for(school, category).each do |school_category| - year = school_category.year - dup_school_categories = SchoolCategory.for(school, category).in(year) - if dup_school_categories.count > 1 - dup_school_categories.each { |dsc| dsc.destroy unless dsc.id == school_category.id } - school_category.sync_aggregated_responses - parent = category.parent_category - while parent != nil - SchoolCategory.for(school, parent).in(year).valid.each do |parent_school_category| - parent_dup_school_categories = SchoolCategory.for(school, parent).in(year) - if parent_dup_school_categories.count > 1 - parent_dup_school_categories.each { |pdsc| pdsc.destroy unless pdsc.id == parent_school_category.id } - parent_school_category.sync_aggregated_responses - end - end - parent = parent.parent_category - end - end - end - end - - destroy - end - end diff --git a/app/models/school_category.rb b/app/models/school_category.rb deleted file mode 100644 index e05c5ffd..00000000 --- a/app/models/school_category.rb +++ /dev/null @@ -1,104 +0,0 @@ -class SchoolCategory < ApplicationRecord - - MIN_RESPONSE_COUNT = 10 - - belongs_to :school - belongs_to :category - - has_many :school_questions - - validates_associated :school - validates_associated :category - - scope :for, -> (school, category) { where(school: school).where(category: category) } - scope :for_parent_category, -> (school, category=nil) { where(school: school).joins(:category).merge(Category.for_parent(category)) } - scope :in, -> (year) { where(year: year) } - - scope :valid, -> { where("zscore is not null or valid_child_count is not null") } - - def admin? - child_categories = category.child_categories - return false if child_categories.blank? - child_categories.each { |cc| return false if cc.benchmark.blank? } - return true - end - - def root_index - category.root_index - end - - def answer_index_average - answer_index_total.to_f / response_count.to_f - end - - def aggregated_responses - attempt_data = Attempt. - created_in(year). - for_category(category). - for_school(school). - select('count(attempts.id) as attempt_count'). - select('count(attempts.answer_index) as response_count'). - select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] - - return { - attempt_count: attempt_data.attempt_count || 0, - response_count: attempt_data.response_count || 0, - answer_index_total: attempt_data.answer_index_total || 0, - zscore: attempt_data.answer_index_total.nil? ? - (attempt_data.response_count > MIN_RESPONSE_COUNT ? zscore : nil) : - (attempt_data.response_count > MIN_RESPONSE_COUNT ? - (attempt_data.answer_index_total.to_f / attempt_data.response_count.to_f - 3.to_f) : - nil) - } - end - - def chained_aggregated_responses - return {} if nonlikert.present? - - _aggregated_responses = aggregated_responses - - child_school_categories = [] - if category.child_categories.length > 0 - child_school_categories = category.child_categories.collect do |cc| - SchoolCategory.for(school, cc).in(year).valid - end.flatten.compact - - return {} if child_school_categories.blank? - end - - average_zscore = nil - zscore_categories = child_school_categories.select { |csc| csc.zscore.present? && !csc.zscore.nan? } - if zscore_categories.length > 0 - total_zscore = zscore_categories.inject(0) { |total, zc| total + zc.zscore } - average_zscore = total_zscore / zscore_categories.length - end - - return { - attempt_count: - _aggregated_responses[:attempt_count] + - child_school_categories.inject(0) { |total, csc| total + (csc.attempt_count || 0) }, - response_count: - _aggregated_responses[:response_count] + - child_school_categories.inject(0) { |total, csc| total + (csc.response_count || 0) }, - answer_index_total: - _aggregated_responses[:answer_index_total] + - child_school_categories.inject(0) { |total, csc| total + (csc.answer_index_total || 0) }, - zscore: average_zscore.present? ? average_zscore : _aggregated_responses[:zscore] - } - end - - def sync_aggregated_responses - # This doesn't seem to be taking into account valid_child_count or Boston's "Community and Wellbeing" category which should be suppressed if the "Health" category is the only child category visible. - - return if ENV['BULK_PROCESS'] - update(chained_aggregated_responses) - return if response_count == 0 && zscore.nil? - if category.parent_category.present? - parent_school_category = SchoolCategory.for(school, category.parent_category).in(year).first - if parent_school_category.nil? - parent_school_category = SchoolCategory.create(school: school, category: category.parent_category, year: year) - end - parent_school_category.sync_aggregated_responses - end - end -end diff --git a/app/models/school_question.rb b/app/models/school_question.rb deleted file mode 100644 index 91136ead..00000000 --- a/app/models/school_question.rb +++ /dev/null @@ -1,33 +0,0 @@ -class SchoolQuestion < ApplicationRecord - - belongs_to :school - belongs_to :question - belongs_to :school_category - - validates_associated :school - validates_associated :question - validates_associated :school_category - - scope :for, -> (school, question) { where(school_id: school.id, question_id: question.id) } - scope :in, -> (year) { where(year: year) } - - def sync_attempts - attempt_data = Attempt. - joins(:question). - created_in(school_category.year). - for_question(question). - for_school(school). - select('count(attempts.answer_index) as response_count'). - select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0] - - available_responders = school.available_responders_for(question) - - update( - attempt_count: available_responders, - response_count: attempt_data.response_count, - response_rate: attempt_data.response_count.to_f / available_responders.to_f, - response_total: attempt_data.answer_index_total - ) - end - -end diff --git a/app/models/sqm_category.rb b/app/models/sqm_category.rb deleted file mode 100644 index 5bbebe29..00000000 --- a/app/models/sqm_category.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SqmCategory < ActiveRecord::Base - include FriendlyId - friendly_id :name, use: [:slugged] - - scope :sorted, ->() { order(:sort_index) } - - has_many :subcategories - has_many :measures, through: :subcategories -end diff --git a/app/models/student.rb b/app/models/student.rb deleted file mode 100644 index 1ffc5e9a..00000000 --- a/app/models/student.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Student < ApplicationRecord - belongs_to :recipient -end diff --git a/app/models/subcategory.rb b/app/models/subcategory.rb index 5bc2a454..c563f253 100644 --- a/app/models/subcategory.rb +++ b/app/models/subcategory.rb @@ -1,5 +1,5 @@ class Subcategory < ActiveRecord::Base - belongs_to :sqm_category + belongs_to :category has_many :measures end diff --git a/app/models/user.rb b/app/models/user.rb deleted file mode 100644 index 2d2ce9d4..00000000 --- a/app/models/user.rb +++ /dev/null @@ -1,21 +0,0 @@ -class User < ApplicationRecord - # Include default devise modules. Others available are: - # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable - - has_many :user_schools - - def schools - districts = user_schools.map(&:district).compact.uniq - (user_schools.map(&:school) + districts.map(&:schools)).flatten.compact.uniq - end - - def admin?(school) - schools.index(school).present? - end - - def super_admin? - [1].index(id).present? - end -end diff --git a/app/models/user_school.rb b/app/models/user_school.rb deleted file mode 100644 index fe21ea8b..00000000 --- a/app/models/user_school.rb +++ /dev/null @@ -1,7 +0,0 @@ -class UserSchool < ApplicationRecord - - belongs_to :user - belongs_to :school - belongs_to :district - -end diff --git a/app/views/admin/index.html.haml b/app/views/admin/index.html.haml deleted file mode 100644 index 1d05f4c4..00000000 --- a/app/views/admin/index.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%p= link_to 'Categories', categories_path - -%p= link_to 'Questions', questions_path diff --git a/app/views/categories/_breadcrumbs.html.haml b/app/views/categories/_breadcrumbs.html.haml deleted file mode 100644 index 88057ccf..00000000 --- a/app/views/categories/_breadcrumbs.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%p - = school_category.category.path.map { |c| link_to(c.name, school_category_path(school_category.school, c, year: school_category.year)) }.join(' > ').html_safe diff --git a/app/views/sqm_categories/_data_item_section.html.erb b/app/views/categories/_data_item_section.html.erb similarity index 100% rename from app/views/sqm_categories/_data_item_section.html.erb rename to app/views/categories/_data_item_section.html.erb diff --git a/app/views/sqm_categories/_gauge_graph.html.erb b/app/views/categories/_gauge_graph.html.erb similarity index 100% rename from app/views/sqm_categories/_gauge_graph.html.erb rename to app/views/categories/_gauge_graph.html.erb diff --git a/app/views/sqm_categories/_measures_section.html.erb b/app/views/categories/_measures_section.html.erb similarity index 100% rename from app/views/sqm_categories/_measures_section.html.erb rename to app/views/categories/_measures_section.html.erb diff --git a/app/views/sqm_categories/_subcategory_section.html.erb b/app/views/categories/_subcategory_section.html.erb similarity index 100% rename from app/views/sqm_categories/_subcategory_section.html.erb rename to app/views/categories/_subcategory_section.html.erb diff --git a/app/views/sqm_categories/show.html.erb b/app/views/categories/show.html.erb similarity index 100% rename from app/views/sqm_categories/show.html.erb rename to app/views/categories/show.html.erb diff --git a/app/views/layouts/_school_header.html.haml b/app/views/layouts/_school_header.html.haml index eaf08d94..cabadb83 100644 --- a/app/views/layouts/_school_header.html.haml +++ b/app/views/layouts/_school_header.html.haml @@ -1,7 +1,7 @@ .row .col =# link_to(image_tag(@district.logo), @district) if @district.present? - %h2= link_to @school.name, school_path(@school, year: @year) + %h2= link_to @school.name, legacy_school_path(@school, year: @year) = simple_format(@school.description) - if @year.present? %p @@ -12,9 +12,9 @@ - @years.sort.each do |year|     - if @school_category.present? - = link_to_unless(year == @year, "#{year - 1}-#{year}", school_category_path(@school_category.school, @school_category.category, year: year)) + = link_to_unless(year == @year, "#{year - 1}-#{year}", legacy_school_legacy_category_path(@school_category.school, @school_category.category, year: year)) - else - = link_to_unless(year == @year, "#{year - 1}-#{year}", school_path(@school, year: year)) + = link_to_unless(year == @year, "#{year - 1}-#{year}", legacy_school_path(@school, year: year)) - if @school.district.present? %p %strong District: diff --git a/app/views/legacy/admin/index.html.haml b/app/views/legacy/admin/index.html.haml new file mode 100644 index 00000000..809a0407 --- /dev/null +++ b/app/views/legacy/admin/index.html.haml @@ -0,0 +1,3 @@ +%p= link_to 'Categories', legacy_categories_path + +%p= link_to 'Questions', legacy_questions_path diff --git a/app/views/legacy/categories/_breadcrumbs.html.haml b/app/views/legacy/categories/_breadcrumbs.html.haml new file mode 100644 index 00000000..e464a7bd --- /dev/null +++ b/app/views/legacy/categories/_breadcrumbs.html.haml @@ -0,0 +1,2 @@ +%p + = school_category.category.path.map { |c| link_to(c.name, legacy_school_legacy_category_path(school_category.school, c, year: school_category.year)) }.join(' > ').html_safe diff --git a/app/views/categories/_form.html.haml b/app/views/legacy/categories/_form.html.haml similarity index 93% rename from app/views/categories/_form.html.haml rename to app/views/legacy/categories/_form.html.haml index 75bf3c83..6ed0f655 100644 --- a/app/views/categories/_form.html.haml +++ b/app/views/legacy/categories/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(category) do |f| += form_for(category, as: 'category') do |f| - if category.errors.any? #error_explanation %h2 diff --git a/app/views/categories/_full_path.html.haml b/app/views/legacy/categories/_full_path.html.haml similarity index 100% rename from app/views/categories/_full_path.html.haml rename to app/views/legacy/categories/_full_path.html.haml diff --git a/app/views/categories/edit.html.haml b/app/views/legacy/categories/edit.html.haml similarity index 68% rename from app/views/categories/edit.html.haml rename to app/views/legacy/categories/edit.html.haml index 10a16e08..02de4dbe 100644 --- a/app/views/categories/edit.html.haml +++ b/app/views/legacy/categories/edit.html.haml @@ -2,4 +2,4 @@ = render 'form', category: @category = link_to 'Show', @category | -= link_to 'Back', categories_path += link_to 'Back', legacy_categories_path diff --git a/app/views/categories/index.html.haml b/app/views/legacy/categories/index.html.haml similarity index 82% rename from app/views/categories/index.html.haml rename to app/views/legacy/categories/index.html.haml index 047f34bd..a259502f 100644 --- a/app/views/categories/index.html.haml +++ b/app/views/legacy/categories/index.html.haml @@ -18,7 +18,7 @@ %td= category.external_id %td= category.parent_category_id %td= link_to 'Show', category - %td= link_to 'Edit', edit_category_path(category) + %td= link_to 'Edit', edit_legacy_category_path(category) %td= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %br/ -= link_to 'New Category', new_category_path += link_to 'New Category', new_legacy_category_path diff --git a/app/views/categories/index.json.jbuilder b/app/views/legacy/categories/index.json.jbuilder similarity index 100% rename from app/views/categories/index.json.jbuilder rename to app/views/legacy/categories/index.json.jbuilder diff --git a/app/views/categories/new.html.haml b/app/views/legacy/categories/new.html.haml similarity index 56% rename from app/views/categories/new.html.haml rename to app/views/legacy/categories/new.html.haml index 6ddb7a66..007cc88e 100644 --- a/app/views/categories/new.html.haml +++ b/app/views/legacy/categories/new.html.haml @@ -1,3 +1,3 @@ %h1 New Category = render 'form', category: @category -= link_to 'Back', categories_path += link_to 'Back', legacy_categories_path diff --git a/app/views/categories/show.html.haml b/app/views/legacy/categories/show.html.haml similarity index 86% rename from app/views/categories/show.html.haml rename to app/views/legacy/categories/show.html.haml index 44085713..f73c29f8 100644 --- a/app/views/categories/show.html.haml +++ b/app/views/legacy/categories/show.html.haml @@ -6,7 +6,7 @@ .row .col-12 %p - = render 'categories/breadcrumbs', school_category: @school_category + = render 'legacy/categories/breadcrumbs', school_category: @school_category .row .col-12 @@ -29,7 +29,7 @@ .indicator-container.py-3 - = render 'school_categories/indicator', info: @school_category + = render 'legacy/school_categories/indicator', info: @school_category - else .row.py-4 .col-12.text-center @@ -46,4 +46,4 @@ .row = render @questions -= render "shared/performance_spectrum" += render "legacy/shared/performance_spectrum" diff --git a/app/views/categories/show.json.jbuilder b/app/views/legacy/categories/show.json.jbuilder similarity index 100% rename from app/views/categories/show.json.jbuilder rename to app/views/legacy/categories/show.json.jbuilder diff --git a/app/views/districts/_form.html.haml b/app/views/legacy/districts/_form.html.haml similarity index 90% rename from app/views/districts/_form.html.haml rename to app/views/legacy/districts/_form.html.haml index 33a8f43f..aa4fbb1a 100644 --- a/app/views/districts/_form.html.haml +++ b/app/views/legacy/districts/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(district) do |f| += form_for(district, as: 'district') do |f| - if district.errors.any? #error_explanation %h2 diff --git a/app/views/districts/edit.html.haml b/app/views/legacy/districts/edit.html.haml similarity index 100% rename from app/views/districts/edit.html.haml rename to app/views/legacy/districts/edit.html.haml diff --git a/app/views/districts/index.html.haml b/app/views/legacy/districts/index.html.haml similarity index 100% rename from app/views/districts/index.html.haml rename to app/views/legacy/districts/index.html.haml diff --git a/app/views/districts/index.json.jbuilder b/app/views/legacy/districts/index.json.jbuilder similarity index 100% rename from app/views/districts/index.json.jbuilder rename to app/views/legacy/districts/index.json.jbuilder diff --git a/app/views/districts/new.html.haml b/app/views/legacy/districts/new.html.haml similarity index 100% rename from app/views/districts/new.html.haml rename to app/views/legacy/districts/new.html.haml diff --git a/app/views/districts/show.html.haml b/app/views/legacy/districts/show.html.haml similarity index 100% rename from app/views/districts/show.html.haml rename to app/views/legacy/districts/show.html.haml diff --git a/app/views/districts/show.json.jbuilder b/app/views/legacy/districts/show.json.jbuilder similarity index 100% rename from app/views/districts/show.json.jbuilder rename to app/views/legacy/districts/show.json.jbuilder diff --git a/app/views/question_lists/_form.html.haml b/app/views/legacy/question_lists/_form.html.haml similarity index 72% rename from app/views/question_lists/_form.html.haml rename to app/views/legacy/question_lists/_form.html.haml index 223a2670..f1a08204 100644 --- a/app/views/question_lists/_form.html.haml +++ b/app/views/legacy/question_lists/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(question_list) do |f| += form_for(question_list, as: 'question_list') do |f| - if question_list.errors.any? #error_explanation %h2 @@ -17,6 +17,6 @@ = f.label :question_id_array, 'Questions' %br/ .form-check.form-check-collection - = f.collection_check_boxes(:question_id_array, Question.all, :id, :text) { |c| c.label(class: 'form-check-label') { c.check_box(class: 'form-check-input') + " #{c.text}" } } + = f.collection_check_boxes(:question_id_array, Legacy::Question.all, :id, :text) { |c| c.label(class: 'form-check-label') { c.check_box(class: 'form-check-input') + " #{c.text}" } } .form-group = f.submit 'Save List', class: 'btn btn-primary' diff --git a/app/views/question_lists/edit.html.haml b/app/views/legacy/question_lists/edit.html.haml similarity index 70% rename from app/views/question_lists/edit.html.haml rename to app/views/legacy/question_lists/edit.html.haml index 374f01b9..ed47c989 100644 --- a/app/views/question_lists/edit.html.haml +++ b/app/views/legacy/question_lists/edit.html.haml @@ -2,4 +2,4 @@ = render 'form', question_list: @question_list = link_to 'Show', @question_list | -= link_to 'Back', question_lists_path += link_to 'Back', legacy_question_lists_path diff --git a/app/views/question_lists/index.html.haml b/app/views/legacy/question_lists/index.html.haml similarity index 77% rename from app/views/question_lists/index.html.haml rename to app/views/legacy/question_lists/index.html.haml index 2e68099a..28664be7 100644 --- a/app/views/question_lists/index.html.haml +++ b/app/views/legacy/question_lists/index.html.haml @@ -14,7 +14,7 @@ %td= question_list.description %td= question_list.question_ids %td= link_to 'Show', question_list - %td= link_to 'Edit', edit_question_list_path(question_list) + %td= link_to 'Edit', edit_legacy_question_list_path(question_list) %td= link_to 'Destroy', question_list, method: :delete, data: { confirm: 'Are you sure?' } %br/ -= link_to 'New Question List', new_question_list_path += link_to 'New Question List', new_legacy_question_list_path diff --git a/app/views/question_lists/index.json.jbuilder b/app/views/legacy/question_lists/index.json.jbuilder similarity index 100% rename from app/views/question_lists/index.json.jbuilder rename to app/views/legacy/question_lists/index.json.jbuilder diff --git a/app/views/question_lists/new.html.haml b/app/views/legacy/question_lists/new.html.haml similarity index 100% rename from app/views/question_lists/new.html.haml rename to app/views/legacy/question_lists/new.html.haml diff --git a/app/views/question_lists/show.html.haml b/app/views/legacy/question_lists/show.html.haml similarity index 68% rename from app/views/question_lists/show.html.haml rename to app/views/legacy/question_lists/show.html.haml index 5a8e256c..d47432af 100644 --- a/app/views/question_lists/show.html.haml +++ b/app/views/legacy/question_lists/show.html.haml @@ -7,9 +7,9 @@ = @question_list.description %p - = link_to 'Edit', edit_question_list_path(@question_list) + = link_to 'Edit', edit_legacy_question_list_path(@question_list) | - = link_to 'Back', question_lists_path + = link_to 'Back', legacy_question_lists_path %br %br diff --git a/app/views/question_lists/show.json.jbuilder b/app/views/legacy/question_lists/show.json.jbuilder similarity index 100% rename from app/views/question_lists/show.json.jbuilder rename to app/views/legacy/question_lists/show.json.jbuilder diff --git a/app/views/questions/_form.html.haml b/app/views/legacy/questions/_form.html.haml similarity index 94% rename from app/views/questions/_form.html.haml rename to app/views/legacy/questions/_form.html.haml index a19db4f3..b4b94ac6 100644 --- a/app/views/questions/_form.html.haml +++ b/app/views/legacy/questions/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(question) do |f| += form_for(question, as: 'question') do |f| - if question.errors.any? #error_explanation %h2 diff --git a/app/views/questions/_question.html.haml b/app/views/legacy/questions/_question.html.haml similarity index 90% rename from app/views/questions/_question.html.haml rename to app/views/legacy/questions/_question.html.haml index c53f5492..3d16da6b 100644 --- a/app/views/questions/_question.html.haml +++ b/app/views/legacy/questions/_question.html.haml @@ -1,6 +1,6 @@ - aggregated_responses = question.aggregated_responses_for_school(@school) - return if aggregated_responses.nil? -- school_question = SchoolQuestion.for(@school, question).first +- school_question = Legacy::SchoolQuestion.for(@school, question).first - valid_responses = school_question.nil? ? true : school_question.response_rate > 0.3 # || (aggregated_responses.count.to_f / @school.available_responders_for(question).to_f)) >= 0.3 .col-12.col-md-6.py-3 @@ -11,7 +11,7 @@ - if valid_responses .row.pt-2 .col-4.indicator-container.centered - = render 'school_categories/indicator', info: aggregated_responses, small: true + = render 'legacy/school_categories/indicator', info: aggregated_responses, small: true .col-8 %p @@ -48,7 +48,7 @@ Raw Data .collapse{id: "histogram#{question.id}"} - = render 'shared/histogram', data: aggregated_responses + = render 'legacy/shared/histogram', data: aggregated_responses %p.collapse{id: "raw-data#{question.id}"} = aggregated_responses.responses.map(&:answer_index_with_reverse).join(', ') diff --git a/app/views/questions/edit.html.haml b/app/views/legacy/questions/edit.html.haml similarity index 68% rename from app/views/questions/edit.html.haml rename to app/views/legacy/questions/edit.html.haml index c5edb3ae..e9179886 100644 --- a/app/views/questions/edit.html.haml +++ b/app/views/legacy/questions/edit.html.haml @@ -2,4 +2,4 @@ = render 'form', question: @question = link_to 'Show', @question | -= link_to 'Back', questions_path += link_to 'Back', legacy_questions_path diff --git a/app/views/questions/index.html.haml b/app/views/legacy/questions/index.html.haml similarity index 84% rename from app/views/questions/index.html.haml rename to app/views/legacy/questions/index.html.haml index 2bd455b1..06639a82 100644 --- a/app/views/questions/index.html.haml +++ b/app/views/legacy/questions/index.html.haml @@ -22,7 +22,7 @@ %td= question.option5 %td= link_to(question.category.name, question.category) %td= link_to 'Show', question - %td= link_to 'Edit', edit_question_path(question) + %td= link_to 'Edit', edit_legacy_question_path(question) %td= link_to 'Destroy', question, method: :delete, data: { confirm: 'Are you sure?' } %br/ -= link_to 'New Question', new_question_path += link_to 'New Question', new_legacy_question_path diff --git a/app/views/questions/index.json.jbuilder b/app/views/legacy/questions/index.json.jbuilder similarity index 100% rename from app/views/questions/index.json.jbuilder rename to app/views/legacy/questions/index.json.jbuilder diff --git a/app/views/questions/new.html.haml b/app/views/legacy/questions/new.html.haml similarity index 57% rename from app/views/questions/new.html.haml rename to app/views/legacy/questions/new.html.haml index 290bccf2..09c5bbe4 100644 --- a/app/views/questions/new.html.haml +++ b/app/views/legacy/questions/new.html.haml @@ -1,3 +1,3 @@ %h1 New Question = render 'form', question: @question -= link_to 'Back', questions_path += link_to 'Back', legacy_questions_path diff --git a/app/views/questions/show.html.haml b/app/views/legacy/questions/show.html.haml similarity index 70% rename from app/views/questions/show.html.haml rename to app/views/legacy/questions/show.html.haml index a808a8b5..84e6c312 100644 --- a/app/views/questions/show.html.haml +++ b/app/views/legacy/questions/show.html.haml @@ -21,13 +21,13 @@ %strong Category:   - if @question.category.present? - = render partial: 'categories/full_path', locals: {category: @question.category} + = render partial: 'legacy/categories/full_path', locals: {category: @question.category} - else No Category -= link_to 'Edit', edit_question_path(@question) += link_to 'Edit', edit_legacy_question_path(@question) | -= link_to 'Back', questions_path += link_to 'Back', legacy_questions_path %br diff --git a/app/views/questions/show.json.jbuilder b/app/views/legacy/questions/show.json.jbuilder similarity index 100% rename from app/views/questions/show.json.jbuilder rename to app/views/legacy/questions/show.json.jbuilder diff --git a/app/views/recipient_lists/_form.html.haml b/app/views/legacy/recipient_lists/_form.html.haml similarity index 92% rename from app/views/recipient_lists/_form.html.haml rename to app/views/legacy/recipient_lists/_form.html.haml index 6910be24..cf2652cc 100644 --- a/app/views/recipient_lists/_form.html.haml +++ b/app/views/legacy/recipient_lists/_form.html.haml @@ -1,4 +1,4 @@ -= form_for([@school, @recipient_list]) do |f| += form_for([@school, @recipient_list], as: 'recipient_list') do |f| - if @recipient_list.errors.any? #error_explanation %h2 diff --git a/app/views/recipient_lists/edit.html.haml b/app/views/legacy/recipient_lists/edit.html.haml similarity index 100% rename from app/views/recipient_lists/edit.html.haml rename to app/views/legacy/recipient_lists/edit.html.haml diff --git a/app/views/recipient_lists/index.html.haml b/app/views/legacy/recipient_lists/index.html.haml similarity index 70% rename from app/views/recipient_lists/index.html.haml rename to app/views/legacy/recipient_lists/index.html.haml index f064ed06..80ece6e7 100644 --- a/app/views/recipient_lists/index.html.haml +++ b/app/views/legacy/recipient_lists/index.html.haml @@ -13,7 +13,7 @@ %td= recipient_list.description %td= recipient_list.recipient_ids %td= link_to 'Show', [recipient_list.school, recipient_list] - %td= link_to 'Edit', edit_school_recipient_list_path(recipient_list.school, recipient_list) + %td= link_to 'Edit', edit_legacy_school_legacy_recipient_list_path(recipient_list.school, recipient_list) %td= link_to 'Destroy', [recipient_list.school, recipient_list], :confirm => 'Are you sure?', :method => :delete %br/ -= link_to 'New Recipient list', new_school_recipient_list_path(@school) += link_to 'New Recipient list', new_legacy_school_legacy_recipient_list_path(@school) diff --git a/app/views/recipient_lists/new.html.haml b/app/views/legacy/recipient_lists/new.html.haml similarity index 100% rename from app/views/recipient_lists/new.html.haml rename to app/views/legacy/recipient_lists/new.html.haml diff --git a/app/views/recipient_lists/show.html.haml b/app/views/legacy/recipient_lists/show.html.haml similarity index 63% rename from app/views/recipient_lists/show.html.haml rename to app/views/legacy/recipient_lists/show.html.haml index 61df0216..4975cc4d 100644 --- a/app/views/recipient_lists/show.html.haml +++ b/app/views/legacy/recipient_lists/show.html.haml @@ -1,6 +1,6 @@ %p %b School: - = link_to @school.name, school_admin_path(@school) + = link_to @school.name, legacy_school_admin_path(@school) %p %b Name: = @recipient_list.name @@ -9,13 +9,13 @@ = @recipient_list.description %p - = link_to 'Edit', edit_school_recipient_list_path(@recipient_list.school, @recipient_list) + = link_to 'Edit', edit_legacy_school_legacy_recipient_list_path(@recipient_list.school, @recipient_list) | = link_to 'Back', @recipient_list.school %br %br - + %p %b Recipients: - @recipient_list.recipients.each do |recipient| diff --git a/app/views/recipients/_form.html.haml b/app/views/legacy/recipients/_form.html.haml similarity index 95% rename from app/views/recipients/_form.html.haml rename to app/views/legacy/recipients/_form.html.haml index dcf28a20..dc4e64d7 100644 --- a/app/views/recipients/_form.html.haml +++ b/app/views/legacy/recipients/_form.html.haml @@ -1,4 +1,4 @@ -= form_for([@school, recipient]) do |f| += form_for([@school, recipient], as: 'recipient') do |f| - if recipient.errors.any? #error_explanation %h2 diff --git a/app/views/legacy/recipients/edit.html.haml b/app/views/legacy/recipients/edit.html.haml new file mode 100644 index 00000000..fa9df5a0 --- /dev/null +++ b/app/views/legacy/recipients/edit.html.haml @@ -0,0 +1,5 @@ +%h1 Editing Recipient += render 'form', recipient: @recipient += link_to 'Show', legacy_school_legacy_recipient_path(@school, @recipient) +| += link_to 'Back', legacy_school_path(@school) diff --git a/app/views/recipients/import.html.haml b/app/views/legacy/recipients/import.html.haml similarity index 72% rename from app/views/recipients/import.html.haml rename to app/views/legacy/recipients/import.html.haml index a2f8f196..b059975b 100644 --- a/app/views/recipients/import.html.haml +++ b/app/views/legacy/recipients/import.html.haml @@ -1,7 +1,7 @@ .row .offset-sm-2.col-sm-8 %h3 Import Recipients To This School - = form_tag import_school_recipients_path(@school), multipart: true do + = form_tag import_legacy_school_legacy_recipients_path(@school), multipart: true do %br .form-group = file_field_tag :file, class: 'form-control-file' diff --git a/app/views/recipients/index.html.haml b/app/views/legacy/recipients/index.html.haml similarity index 61% rename from app/views/recipients/index.html.haml rename to app/views/legacy/recipients/index.html.haml index f04ecb22..a8f9dd6b 100644 --- a/app/views/recipients/index.html.haml +++ b/app/views/legacy/recipients/index.html.haml @@ -26,8 +26,8 @@ %td= recipient.income %td= recipient.opted_out %td= recipient.school_id - %td= link_to 'Show', school_recipient_path(@school, recipient) - %td= link_to 'Edit', edit_school_recipient_path(@school, recipient) - %td= link_to 'Destroy', school_recipient_path(@school, recipient), method: :delete, data: { confirm: 'Are you sure?' } + %td= link_to 'Show', legacy_school_legacy_recipient_path(@school, recipient) + %td= link_to 'Edit', edit_legacy_school_legacy_recipient_path(@school, recipient) + %td= link_to 'Destroy', legacy_school_legacy_recipient_path(@school, recipient), method: :delete, data: { confirm: 'Are you sure?' } %br/ -= link_to 'New Recipient', new_school_recipient_path(@school) += link_to 'New Recipient', new_legacy_school_legacy_recipient_path(@school) diff --git a/app/views/recipients/index.json.jbuilder b/app/views/legacy/recipients/index.json.jbuilder similarity index 100% rename from app/views/recipients/index.json.jbuilder rename to app/views/legacy/recipients/index.json.jbuilder diff --git a/app/views/recipients/new.html.haml b/app/views/legacy/recipients/new.html.haml similarity index 100% rename from app/views/recipients/new.html.haml rename to app/views/legacy/recipients/new.html.haml diff --git a/app/views/recipients/show.html.haml b/app/views/legacy/recipients/show.html.haml similarity index 90% rename from app/views/recipients/show.html.haml rename to app/views/legacy/recipients/show.html.haml index 0791746a..e0a00f8a 100644 --- a/app/views/recipients/show.html.haml +++ b/app/views/legacy/recipients/show.html.haml @@ -2,7 +2,7 @@ .col %p %strong School: - = link_to @school.name, school_admin_path(@school) + = link_to @school.name, legacy_school_admin_path(@school) %p %strong Recipient: = @recipient.name @@ -55,10 +55,9 @@ %strong Next Attempt At: = recipient_schedule.next_attempt_at.in_time_zone('Eastern Time (US & Canada)').strftime('%m-%e-%y %H:%M') -= link_to 'Edit', edit_school_recipient_path(@school, @recipient) += link_to 'Edit', edit_legacy_school_legacy_recipient_path(@school, @recipient) | -= link_to 'Back', school_path(@school) - += link_to 'Back', legacy_school_path(@school) %br diff --git a/app/views/recipients/show.json.jbuilder b/app/views/legacy/recipients/show.json.jbuilder similarity index 100% rename from app/views/recipients/show.json.jbuilder rename to app/views/legacy/recipients/show.json.jbuilder diff --git a/app/views/schedules/_form.html.haml b/app/views/legacy/schedules/_form.html.haml similarity index 89% rename from app/views/schedules/_form.html.haml rename to app/views/legacy/schedules/_form.html.haml index 2755c775..a38b44b6 100644 --- a/app/views/schedules/_form.html.haml +++ b/app/views/legacy/schedules/_form.html.haml @@ -1,4 +1,4 @@ -= form_for([@schedule.school, @schedule]) do |f| += form_for([@schedule.school, @schedule], as: 'schedule') do |f| - if @schedule.errors.any? #error_explanation %h2 @@ -46,6 +46,6 @@ .form-group = f.label :question_list_id %br/ - = f.collection_select :question_list_id, QuestionList.all, :id, :name, class: 'form-control' + = f.collection_select :question_list_id, Legacy::QuestionList.all, :id, :name, class: 'form-control' .form-group = f.submit 'Save Schedule', class: 'btn btn-primary' diff --git a/app/views/schedules/edit.html.haml b/app/views/legacy/schedules/edit.html.haml similarity index 54% rename from app/views/schedules/edit.html.haml rename to app/views/legacy/schedules/edit.html.haml index ad65abfd..f606aea0 100644 --- a/app/views/schedules/edit.html.haml +++ b/app/views/legacy/schedules/edit.html.haml @@ -2,4 +2,4 @@ = render 'form' = link_to 'Show', [@schedule.school, @schedule] | -= link_to 'Back', school_schedules_path(@schedule.school) += link_to 'Back', legacy_school_legacy_schedules_path(@schedule.school) diff --git a/app/views/schedules/new.html.haml b/app/views/legacy/schedules/new.html.haml similarity index 100% rename from app/views/schedules/new.html.haml rename to app/views/legacy/schedules/new.html.haml diff --git a/app/views/schedules/show.html.haml b/app/views/legacy/schedules/show.html.haml similarity index 71% rename from app/views/schedules/show.html.haml rename to app/views/legacy/schedules/show.html.haml index 10329b80..553c8b55 100644 --- a/app/views/schedules/show.html.haml +++ b/app/views/legacy/schedules/show.html.haml @@ -7,7 +7,7 @@ = @schedule.description %p %b School: - = link_to(@school.name, school_admin_path(@school)) + = link_to(@school.name, legacy_school_admin_path(@school)) %p %b Frequency hours: = frequency_description(@schedule.frequency_hours) @@ -30,6 +30,6 @@ %b Question list: = link_to(@schedule.question_list.name, @schedule.question_list) -= link_to 'Edit', edit_school_schedule_path(@schedule.school, @schedule) += link_to 'Edit', edit_legacy_school_legacy_schedule_path(@schedule.school, @schedule) | -= link_to 'Back', school_schedules_path(@schedule.school) += link_to 'Back', legacy_school_legacy_schedules_path(@schedule.school) diff --git a/app/views/school/recipient_lists/index.json.jbuilder b/app/views/legacy/school/recipient_lists/index.json.jbuilder similarity index 62% rename from app/views/school/recipient_lists/index.json.jbuilder rename to app/views/legacy/school/recipient_lists/index.json.jbuilder index 1a8de98a..ee97609d 100644 --- a/app/views/school/recipient_lists/index.json.jbuilder +++ b/app/views/legacy/school/recipient_lists/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@school_recipient_lists) do |school_recipient_list| json.extract! school_recipient_list, :id, :name, :description, :recipient_ids - json.url school_recipient_list_url(school_recipient_list, format: :json) + json.url legacy_school_legacy_recipient_list_url(school_recipient_list, format: :json) end diff --git a/app/views/school/recipient_lists/show.json.jbuilder b/app/views/legacy/school/recipient_lists/show.json.jbuilder similarity index 100% rename from app/views/school/recipient_lists/show.json.jbuilder rename to app/views/legacy/school/recipient_lists/show.json.jbuilder diff --git a/app/views/school/schedules/index.json.jbuilder b/app/views/legacy/school/schedules/index.json.jbuilder similarity index 100% rename from app/views/school/schedules/index.json.jbuilder rename to app/views/legacy/school/schedules/index.json.jbuilder diff --git a/app/views/school/schedules/show.json.jbuilder b/app/views/legacy/school/schedules/show.json.jbuilder similarity index 100% rename from app/views/school/schedules/show.json.jbuilder rename to app/views/legacy/school/schedules/show.json.jbuilder diff --git a/app/views/school_categories/_indicator.html.haml b/app/views/legacy/school_categories/_indicator.html.haml similarity index 100% rename from app/views/school_categories/_indicator.html.haml rename to app/views/legacy/school_categories/_indicator.html.haml diff --git a/app/views/school_categories/_school_category.html.haml b/app/views/legacy/school_categories/_school_category.html.haml similarity index 79% rename from app/views/school_categories/_school_category.html.haml rename to app/views/legacy/school_categories/_school_category.html.haml index f29d9e1c..0b95c54e 100644 --- a/app/views/school_categories/_school_category.html.haml +++ b/app/views/legacy/school_categories/_school_category.html.haml @@ -1,11 +1,11 @@ .col-12.col-sm-6.py-3 .school_category.short.p-2 %h4.title.text-center.pt-3 - = link_to(school_category.category.name, school_category_path(school_category.school, school_category.category, year: school_category.year)) + = link_to(school_category.category.name, legacy_school_legacy_category_path(school_category.school, school_category.category, year: school_category.year)) - if !school_category.new_record? && (school_category.school.district.name != "Boston" || (school_category.valid_child_count || 1) > 0) .indicator-container.short - = render 'school_categories/indicator', info: school_category + = render 'legacy/school_categories/indicator', info: school_category .description.px-2.pt-3.pb-2.mt-2 - if false #(measurements = school_category.questions.measurements.for_school(school_measure.school)).present? diff --git a/app/views/schools/_form.html.haml b/app/views/legacy/schools/_form.html.haml similarity index 92% rename from app/views/schools/_form.html.haml rename to app/views/legacy/schools/_form.html.haml index bd4ad5f8..bdd3fc83 100644 --- a/app/views/schools/_form.html.haml +++ b/app/views/legacy/schools/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(school) do |f| += form_for(school, as: 'school') do |f| - if school.errors.any? #error_explanation %h2 diff --git a/app/views/schools/admin.html.haml b/app/views/legacy/schools/admin.html.haml similarity index 65% rename from app/views/schools/admin.html.haml rename to app/views/legacy/schools/admin.html.haml index 7d62eeee..fbb0924a 100644 --- a/app/views/schools/admin.html.haml +++ b/app/views/legacy/schools/admin.html.haml @@ -7,17 +7,17 @@ %strong District: = @school.district_id - %p= link_to "Add Recipient", new_school_recipient_path(@school) + %p= link_to "Add Recipient", new_legacy_school_legacy_recipient_path(@school) - %p= link_to "Bulk Add Recipients", import_school_recipients_path(@school) + %p= link_to "Bulk Add Recipients", import_legacy_school_legacy_recipients_path(@school) - %p= link_to "Create Recipient List", new_school_recipient_list_path(@school) + %p= link_to "Create Recipient List", new_legacy_school_legacy_recipient_list_path(@school) - %p= link_to "Create A Question List", new_question_list_path() + %p= link_to "Create A Question List", new_legacy_question_list_path() - %p= link_to "Create A Schedule", new_school_schedule_path(@school) + %p= link_to "Create A Schedule", new_legacy_school_legacy_schedule_path(@school) - = link_to 'Edit', edit_school_path(@school) + = link_to 'Edit', edit_legacy_school_path(@school) | = link_to 'Back', root_path @@ -46,8 +46,8 @@ %td= link_to schedule.name, [@school, schedule] %td= schedule.start_date %td= schedule.end_date - %td= link_to('Edit', edit_school_schedule_path(@school, schedule)) - %td= link_to('Delete', school_schedule_path(@school, schedule), method: :delete, data: {confirm: 'Are you sure you want to delete this schedule?'}) + %td= link_to('Edit', edit_legacy_school_legacy_schedule_path(@school, schedule)) + %td= link_to('Delete', legacy_school_legacy_schedule_path(@school, schedule), method: :delete, data: {confirm: 'Are you sure you want to delete this schedule?'}) %br %br @@ -71,8 +71,8 @@ %tr.recipient %td= link_to recipient_list.name, [@school, recipient_list] %td= recipient_list.description - %td= link_to('Edit', edit_school_recipient_list_path(@school, recipient_list)) - %td= link_to('Delete', school_recipient_list_path(@school, recipient_list), method: :delete, data: {confirm: 'Are you sure you want to delete this list?'}) + %td= link_to('Edit', edit_legacy_school_legacy_recipient_list_path(@school, recipient_list)) + %td= link_to('Delete', legacy_school_legacy_recipient_list_path(@school, recipient_list), method: :delete, data: {confirm: 'Are you sure you want to delete this list?'}) %br %br @@ -100,8 +100,8 @@ %td= recipient.phone %td= recipient.attempts_count %td= recipient.responses_count - %td= link_to('Edit', edit_school_recipient_path(@school, recipient)) - %td= link_to('Delete', school_recipient_path(@school, recipient), method: :delete, data: {confirm: 'Are you sure you want to delete this recipient?'}) + %td= link_to('Edit', edit_legacy_school_legacy_recipient_path(@school, recipient)) + %td= link_to('Delete', legacy_school_legacy_recipient_path(@school, recipient), method: :delete, data: {confirm: 'Are you sure you want to delete this recipient?'}) %br %br @@ -111,7 +111,7 @@ %small = link_to('show/hide', '#question_lists', data: {toggle: 'collapse'}, 'aria-expanded': 'false', 'aria-controls': 'collapseExample') #question_lists.collapse - - if QuestionList.count == 0 + - if Legacy::QuestionList.count == 0 %p %strong None Yet - else @@ -121,9 +121,9 @@ %th Name %th Description %th{colspan: 2} Actions - - QuestionList.all.each do |question_list| + - Legacy::QuestionList.all.each do |question_list| %tr.question_list %td= link_to question_list.name, question_list %td= question_list.description - %td= link_to('Edit', edit_question_list_path(question_list)) - %td= link_to('Delete', question_list_path(question_list), method: :delete, data: {confirm: 'Are you sure you want to delete this question list?'}) + %td= link_to('Edit', edit_legacy_question_list_path(question_list)) + %td= link_to('Delete', legacy_question_list_path(question_list), method: :delete, data: {confirm: 'Are you sure you want to delete this question list?'}) diff --git a/app/views/schools/edit.html.haml b/app/views/legacy/schools/edit.html.haml similarity index 67% rename from app/views/schools/edit.html.haml rename to app/views/legacy/schools/edit.html.haml index 8c69ff7f..91979fe1 100644 --- a/app/views/schools/edit.html.haml +++ b/app/views/legacy/schools/edit.html.haml @@ -2,4 +2,4 @@ = render 'form', school: @school = link_to 'Show', @school | -= link_to 'Back', schools_path += link_to 'Back', legacy_schools_path diff --git a/app/views/schools/new.html.haml b/app/views/legacy/schools/new.html.haml similarity index 69% rename from app/views/schools/new.html.haml rename to app/views/legacy/schools/new.html.haml index 352dff2e..1c196bf0 100644 --- a/app/views/schools/new.html.haml +++ b/app/views/legacy/schools/new.html.haml @@ -3,4 +3,4 @@ %h3 Create A New School = render 'form', school: @school %br - %p= link_to 'Back', schools_path + %p= link_to 'Back', legacy_schools_path diff --git a/app/views/schools/show.html.haml b/app/views/legacy/schools/show.html.haml similarity index 94% rename from app/views/schools/show.html.haml rename to app/views/legacy/schools/show.html.haml index 16cc0eb8..6ec2a1f3 100644 --- a/app/views/schools/show.html.haml +++ b/app/views/legacy/schools/show.html.haml @@ -24,4 +24,4 @@ .row = render @school_categories.sort { |a, b| a.root_index <=> b.root_index } -= render "shared/performance_spectrum" += render "legacy/shared/performance_spectrum" diff --git a/app/views/schools/show.json.jbuilder b/app/views/legacy/schools/show.json.jbuilder similarity index 100% rename from app/views/schools/show.json.jbuilder rename to app/views/legacy/schools/show.json.jbuilder diff --git a/app/views/shared/_histogram.html.haml b/app/views/legacy/shared/_histogram.html.haml similarity index 100% rename from app/views/shared/_histogram.html.haml rename to app/views/legacy/shared/_histogram.html.haml diff --git a/app/views/shared/_performance_spectrum.html.haml b/app/views/legacy/shared/_performance_spectrum.html.haml similarity index 100% rename from app/views/shared/_performance_spectrum.html.haml rename to app/views/legacy/shared/_performance_spectrum.html.haml diff --git a/app/views/users/show.html.haml b/app/views/legacy/users/show.html.haml similarity index 84% rename from app/views/users/show.html.haml rename to app/views/legacy/users/show.html.haml index 2b8c82ba..a212dc3f 100644 --- a/app/views/users/show.html.haml +++ b/app/views/legacy/users/show.html.haml @@ -16,4 +16,4 @@ - current_user.schools.each do |school| %tr.school %td= link_to school.name, school - %td= link_to('Admin', school_admin_path(school)) + %td= link_to('Admin', legacy_school_admin_path(school)) diff --git a/app/views/welcome/index.html.haml b/app/views/legacy/welcome/index.html.haml similarity index 100% rename from app/views/welcome/index.html.haml rename to app/views/legacy/welcome/index.html.haml diff --git a/app/views/recipients/edit.html.haml b/app/views/recipients/edit.html.haml deleted file mode 100644 index b7512be7..00000000 --- a/app/views/recipients/edit.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%h1 Editing Recipient -= render 'form', recipient: @recipient -= link_to 'Show', school_recipient_path(@school, @recipient) -| -= link_to 'Back', school_path(@school) diff --git a/config/routes.rb b/config/routes.rb index 6b5c6ea6..5fbde97e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,39 +1,40 @@ Rails.application.routes.draw do - resources :question_lists - resources :questions - resources :categories - resources :districts do - resources :schools, only: [:index, :show] do - resources :dashboard, only: [:index] - resources :sqm_categories, only: [:show], path: 'browse' + scope module: 'legacy', as: 'legacy' do + resources :question_lists + resources :questions + resources :categories + resources :districts + resources :schools do + resources :recipient_lists, as: 'legacy_recipient_lists' + resources :recipients, as: 'legacy_recipients' do + collection do + get :import + post :import + end + end + resources :schedules, as: 'legacy_schedules' + resources :categories, only: [:show], as: 'legacy_categories' + resources :questions, only: [:show], as: 'legacy_questions' + get :admin end + + get '/admin', to: 'admin#index', as: 'admin' + post '/twilio', to: 'attempts#twilio' end - resources :schools do - resources :recipient_lists - resources :recipients do - collection do - get :import - post :import - end + resources :districts do + resources :schools, only: [:index, :show] do + resources :dashboard, only: [:index] + resources :categories, only: [:show], path: 'browse' end - resources :schedules - resources :categories, only: [:show] - resources :questions, only: [:show] - get :admin end - # resources :attempts, only: [:get, :update] - - devise_for :users + devise_for :users, class_name: 'Legacy::User' as :user do - get 'users', :to => 'users#show', :as => :user_root # Rails 3 + get 'users', :to => 'legacy/users#show', :as => :user_root # Rails 3 end # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - get '/admin', to: 'admin#index', as: 'admin' - post '/twilio', to: 'attempts#twilio' - get '/welcome', to: 'home#index' - root to: "welcome#index" + root to: "legacy/welcome#index" end diff --git a/db/migrate/20211112182728_change_question_list_to_legacy_question_list.rb b/db/migrate/20211112182728_change_question_list_to_legacy_question_list.rb new file mode 100644 index 00000000..87770474 --- /dev/null +++ b/db/migrate/20211112182728_change_question_list_to_legacy_question_list.rb @@ -0,0 +1,5 @@ +class ChangeQuestionListToLegacyQuestionList < ActiveRecord::Migration[6.1] + def change + rename_table :question_lists, :legacy_question_lists + end +end diff --git a/db/migrate/20211112183026_change_legacy_tables_so_they_include_legacy_prefix.rb b/db/migrate/20211112183026_change_legacy_tables_so_they_include_legacy_prefix.rb new file mode 100644 index 00000000..eeb5cf68 --- /dev/null +++ b/db/migrate/20211112183026_change_legacy_tables_so_they_include_legacy_prefix.rb @@ -0,0 +1,18 @@ +class ChangeLegacyTablesSoTheyIncludeLegacyPrefix < ActiveRecord::Migration[6.1] + def change + rename_table :attempts, :legacy_attempts + rename_table :categories, :legacy_categories + rename_table :districts, :legacy_districts + rename_table :questions, :legacy_questions + rename_table :recipients, :legacy_recipients + rename_table :recipient_lists, :legacy_recipient_lists + rename_table :recipient_schedules, :legacy_recipient_schedules + rename_table :schedules, :legacy_schedules + rename_table :schools, :legacy_schools + rename_table :school_categories, :legacy_school_categories + rename_table :school_questions, :legacy_school_questions + rename_table :students, :legacy_students + rename_table :users, :legacy_users + rename_table :user_schools, :legacy_user_schools + end +end diff --git a/db/migrate/20211112205415_create_school_for_new_dashboard.rb b/db/migrate/20211112205415_create_school_for_new_dashboard.rb new file mode 100644 index 00000000..24f0db80 --- /dev/null +++ b/db/migrate/20211112205415_create_school_for_new_dashboard.rb @@ -0,0 +1,13 @@ +class CreateSchoolForNewDashboard < ActiveRecord::Migration[6.1] + def change + create_table :schools do |t| + t.string :name + t.integer :district_id + t.text :description + t.string :slug + t.integer :qualtrics_code + + t.timestamps + end + end +end diff --git a/db/migrate/20211112210223_create_district_for_new_dashboard.rb b/db/migrate/20211112210223_create_district_for_new_dashboard.rb new file mode 100644 index 00000000..1d1ec895 --- /dev/null +++ b/db/migrate/20211112210223_create_district_for_new_dashboard.rb @@ -0,0 +1,11 @@ +class CreateDistrictForNewDashboard < ActiveRecord::Migration[6.1] + def change + create_table :districts do |t| + t.string :name + t.string :slug + t.integer :qualtrics_code + + t.timestamps + end + end +end diff --git a/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb b/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb new file mode 100644 index 00000000..e33edde4 --- /dev/null +++ b/db/migrate/20211115131533_update_foreign_key_between_survey_item_response_and_school.rb @@ -0,0 +1,8 @@ +class UpdateForeignKeyBetweenSurveyItemResponseAndSchool < ActiveRecord::Migration[6.1] + def change + ActiveRecord::Base.connection.execute("DELETE FROM survey_item_responses") + + remove_foreign_key :survey_item_responses, :legacy_schools, column: :school_id + add_foreign_key :survey_item_responses, :schools + end +end diff --git a/db/migrate/20211116151445_rename_sqm_categories_to_categories.rb b/db/migrate/20211116151445_rename_sqm_categories_to_categories.rb new file mode 100644 index 00000000..4e3be1a3 --- /dev/null +++ b/db/migrate/20211116151445_rename_sqm_categories_to_categories.rb @@ -0,0 +1,6 @@ +class RenameSqmCategoriesToCategories < ActiveRecord::Migration[6.1] + def change + rename_table :sqm_categories, :categories + rename_column :subcategories, :sqm_category_id, :category_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 587a57a3..ae2cf51f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_04_181819) do +ActiveRecord::Schema.define(version: 2021_11_16_151445) do # These are extensions that must be enabled in order to support this database + enable_extension "pg_stat_statements" enable_extension "plpgsql" create_table "academic_years", id: :serial, force: :cascade do |t| @@ -28,7 +29,26 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.datetime "updated_at", precision: 6, null: false end - create_table "attempts", id: :serial, force: :cascade do |t| + create_table "categories", id: :serial, force: :cascade do |t| + t.string "name" + t.text "description" + t.string "slug" + t.integer "sort_index" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.string "category_id", null: false + t.index ["slug"], name: "index_categories_on_slug", unique: true + end + + create_table "districts", force: :cascade do |t| + t.string "name" + t.string "slug" + t.integer "qualtrics_code" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + + create_table "legacy_attempts", id: :serial, force: :cascade do |t| t.integer "recipient_id" t.integer "schedule_id" t.integer "recipient_schedule_id" @@ -43,10 +63,10 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.text "twilio_details" t.string "twilio_sid" t.integer "student_id" - t.index ["twilio_sid"], name: "index_attempts_on_twilio_sid" + t.index ["twilio_sid"], name: "index_legacy_attempts_on_twilio_sid" end - create_table "categories", id: :serial, force: :cascade do |t| + create_table "legacy_categories", id: :serial, force: :cascade do |t| t.string "name" t.string "blurb" t.text "description" @@ -58,35 +78,20 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.float "benchmark" t.string "benchmark_description" t.string "zones" - t.index ["slug"], name: "index_categories_on_slug", unique: true + t.index ["slug"], name: "index_legacy_categories_on_slug", unique: true end - create_table "districts", id: :serial, force: :cascade do |t| + create_table "legacy_districts", id: :serial, force: :cascade do |t| t.string "name" t.integer "state_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "slug" t.integer "qualtrics_code" - t.index ["slug"], name: "index_districts_on_slug", unique: true - end - - create_table "measures", id: :serial, force: :cascade do |t| - t.string "measure_id", null: false - t.string "name" - t.float "watch_low_benchmark" - t.float "growth_low_benchmark" - t.float "approval_low_benchmark" - t.float "ideal_low_benchmark" - t.integer "subcategory_id", null: false - t.text "description" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["measure_id"], name: "index_measures_on_measure_id" - t.index ["subcategory_id"], name: "index_measures_on_subcategory_id" + t.index ["slug"], name: "index_legacy_districts_on_slug", unique: true end - create_table "question_lists", id: :serial, force: :cascade do |t| + create_table "legacy_question_lists", id: :serial, force: :cascade do |t| t.string "name" t.text "description" t.text "question_ids" @@ -94,7 +99,7 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.datetime "updated_at", null: false end - create_table "questions", id: :serial, force: :cascade do |t| + create_table "legacy_questions", id: :serial, force: :cascade do |t| t.string "text" t.string "option1" t.string "option2" @@ -110,17 +115,17 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.string "external_id" end - create_table "recipient_lists", id: :serial, force: :cascade do |t| + create_table "legacy_recipient_lists", id: :serial, force: :cascade do |t| t.integer "school_id" t.string "name" t.text "description" t.text "recipient_ids" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index ["school_id"], name: "index_recipient_lists_on_school_id" + t.index ["school_id"], name: "index_legacy_recipient_lists_on_school_id" end - create_table "recipient_schedules", id: :serial, force: :cascade do |t| + create_table "legacy_recipient_schedules", id: :serial, force: :cascade do |t| t.integer "recipient_id" t.integer "schedule_id" t.text "upcoming_question_ids" @@ -132,7 +137,7 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.string "queued_question_ids" end - create_table "recipients", id: :serial, force: :cascade do |t| + create_table "legacy_recipients", id: :serial, force: :cascade do |t| t.string "name" t.string "phone" t.date "birth_date" @@ -150,11 +155,11 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.integer "attempts_count", default: 0 t.integer "responses_count", default: 0 t.string "teacher" - t.index ["phone"], name: "index_recipients_on_phone" - t.index ["slug"], name: "index_recipients_on_slug", unique: true + t.index ["phone"], name: "index_legacy_recipients_on_phone" + t.index ["slug"], name: "index_legacy_recipients_on_slug", unique: true end - create_table "schedules", id: :serial, force: :cascade do |t| + create_table "legacy_schedules", id: :serial, force: :cascade do |t| t.integer "school_id" t.string "name" t.text "description" @@ -168,10 +173,10 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "time", default: 960 - t.index ["school_id"], name: "index_schedules_on_school_id" + t.index ["school_id"], name: "index_legacy_schedules_on_school_id" end - create_table "school_categories", id: :serial, force: :cascade do |t| + create_table "legacy_school_categories", id: :serial, force: :cascade do |t| t.integer "school_id" t.integer "category_id" t.integer "attempt_count", default: 0 @@ -184,11 +189,11 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.string "year" t.integer "valid_child_count" t.integer "response_rate" - t.index ["category_id"], name: "index_school_categories_on_category_id" - t.index ["school_id"], name: "index_school_categories_on_school_id" + t.index ["category_id"], name: "index_legacy_school_categories_on_category_id" + t.index ["school_id"], name: "index_legacy_school_categories_on_school_id" end - create_table "school_questions", id: :serial, force: :cascade do |t| + create_table "legacy_school_questions", id: :serial, force: :cascade do |t| t.integer "school_id" t.integer "question_id" t.integer "school_category_id" @@ -201,7 +206,7 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.integer "response_total" end - create_table "schools", id: :serial, force: :cascade do |t| + create_table "legacy_schools", id: :serial, force: :cascade do |t| t.string "name" t.integer "district_id" t.datetime "created_at", null: false @@ -211,21 +216,10 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.integer "student_count" t.integer "teacher_count" t.integer "qualtrics_code" - t.index ["slug"], name: "index_schools_on_slug", unique: true - end - - create_table "sqm_categories", id: :serial, force: :cascade do |t| - t.string "name" - t.text "description" - t.string "slug" - t.integer "sort_index" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.string "category_id", null: false - t.index ["slug"], name: "index_sqm_categories_on_slug", unique: true + t.index ["slug"], name: "index_legacy_schools_on_slug", unique: true end - create_table "students", id: :serial, force: :cascade do |t| + create_table "legacy_students", id: :serial, force: :cascade do |t| t.string "name" t.string "teacher" t.date "birthdate" @@ -237,9 +231,59 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.datetime "updated_at", null: false end + create_table "legacy_user_schools", id: :serial, force: :cascade do |t| + t.integer "user_id" + t.integer "school_id" + t.integer "district_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "legacy_users", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_legacy_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_legacy_users_on_reset_password_token", unique: true + end + + create_table "measures", id: :serial, force: :cascade do |t| + t.string "measure_id", null: false + t.string "name" + t.float "watch_low_benchmark" + t.float "growth_low_benchmark" + t.float "approval_low_benchmark" + t.float "ideal_low_benchmark" + t.integer "subcategory_id", null: false + t.text "description" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["measure_id"], name: "index_measures_on_measure_id" + t.index ["subcategory_id"], name: "index_measures_on_subcategory_id" + end + + create_table "schools", force: :cascade do |t| + t.string "name" + t.integer "district_id" + t.text "description" + t.string "slug" + t.integer "qualtrics_code" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "subcategories", id: :serial, force: :cascade do |t| t.string "name" - t.integer "sqm_category_id" + t.integer "category_id" t.text "description" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false @@ -270,38 +314,13 @@ ActiveRecord::Schema.define(version: 2021_11_04_181819) do t.index ["survey_item_id"], name: "index_survey_items_on_survey_item_id" end - create_table "user_schools", id: :serial, force: :cascade do |t| - t.integer "user_id" - t.integer "school_id" - t.integer "district_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "users", id: :serial, force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - add_foreign_key "admin_data_items", "measures" + add_foreign_key "legacy_recipient_lists", "legacy_schools", column: "school_id" + add_foreign_key "legacy_schedules", "legacy_schools", column: "school_id" + add_foreign_key "legacy_school_categories", "legacy_categories", column: "category_id" + add_foreign_key "legacy_school_categories", "legacy_schools", column: "school_id" add_foreign_key "measures", "subcategories" - add_foreign_key "recipient_lists", "schools" - add_foreign_key "schedules", "schools" - add_foreign_key "school_categories", "categories" - add_foreign_key "school_categories", "schools" - add_foreign_key "subcategories", "sqm_categories" + add_foreign_key "subcategories", "categories" add_foreign_key "survey_item_responses", "academic_years" add_foreign_key "survey_item_responses", "schools" add_foreign_key "survey_item_responses", "survey_items" diff --git a/lib/tasks/survey.rake b/lib/tasks/survey.rake index 48bc609b..f8bbf372 100644 --- a/lib/tasks/survey.rake +++ b/lib/tasks/survey.rake @@ -2,7 +2,7 @@ namespace :survey do desc 'Text all recipients ready for an attempt' task :attempt_questions => :environment do - Schedule.active.each do |schedule| + Legacy::Schedule.active.each do |schedule| schedule.recipient_schedules.ready.each do |recipient_schedule| recipient_schedule.attempt_question end diff --git a/schooldashfeaturespec.png b/schooldashfeaturespec.png deleted file mode 100644 index 06d8af1a..00000000 Binary files a/schooldashfeaturespec.png and /dev/null differ diff --git a/spec/controllers/attempts_controller_spec.rb b/spec/controllers/attempts_controller_spec.rb deleted file mode 100644 index 9925579c..00000000 --- a/spec/controllers/attempts_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index 72f9bfa7..bdfaaa3f 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -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'} - } - - let(:invalid_attributes) { - {name: ''} +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(: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 - 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 + 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 #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 diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb index cf615823..1e40f1b8 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboard_controller_spec.rb @@ -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 diff --git a/spec/controllers/districts_controller_spec.rb b/spec/controllers/districts_controller_spec.rb deleted file mode 100644 index 55df5344..00000000 --- a/spec/controllers/districts_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index d9ec07f8..6912521a 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/attempts_controller_spec.rb b/spec/controllers/legacy/attempts_controller_spec.rb new file mode 100644 index 00000000..499d6d24 --- /dev/null +++ b/spec/controllers/legacy/attempts_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/categories_controller_spec.rb b/spec/controllers/legacy/categories_controller_spec.rb new file mode 100644 index 00000000..ec595884 --- /dev/null +++ b/spec/controllers/legacy/categories_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/districts_controller_spec.rb b/spec/controllers/legacy/districts_controller_spec.rb new file mode 100644 index 00000000..b9f8fe1a --- /dev/null +++ b/spec/controllers/legacy/districts_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/question_lists_controller_spec.rb b/spec/controllers/legacy/question_lists_controller_spec.rb new file mode 100644 index 00000000..d8a8cc45 --- /dev/null +++ b/spec/controllers/legacy/question_lists_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/questions_controller_spec.rb b/spec/controllers/legacy/questions_controller_spec.rb new file mode 100644 index 00000000..19910d67 --- /dev/null +++ b/spec/controllers/legacy/questions_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/recipient_lists_controller_spec.rb b/spec/controllers/legacy/recipient_lists_controller_spec.rb new file mode 100644 index 00000000..3b163934 --- /dev/null +++ b/spec/controllers/legacy/recipient_lists_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/recipients_controller_spec.rb b/spec/controllers/legacy/recipients_controller_spec.rb new file mode 100644 index 00000000..05bcb086 --- /dev/null +++ b/spec/controllers/legacy/recipients_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/schedules_controller_spec.rb b/spec/controllers/legacy/schedules_controller_spec.rb new file mode 100644 index 00000000..0df1892e --- /dev/null +++ b/spec/controllers/legacy/schedules_controller_spec.rb @@ -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 diff --git a/spec/controllers/schools_controller_spec.rb b/spec/controllers/legacy/schools_controller_spec.rb similarity index 89% rename from spec/controllers/schools_controller_spec.rb rename to spec/controllers/legacy/schools_controller_spec.rb index ed753f39..38278ae9 100644 --- a/spec/controllers/schools_controller_spec.rb +++ b/spec/controllers/legacy/schools_controller_spec.rb @@ -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 diff --git a/spec/controllers/legacy/welcome_controller_spec.rb b/spec/controllers/legacy/welcome_controller_spec.rb new file mode 100644 index 00000000..e0a17cd7 --- /dev/null +++ b/spec/controllers/legacy/welcome_controller_spec.rb @@ -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 diff --git a/spec/controllers/question_lists_controller_spec.rb b/spec/controllers/question_lists_controller_spec.rb deleted file mode 100644 index 9cc18c0d..00000000 --- a/spec/controllers/question_lists_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/questions_controller_spec.rb b/spec/controllers/questions_controller_spec.rb deleted file mode 100644 index 41b26851..00000000 --- a/spec/controllers/questions_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/recipient_lists_controller_spec.rb b/spec/controllers/recipient_lists_controller_spec.rb deleted file mode 100644 index 35aedd7b..00000000 --- a/spec/controllers/recipient_lists_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/recipients_controller_spec.rb b/spec/controllers/recipients_controller_spec.rb deleted file mode 100644 index 2cef9e72..00000000 --- a/spec/controllers/recipients_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/schedules_controller_spec.rb b/spec/controllers/schedules_controller_spec.rb deleted file mode 100644 index f5c656c0..00000000 --- a/spec/controllers/schedules_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/sqm_categories_controller_spec.rb b/spec/controllers/sqm_categories_controller_spec.rb deleted file mode 100644 index 9098771e..00000000 --- a/spec/controllers/sqm_categories_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/controllers/welcome_controller_spec.rb b/spec/controllers/welcome_controller_spec.rb deleted file mode 100644 index 24f2b876..00000000 --- a/spec/controllers/welcome_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index d79e455b..6ff2dc34 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -16,7 +16,7 @@ FactoryBot.define do initialize_with { AcademicYear.find_or_initialize_by(range: range) } end - factory :sqm_category do + factory :category, class: 'Category' do name { "A #{rand} category" } category_id { rand.to_s } description { "A description of a category" } @@ -28,7 +28,7 @@ FactoryBot.define do name { "A subcategory" } subcategory_id { rand.to_s } description { "A description of a subcategory" } - sqm_category + category factory :subcategory_with_measures do transient do diff --git a/spec/lib/seeder_spec.rb b/spec/lib/seeder_spec.rb index 4fbe9afd..27fc1069 100644 --- a/spec/lib/seeder_spec.rb +++ b/spec/lib/seeder_spec.rb @@ -87,8 +87,8 @@ describe Seeder do context 'the sqm framework' do before do - school_culture_category = create(:sqm_category, category_id: '2', sort_index: -1) - safety_subcategory = create(:subcategory, subcategory_id: '2A', sqm_category: school_culture_category) + school_culture_category = create(:category, category_id: '2', sort_index: -1) + safety_subcategory = create(:subcategory, subcategory_id: '2A', category: school_culture_category) student_physical_safety_measure = create(:measure, measure_id: '2A-i', subcategory: safety_subcategory) create(:survey_item, survey_item_id: 's-phys-q1', measure: student_physical_safety_measure) create(:admin_data_item, admin_data_item_id: 'a-phys-i1', measure: student_physical_safety_measure) @@ -97,7 +97,7 @@ describe Seeder do it 'creates new objects as necessary' do expect { seeder.seed_sqm_framework sample_sqm_framework_csv - }.to change { SqmCategory.count }.by(4) + }.to change { Category.count }.by(4) .and change { Subcategory.count }.by(15) .and change { Measure.count }.by(31) .and change { SurveyItem.count }.by(136) @@ -111,15 +111,15 @@ describe Seeder do it 'updates category data' do seeder.seed_sqm_framework sample_sqm_framework_csv - teachers_leadership = SqmCategory.find_by_name 'Teachers & Leadership' + teachers_leadership = Category.find_by_name 'Teachers & Leadership' expect(teachers_leadership.slug).to eq 'teachers-and-leadership' expect(teachers_leadership.description).to eq "This is a category description." end it 'updates category sort index to match a predefined order' do - teachers_leadership = SqmCategory.find_by_name 'Teachers & Leadership' - school_culture = SqmCategory.find_by_name 'School Culture' + teachers_leadership = Category.find_by_name 'Teachers & Leadership' + school_culture = Category.find_by_name 'School Culture' expect(teachers_leadership.sort_index).to eq 0 expect(school_culture.sort_index).to eq 1 diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 2aa11122..70fad0d0 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -1,358 +1,359 @@ require 'rails_helper' -describe "survey:attempt_questions" do - include_context "rake" +module Legacy + describe "survey:attempt_questions" do + include_context "rake" - it 'should have environment as a prerequisite' do - expect(subject.prerequisites).to include("environment") - end - - describe "basic flow" do - let(:now) { - n = DateTime.now - n += 1.day until n.on_weekday? - return n - } - - let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) } - let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) } - let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) } - - it "finds all active schedules" do - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) - Timecop.freeze(date) - - expect(ready_recipient_schedule).to receive(:attempt_question) - expect(active_schedule).to receive(:recipient_schedules) - expect(Schedule).to receive(:active).and_return([active_schedule]) - subject.invoke - end - - it "works only on weekdays" do - now = DateTime.now - now += 1.day until now.on_weekend? - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) - Timecop.freeze(date) - - expect(ready_recipient_schedule).to_not receive(:attempt_question) - subject.invoke + it 'should have environment as a prerequisite' do + expect(subject.prerequisites).to include("environment") end - end - xdescribe "complex flow" do - let(:now) { - n = DateTime.now - n += 1.day until n.on_weekday? - return n - } + describe "basic flow" do + let(:now) { + n = DateTime.now + n += 1.day until n.on_weekday? + return n + } - let!(:school) { School.create!(name: 'School') } + let(:ready_recipient_schedule) { double('ready recipient schedule', attempt_question: nil) } + let(:recipient_schedules) { double("recipient schedules", ready: [ready_recipient_schedule]) } + let(:active_schedule) { double("active schedule", recipient_schedules: recipient_schedules) } - let!(:recipients) { create_recipients(school, 3) } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) - end - - let!(:category) { Category.create(name: 'Category') } - let!(:questions) { create_questions(3, category) } - let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) - end + it "finds all active schedules" do + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + Timecop.freeze(date) - let!(:schedule) do - Schedule.create!( - name: 'Parent Schedule', - recipient_list_id: recipient_list.id, - question_list: question_list, - frequency_hours: 24 * 7, - start_date: Time.new, - end_date: 1.year.from_now, - time: 1200 - ) - end + expect(ready_recipient_schedule).to receive(:attempt_question) + expect(active_schedule).to receive(:recipient_schedules) + expect(Schedule).to receive(:active).and_return([active_schedule]) + subject.invoke + end - describe 'First attempt not at specified time' do - before :each do - now = DateTime.new + it "works only on weekdays" do + now = DateTime.now now += 1.day until now.on_weekend? - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z")) - Timecop.freeze(date) { subject.invoke } - end + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + Timecop.freeze(date) - it 'should not create any attempts' do - expect(Attempt.count).to eq(0) + expect(ready_recipient_schedule).to_not receive(:attempt_question) + subject.invoke end end + xdescribe "complex flow" do + let(:now) { + n = DateTime.now + n += 1.day until n.on_weekday? + return n + } - describe 'First attempt at specified time' do - before :each do - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) - Timecop.freeze(date) { subject.invoke } + 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 - it 'should create the first attempt for each recipient' do - recipients.each do |recipient| - recipient.reload - expect(recipient.attempts.count).to eq(1) - attempt = recipient.attempts.first - expect(attempt.sent_at).to be_present - expect(attempt.answer_index).to be_nil - end + let!(:category) { Category.create(name: 'Category') } + let!(:questions) { create_questions(3, category) } + let!(:question_list) do + QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) end - end - describe 'Second Attempts' do - before :each do - recipients.each do |recipient| - recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first - recipient_schedule.attempt_question - end + let!(:schedule) do + Schedule.create!( + name: 'Parent Schedule', + recipient_list_id: recipient_list.id, + question_list: question_list, + frequency_hours: 24 * 7, + start_date: Time.new, + end_date: 1.year.from_now, + time: 1200 + ) end - describe 'Immediate' do + describe 'First attempt not at specified time' do before :each do - subject.invoke + now = DateTime.new + now += 1.day until now.on_weekend? + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT19:00:00%z")) + Timecop.freeze(date) { subject.invoke } end - it 'should do nothing' do - recipients.each do |recipient| - recipient.reload - expect(recipient.attempts.count).to eq(1) - end + it 'should not create any attempts' do + expect(Attempt.count).to eq(0) end end - describe 'A Week Later' do + describe 'First attempt at specified time' do before :each do - recipients[1].attempts.first.update( - answer_index: 4, - responded_at: Time.new - ) - Timecop.freeze(now + 7) { subject.invoke } + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + Timecop.freeze(date) { subject.invoke } end - it 'should resend the first question if unanswered by a recipient' do - [recipients[0], recipients[2]].each do |recipient| + it 'should create the first attempt for each recipient' do + recipients.each do |recipient| recipient.reload expect(recipient.attempts.count).to eq(1) - attempt = recipient.attempts.last - expect(attempt.sent_at).to be > 1.day.ago + attempt = recipient.attempts.first + expect(attempt.sent_at).to be_present expect(attempt.answer_index).to be_nil end end - - it 'should create the second attempt with a new question for each recipient who has answered the first question' do - recipient = recipients[1] - recipient.reload - expect(recipient.attempts.count).to eq(2) - attempt = recipient.attempts.last - expect(attempt.sent_at).to be_present - expect(attempt.answer_index).to be_nil - - first_attempt = recipient.attempts.first - expect(first_attempt.question).to_not eq(attempt.question) - end end - describe 'And Then A Recipient Answers The First Attempt' do + describe 'Second Attempts' do before :each do - recipients[1].attempts.first.save_response(answer_index: 4) - - Timecop.freeze(now + 7) recipients.each do |recipient| recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first recipient_schedule.attempt_question end + end - @existing_message_count = FakeSMS.messages.length + describe 'Immediate' do + before :each do + subject.invoke + end - Timecop.freeze(now + 8) - recipients[2].attempts.first.save_response(answer_index: 3) - subject.invoke + it 'should do nothing' do + recipients.each do |recipient| + recipient.reload + expect(recipient.attempts.count).to eq(1) + end + end end - it 'should create the second attempt with a new question for each recipient who just answered the first question' do - recipient = recipients[2] - recipient.reload - expect(recipient.attempts.count).to eq(2) - attempt = recipient.attempts.last - expect(attempt.sent_at).to be_present - expect(attempt.answer_index).to be_nil + describe 'A Week Later' do + before :each do + recipients[1].attempts.first.update( + answer_index: 4, + responded_at: Time.new + ) + Timecop.freeze(now + 7) { subject.invoke } + end - first_attempt = recipient.attempts.first - expect(first_attempt.question).to_not eq(attempt.question) - end + it 'should resend the first question if unanswered by a recipient' do + [recipients[0], recipients[2]].each do |recipient| + recipient.reload + expect(recipient.attempts.count).to eq(1) + attempt = recipient.attempts.last + expect(attempt.sent_at).to be > 1.day.ago + expect(attempt.answer_index).to be_nil + end + end + + it 'should create the second attempt with a new question for each recipient who has answered the first question' do + recipient = recipients[1] + recipient.reload + expect(recipient.attempts.count).to eq(2) + attempt = recipient.attempts.last + expect(attempt.sent_at).to be_present + expect(attempt.answer_index).to be_nil - it 'should not send anything to anyone else' do - expect(FakeSMS.messages.length).to eq(@existing_message_count + 2) - expect(recipients[0].attempts.count).to eq(1) - expect(recipients[1].attempts.count).to eq(2) + first_attempt = recipient.attempts.first + expect(first_attempt.question).to_not eq(attempt.question) + end end - end - end - describe 'Multiple Students In A Family' do + describe 'And Then A Recipient Answers The First Attempt' do + before :each do + recipients[1].attempts.first.save_response(answer_index: 4) - before :each do - 3.times do |i| - recipients[1].students.create(name: "Student#{i}") - end - end + Timecop.freeze(now + 7) + recipients.each do |recipient| + recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first + recipient_schedule.attempt_question + end - let(:students_recipient) { recipients[1] } - let(:students_recipient_schedule) { - students_recipient.recipient_schedules.for_schedule(schedule).first - } + @existing_message_count = FakeSMS.messages.length - describe 'With A FOR_CHILD Question Is Asked' do - let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + Timecop.freeze(now + 8) + recipients[2].attempts.first.save_response(answer_index: 3) + subject.invoke + end - before :each do - questions.first.update(for_recipient_students: true) - Timecop.freeze(date) { subject.invoke } - end + it 'should create the second attempt with a new question for each recipient who just answered the first question' do + recipient = recipients[2] + recipient.reload + expect(recipient.attempts.count).to eq(2) + attempt = recipient.attempts.last + expect(attempt.sent_at).to be_present + expect(attempt.answer_index).to be_nil - it 'should create one attempt per recipient regardless of students' do - expect(FakeSMS.messages.length).to eq(6) - recipients.each do |recipient| - expect(recipient.attempts.count).to eq(1) + first_attempt = recipient.attempts.first + expect(first_attempt.question).to_not eq(attempt.question) end - end - it 'should store queued questions when an attempt is made on first student' do - expect(students_recipient_schedule.queued_question_ids).to be_present - queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/) - expect(queued_question_ids.length).to eq(1) - expect(queued_question_ids.first).to eq("#{questions[0].id}") + it 'should not send anything to anyone else' do + expect(FakeSMS.messages.length).to eq(@existing_message_count + 2) + expect(recipients[0].attempts.count).to eq(1) + expect(recipients[1].attempts.count).to eq(2) + end end + end + + describe 'Multiple Students In A Family' do - it 'should set the next_attempt_at to now when attempt is made on first student' do - students_recipient.attempts.last.save_response(answer_index: 3) - expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) + before :each do + 3.times do |i| + recipients[1].students.create(name: "Student#{i}") + end end - it 'should set the next_attempt_at in the future when an attempts are made on each student' do - students_recipient.attempts.last.save_response(answer_index: 3) - expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) - expect(students_recipient_schedule.reload.queued_question_ids).to be_present + let(:students_recipient) { recipients[1] } + let(:students_recipient_schedule) { + students_recipient.recipient_schedules.for_schedule(schedule).first + } - attempt = students_recipient.attempts.last - expect(attempt.student).to eq(students_recipient.students[1]) + describe 'With A FOR_CHILD Question Is Asked' do + let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } - Timecop.freeze(date + 1.day) - attempt.save_response(answer_index: 4) - expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day) + before :each do + questions.first.update(for_recipient_students: true) + Timecop.freeze(date) { subject.invoke } + end - expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) - expect(students_recipient_schedule.reload.queued_question_ids).to be_nil - expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours)) + it 'should create one attempt per recipient regardless of students' do + expect(FakeSMS.messages.length).to eq(6) + recipients.each do |recipient| + expect(recipient.attempts.count).to eq(1) + end + end - attempt = students_recipient.attempts.last - expect(attempt.student).to eq(students_recipient.students[2]) + it 'should store queued questions when an attempt is made on first student' do + expect(students_recipient_schedule.queued_question_ids).to be_present + queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/) + expect(queued_question_ids.length).to eq(1) + expect(queued_question_ids.first).to eq("#{questions[0].id}") + end - Timecop.freeze(date + 2.days) - attempt.save_response(answer_index: 2) - expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days) - end + it 'should set the next_attempt_at to now when attempt is made on first student' do + students_recipient.attempts.last.save_response(answer_index: 3) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) + end - it 'should mention the students name in the text' do - expect(FakeSMS.messages[2].body).to match(/\(for Student0\)/) - end + it 'should set the next_attempt_at in the future when an attempts are made on each student' do + students_recipient.attempts.last.save_response(answer_index: 3) + expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1) + expect(students_recipient_schedule.reload.queued_question_ids).to be_present - it 'should not mention the students name in the text if the recipient has no student specified' do - expect(FakeSMS.messages[0].body).to_not match(/\(for .*\)/) - end + attempt = students_recipient.attempts.last + expect(attempt.student).to eq(students_recipient.students[1]) - it 'resends the question about the same student if not responded to' do - message_count = FakeSMS.messages.length - expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(0) - expect(FakeSMS.messages.length).to eq(message_count + 2) - expect(FakeSMS.messages[message_count].body).to match(questions.first.text) - expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/) - end + Timecop.freeze(date + 1.day) + attempt.save_response(answer_index: 4) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day) - it 'doesnt store any queued_question_ids when no students are present' do - recipient_schedule = recipients[0].recipient_schedules.for_schedule(schedule).first - expect(recipient_schedule.queued_question_ids).to be_nil - end + expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(1) + expect(students_recipient_schedule.reload.queued_question_ids).to be_nil + expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours)) - end + attempt = students_recipient.attempts.last + expect(attempt.student).to eq(students_recipient.students[2]) - describe 'With A General Question Is Asked' do - before :each do - subject.invoke - end + Timecop.freeze(date + 2.days) + attempt.save_response(answer_index: 2) + expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days) + end - it 'should not queue up an questions regardless of how many students there are' do - expect(students_recipient_schedule.queued_question_ids).to be_nil - end + it 'should mention the students name in the text' do + expect(FakeSMS.messages[2].body).to match(/\(for Student0\)/) + end - it 'should not mention the students name in the text' do - FakeSMS.messages.each do |message| - expect(message.body).to_not match(/\(for .*\)/) + it 'should not mention the students name in the text if the recipient has no student specified' do + expect(FakeSMS.messages[0].body).to_not match(/\(for .*\)/) end + + it 'resends the question about the same student if not responded to' do + message_count = FakeSMS.messages.length + expect { students_recipient_schedule.attempt_question }.to change { students_recipient.attempts.count }.by(0) + expect(FakeSMS.messages.length).to eq(message_count + 2) + expect(FakeSMS.messages[message_count].body).to match(questions.first.text) + expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/) + end + + it 'doesnt store any queued_question_ids when no students are present' do + recipient_schedule = recipients[0].recipient_schedules.for_schedule(schedule).first + expect(recipient_schedule.queued_question_ids).to be_nil + end + end - end - end + describe 'With A General Question Is Asked' do + before :each do + subject.invoke + end - describe 'One Student In A Family' do + it 'should not queue up an questions regardless of how many students there are' do + expect(students_recipient_schedule.queued_question_ids).to be_nil + end - before :each do - recipients[1].students.create(name: "Only Student") - end + it 'should not mention the students name in the text' do + FakeSMS.messages.each do |message| + expect(message.body).to_not match(/\(for .*\)/) + end + end - let(:students_recipient) { recipients[1] } - let(:students_recipient_schedule) { - students_recipient.recipient_schedules.for_schedule(schedule).first - } + end + end - describe 'With A FOR_CHILD Question Is Asked' do - let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + describe 'One Student In A Family' do before :each do - questions.first.update(for_recipient_students: true) - Timecop.freeze(date) { subject.invoke } + recipients[1].students.create(name: "Only Student") end - it 'should create one attempt per recipient regardless of students' do - expect(FakeSMS.messages.length).to eq(6) - recipients.each do |recipient| - expect(recipient.attempts.count).to eq(1) + let(:students_recipient) { recipients[1] } + let(:students_recipient_schedule) { + students_recipient.recipient_schedules.for_schedule(schedule).first + } + + describe 'With A FOR_CHILD Question Is Asked' do + let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + + before :each do + questions.first.update(for_recipient_students: true) + Timecop.freeze(date) { subject.invoke } + end + + it 'should create one attempt per recipient regardless of students' do + expect(FakeSMS.messages.length).to eq(6) + recipients.each do |recipient| + expect(recipient.attempts.count).to eq(1) + end end - end - it 'doesnt store any queued_question_ids' do - expect(students_recipient_schedule.queued_question_ids).to be_nil + it 'doesnt store any queued_question_ids' do + expect(students_recipient_schedule.queued_question_ids).to be_nil + end end end - end - describe 'Opted Out Recipient' do + describe 'Opted Out Recipient' do - before :each do - recipients[1].update(opted_out: true) + before :each do + recipients[1].update(opted_out: true) - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) - Timecop.freeze(date) { subject.invoke } - end + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + Timecop.freeze(date) { subject.invoke } + end - it 'should create the first attempt for each recipient' do - recipients.each_with_index do |recipient, index| - recipient.reload - if index == 1 - expect(recipient.attempts.count).to eq(0) - expect(recipient.attempts.first).to be_nil - else - expect(recipient.attempts.count).to eq(1) - attempt = recipient.attempts.first - expect(attempt.sent_at).to be_present - expect(attempt.answer_index).to be_nil + it 'should create the first attempt for each recipient' do + recipients.each_with_index do |recipient, index| + recipient.reload + if index == 1 + expect(recipient.attempts.count).to eq(0) + expect(recipient.attempts.first).to be_nil + else + expect(recipient.attempts.count).to eq(1) + attempt = recipient.attempts.first + expect(attempt.sent_at).to be_present + expect(attempt.answer_index).to be_nil + end end end end - end + end end end diff --git a/spec/models/attempt_spec.rb b/spec/models/attempt_spec.rb deleted file mode 100644 index 55f52734..00000000 --- a/spec/models/attempt_spec.rb +++ /dev/null @@ -1,112 +0,0 @@ -require 'rails_helper' - -RSpec.describe Attempt, type: :model do - - let!(:school) { School.create!(name: 'School') } - - let!(:recipient) { school.recipients.create(name: 'name', phone: "#{1}" * 9) } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}") - end - - let!(:category) { Category.create(name: 'Category') } - let!(:question) { create_questions(1, category).first } - let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: "#{question.id}") - end - - let(:schedule) { Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) } - - let(:recipient_schedule) do - RecipientSchedule.create!( - recipient: recipient, - schedule: schedule, - upcoming_question_ids: "#{question.id},3", - attempted_question_ids: '2', - last_attempt_at: 2.weeks.ago, - next_attempt_at: Time.new - ) - end - - let!(:attempt) do - recipient.attempts.create( - schedule: schedule, - recipient_schedule: recipient_schedule, - question: question - ) - end - - describe 'after_save' do - let!(:school_categories) { SchoolCategory.for(attempt.recipient.school, attempt.question.category) } - - xit 'creates the associated school_category' do - expect(school_categories.count).to eq(1) - expect(school_categories.first.attempt_count).to eq(1) - expect(school_categories.first.response_count).to eq(0) - expect(school_categories.first.answer_index_total).to eq(0) - end - - describe 'after_update' do - before :each do - attempt.update(answer_index: 4) - end - - xit 'updates associated school_categories' do - expect(school_categories.count).to eq(1) - expect(school_categories.first.attempt_count).to eq(1) - expect(school_categories.first.response_count).to eq(1) - expect(school_categories.first.answer_index_total).to eq(4) - end - end - end - - describe 'counters' do - it 'are updated when an attempt is created' do - expect(recipient.attempts_count).to eq(1) - expect(recipient.responses_count).to eq(0) - end - - it 'are updated when an attempt is destroyed' do - attempt.destroy - expect(recipient.attempts_count).to eq(0) - expect(recipient.responses_count).to eq(0) - end - - it 'are updated when an attempt is responded to' do - attempt.update(answer_index: 2) - expect(recipient.attempts_count).to eq(1) - expect(recipient.responses_count).to eq(1) - end - - it 'are updated when an attempt is responded to with an open-ended response' do - attempt.update(open_response_id: 1) - expect(recipient.attempts_count).to eq(1) - expect(recipient.responses_count).to eq(1) - end - end - - describe 'send_message' do - before :each do - Timecop.freeze - attempt.send_message - end - - it 'should contact the Twilio API' do - expect(FakeSMS.messages.length).to eq(2) - - expect(FakeSMS.messages.first.to).to eq('111111111') - expect(FakeSMS.messages.first.body).to eq("Question 0:1") - - expect(FakeSMS.messages.last.to).to eq('111111111') - expect(FakeSMS.messages.last.body).to eq("Option 0:1 A: Reply 1\nOption 0:1 B: 2\nOption 0:1 C: 3\nOption 0:1 D: 4\nOption 0:1 E: 5") - end - - it 'should update sent_at' do - expect(attempt.sent_at).to eq(Time.new) - end - - it 'should update the recipient phone number' do - expect(attempt.recipient.reload.phone).to eq('+1111111111') - end - end -end diff --git a/spec/models/district_spec.rb b/spec/models/district_spec.rb deleted file mode 100644 index fe6e5b49..00000000 --- a/spec/models/district_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rails_helper' - -RSpec.describe District, type: :model do - let(:district1) { District.create(name: 'District one', state_id: 32) } - let(:district2) { District.new(name: 'District two', state_id: 32) } - - context "when saving or creating" do - it 'should return a slug' do - expect(district1.slug).to eq 'district-one' - - district2.save - expect(district2.slug).to eq 'district-two' - - first_district = District.find_by_slug('district-one') - expect(first_district.slug).to eq 'district-one' - end - end -end - diff --git a/spec/models/legacy/attempt_spec.rb b/spec/models/legacy/attempt_spec.rb new file mode 100644 index 00000000..edfa1c1c --- /dev/null +++ b/spec/models/legacy/attempt_spec.rb @@ -0,0 +1,114 @@ +require 'rails_helper' + +module Legacy + describe Attempt, type: :model do + + let!(:school) { School.create!(name: 'School') } + + let!(:recipient) { school.recipients.create(name: 'name', phone: "#{1}" * 9) } + let!(:recipient_list) do + school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}") + end + + let!(:category) { Category.create(name: 'Category') } + let!(:question) { create_questions(1, category).first } + let!(:question_list) do + QuestionList.create!(name: 'Parent Questions', question_ids: "#{question.id}") + end + + let(:schedule) { Schedule.create!(name: 'Parent Schedule', recipient_list_id: recipient_list.id, question_list: question_list) } + + let(:recipient_schedule) do + RecipientSchedule.create!( + recipient: recipient, + schedule: schedule, + upcoming_question_ids: "#{question.id},3", + attempted_question_ids: '2', + last_attempt_at: 2.weeks.ago, + next_attempt_at: Time.new + ) + end + + let!(:attempt) do + recipient.attempts.create( + schedule: schedule, + recipient_schedule: recipient_schedule, + question: question + ) + end + + describe 'after_save' do + let!(:school_categories) { SchoolCategory.for(attempt.recipient.school, attempt.question.category) } + + xit 'creates the associated school_category' do + expect(school_categories.count).to eq(1) + expect(school_categories.first.attempt_count).to eq(1) + expect(school_categories.first.response_count).to eq(0) + expect(school_categories.first.answer_index_total).to eq(0) + end + + describe 'after_update' do + before :each do + attempt.update(answer_index: 4) + end + + xit 'updates associated school_categories' do + expect(school_categories.count).to eq(1) + expect(school_categories.first.attempt_count).to eq(1) + expect(school_categories.first.response_count).to eq(1) + expect(school_categories.first.answer_index_total).to eq(4) + end + end + end + + describe 'counters' do + it 'are updated when an attempt is created' do + expect(recipient.attempts_count).to eq(1) + expect(recipient.responses_count).to eq(0) + end + + it 'are updated when an attempt is destroyed' do + attempt.destroy + expect(recipient.attempts_count).to eq(0) + expect(recipient.responses_count).to eq(0) + end + + it 'are updated when an attempt is responded to' do + attempt.update(answer_index: 2) + expect(recipient.attempts_count).to eq(1) + expect(recipient.responses_count).to eq(1) + end + + it 'are updated when an attempt is responded to with an open-ended response' do + attempt.update(open_response_id: 1) + expect(recipient.attempts_count).to eq(1) + expect(recipient.responses_count).to eq(1) + end + end + + describe 'send_message' do + before :each do + Timecop.freeze + attempt.send_message + end + + it 'should contact the Twilio API' do + expect(FakeSMS.messages.length).to eq(2) + + expect(FakeSMS.messages.first.to).to eq('111111111') + expect(FakeSMS.messages.first.body).to eq("Question 0:1") + + expect(FakeSMS.messages.last.to).to eq('111111111') + expect(FakeSMS.messages.last.body).to eq("Option 0:1 A: Reply 1\nOption 0:1 B: 2\nOption 0:1 C: 3\nOption 0:1 D: 4\nOption 0:1 E: 5") + end + + it 'should update sent_at' do + expect(attempt.sent_at).to eq(Time.new) + end + + it 'should update the recipient phone number' do + expect(attempt.recipient.reload.phone).to eq('+1111111111') + end + end + end +end diff --git a/spec/models/legacy/district_spec.rb b/spec/models/legacy/district_spec.rb new file mode 100644 index 00000000..f9d0d2b6 --- /dev/null +++ b/spec/models/legacy/district_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +module Legacy + RSpec.describe District, type: :model do + let(:district1) { District.create(name: 'District one', state_id: 32) } + let(:district2) { District.new(name: 'District two', state_id: 32) } + + context "when saving or creating" do + it 'should return a slug' do + expect(district1.slug).to eq 'district-one' + + district2.save + expect(district2.slug).to eq 'district-two' + + first_district = District.find_by_slug('district-one') + expect(first_district.slug).to eq 'district-one' + end + end + end + +end diff --git a/spec/models/legacy/question_spec.rb b/spec/models/legacy/question_spec.rb new file mode 100644 index 00000000..ddf9130f --- /dev/null +++ b/spec/models/legacy/question_spec.rb @@ -0,0 +1,55 @@ +require 'rails_helper' + +module Legacy + RSpec.describe Question, type: :model do + + let!(:school1) { School.create!(name: 'School 1') } + let!(:school2) { School.create!(name: 'School 2') } + + let!(:school1recipients) { create_recipients(school1, 5) } + let!(:school2recipients) { create_recipients(school2, 4) } + + let!(:category1) { Category.create!(name: 'Resources') } + let!(:category2) { Category.create!(name: 'Category 2') } + + let!(:category1questions) { create_questions(3, category1) } + let!(:category2questions) { create_questions(3, category2) } + let(:question) { category1questions.first } + + let!(:attempt1) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3) } + let!(:attempt2) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2) } + let!(:attempt3) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[2]) } + let!(:attempt4) { Legacy::Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3) } + let!(:attempt5) { Legacy::Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) } + let!(:attempt6) { Legacy::Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) } + let!(:attempt7) { Legacy::Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) } + let!(:attempt8) { Legacy::Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) } + let!(:attempt9) { Legacy::Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) } + + describe 'aggregated_responses_for_school' do + + let(:aggregated_responses) { question.aggregated_responses_for_school(school1) } + + it 'aggregates all attempts with responses for the question for a given school' do + expect(aggregated_responses.count).to eq(3) + expect(aggregated_responses.responses.to_a).to eq([attempt1, attempt2, attempt4]) + expect(aggregated_responses.answer_index_total).to eq(8) + end + + it 'should calculate answer_index_average' do + expect(aggregated_responses.answer_index_average).to eq(8.0 / 3) + end + + it 'should calculate the most popular answer' do + expect(aggregated_responses.most_popular_answer).to eq(question.option3) + end + + it 'should provide access to the question and category' do + expect(aggregated_responses.question).to eq(question) + expect(aggregated_responses.category).to eq(question.category) + end + + end + + end +end diff --git a/spec/models/legacy/recipient_list_spec.rb b/spec/models/legacy/recipient_list_spec.rb new file mode 100644 index 00000000..d52d3894 --- /dev/null +++ b/spec/models/legacy/recipient_list_spec.rb @@ -0,0 +1,55 @@ +require 'rails_helper' + +module Legacy + describe RecipientList do + describe "Save" do + it "should convert the recipient_id_array into the recipient_ids attribute" do + recipient_list = RecipientList.create(name: 'Name', recipient_id_array: ['', '1', '2', '3']) + expect(recipient_list).to be_a(RecipientList) + expect(recipient_list).to be_persisted + expect(recipient_list.recipient_ids).to eq('1,2,3') + + recipient_list.update(recipient_id_array: ['3', '', '4', '5', '6']) + expect(recipient_list.reload.recipient_ids).to eq('3,4,5,6') + end + end + + describe "when edited" do + let!(:school) { School.create!(name: 'School') } + + let!(:recipients) { create_recipients(school, 3) } + let!(:recipient_list) do + school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) + end + + let!(:questions) { create_questions(3) } + let!(:question_list) do + QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) + end + + let!(:schedule) do + Schedule.create!( + name: 'Parent Schedule', + recipient_list_id: recipient_list.id, + question_list: question_list, + random: false, + frequency_hours: 24 * 7 + ) + end + + it 'should delete recipient_schedules if a recipient is removed' do + modified_recipient_ids = recipients.map(&:id)[0, 2].join(',') + expect do + recipient_list.update(recipient_ids: modified_recipient_ids) + end.to change { schedule.recipient_schedules.count }.from(3).to(2) + end + + it 'should create recipient_schedules if a recipient is added' do + new_recipients = create_recipients(school, 2) + expect do + recipient_list.update(recipient_ids: (recipients + new_recipients).map(&:id).join(',')) + end.to change { schedule.recipient_schedules.count }.from(3).to(5) + end + end + end +end diff --git a/spec/models/legacy/recipient_schedule_spec.rb b/spec/models/legacy/recipient_schedule_spec.rb new file mode 100644 index 00000000..d2f7b2b7 --- /dev/null +++ b/spec/models/legacy/recipient_schedule_spec.rb @@ -0,0 +1,134 @@ +require 'rails_helper' + +module Legacy + RSpec.describe RecipientSchedule, type: :model do + let!(:school) { School.create!(name: 'School') } + + let!(:recipient) { create_recipients(school, 1).first } + let!(:recipient_list) do + school.recipient_lists.create!(name: 'Parents', recipient_ids: recipient.id.to_s) + end + + let(:category) { Category.create(name: 'Category') } + let!(:questions) { create_questions(3, category) } + let!(:question_list) do + QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) + end + + let!(:schedule) do + Schedule.create!( + name: 'Parent Schedule', + recipient_list_id: recipient_list.id, + question_list: question_list, + random: false, + frequency_hours: 24 + ) + end + let!(:recipient_schedule) { schedule.recipient_schedules.for_recipient(recipient).first } + + let!(:not_ready_recipient_schedule) do + RecipientSchedule.create!( + recipient: recipient, + schedule: schedule, + upcoming_question_ids: '1,3', + attempted_question_ids: '2', + last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours), + next_attempt_at: 1.day.from_now + (60 * 60 * schedule.frequency_hours) + ) + end + + xdescribe 'ready' do + before :each do + now = DateTime.now + date = ActiveSupport::TimeZone['UTC'].parse(now.strftime('%Y-%m-%dT16:00:00%z')) + Timecop.freeze(date) + end + + subject { schedule.recipient_schedules.ready } + + it('should only provide recipient_schedules who are ready to send a message') do + expect(subject.length).to eq(1) + expect(subject.first).to eq(recipient_schedule) + end + end + + describe 'next_question' do + it 'should provide the next question from the upcoming_question_ids list' do + expect(recipient_schedule.next_question).to eq(questions.first) + end + end + + describe 'attempt_question' do + before :each do + Timecop.freeze + end + + describe 'with an opted out recipient' do + before :each do + recipient_schedule.recipient.update(opted_out: true) + end + + let!(:attempt) { recipient_schedule.attempt_question } + + it 'should not do anything' do + expect(attempt).to be_nil + end + end + + describe 'right before a weekend' do + before :each do + friday_time = ActiveSupport::TimeZone['UTC'].parse('2017-04-21T20:00:00') + Timecop.freeze + recipient_schedule.update(next_attempt_at: friday_time) + end + + let!(:attempt) { recipient_schedule.attempt_question } + + it 'should schedule the next attempt for after the weekend' do + next_weekday_time = ActiveSupport::TimeZone['UTC'].parse('2017-04-24T20:00:00') + expect(recipient_schedule.reload.next_attempt_at).to eq(next_weekday_time) + end + end + + describe 'with an opted in recipient' do + before :each do + date = ActiveSupport::TimeZone['UTC'].parse('2017-04-20T20:00:00') + Timecop.freeze(date) + end + + let!(:attempt) { recipient_schedule.attempt_question } + + it 'should make an attempt to ask the next question' do + expect(attempt).to be_persisted + expect(attempt.recipient).to eq(recipient) + expect(attempt.schedule).to eq(schedule) + expect(attempt.recipient_schedule).to eq(recipient_schedule) + expect(attempt.question).to eq(questions.first) + expect(attempt.sent_at.to_i).to eq(Time.new.to_i) + expect(attempt.answer_index).to be_nil + end + + it 'should update the upcoming_questions_ids' do + expect(recipient_schedule.upcoming_question_ids).to eq(questions[1..2].map(&:id).join(',')) + end + + it 'should update the attempted_question_ids' do + expect(recipient_schedule.attempted_question_ids).to eq(questions.first.id.to_s) + end + + it 'should update last_attempt_at' do + expect(recipient_schedule.last_attempt_at.to_i).to eq(Time.new.to_i) + end + + it 'should update next_attempt_at' do + now = DateTime.now + date = ActiveSupport::TimeZone['Eastern Time (US & Canada)'].parse(now.strftime('%Y-%m-%dT16:00:00%z')) + date += 1.day + date += 1.day if date.on_weekend? + + expect(recipient_schedule.reload.next_attempt_at).to eq(date.to_time) + end + end + end + end +end diff --git a/spec/models/legacy/recipient_spec.rb b/spec/models/legacy/recipient_spec.rb new file mode 100644 index 00000000..2db26a61 --- /dev/null +++ b/spec/models/legacy/recipient_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +module Legacy + describe Recipient do + describe "Import" do + let(:school) { School.create!(name: 'School') } + let(:data) { "name,phone\rJared,111-222-333\rLauren,222-333-4444\rAbby,333-444-5555\r" } + let(:file) { instance_double('File', path: 'path') } + + xit "should parse file contents and return a result" do + expect(File).to receive(:open).with('path', universal_newline: false, headers: true) { StringIO.new(data) } + Recipient.import(school, file) + expect(Recipient.count).to eq(3) + expect(Recipient.all.map(&:name)).to eq(['Jared', 'Lauren', 'Abby']) + expect(Recipient.all.map(&:school).uniq).to eq([school]) + end + end + + describe "When Deleted" do + let!(:school) { School.create!(name: 'School') } + + let!(:recipients) { create_recipients(school, 3) } + let!(:recipient_list) do + school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) + end + + let!(:questions) { create_questions(3) } + let!(:question_list) do + QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) + end + + let!(:schedule) do + Schedule.create!( + name: 'Parent Schedule', + recipient_list_id: recipient_list.id, + question_list: question_list, + random: false, + frequency_hours: 24 * 7 + ) + end + + it 'should delete all recipient_schedules and update all recipient_lists' do + expect do + recipients[1].destroy + end.to change { schedule.recipient_schedules.count }.from(3).to(2) + + expect(recipient_list.recipient_ids).to eq("#{recipients[0].id},#{recipients[2].id}") + + end + end + end +end diff --git a/spec/models/legacy/schedule_spec.rb b/spec/models/legacy/schedule_spec.rb new file mode 100644 index 00000000..c8d0d6a6 --- /dev/null +++ b/spec/models/legacy/schedule_spec.rb @@ -0,0 +1,64 @@ +require 'rails_helper' + +module Legacy + describe Schedule do + + let!(:school) { School.create!(name: 'School') } + + let!(:recipients) { create_recipients(school, 3) } + let!(:recipient_list) do + school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) + end + + let!(:kid_recipients) { create_recipients(school, 3) } + let!(:kids_recipient_list) do + school.recipient_lists.create!(name: 'Kids', recipient_ids: kid_recipients.map(&:id).join(',')) + end + + let!(:questions) { create_questions(3) } + let!(:question_list) do + QuestionList.create!(name: 'Questions', question_ids: questions.map(&:id).join(',')) + end + + let(:default_schedule_params) { + { + school: school, + recipient_list: recipient_list, + question_list: question_list, + name: 'Parents Schedule', + description: 'Schedule for parent questions', + start_date: 1.month.ago, + end_date: 11.months.from_now, + active: true + } + } + + let!(:active_schedule) do + Schedule.create!(default_schedule_params) + end + + let!(:active_schedule_kids) do + Schedule.create!(default_schedule_params.merge!(name: 'Kids Schedule', recipient_list: kids_recipient_list)) + end + + let!(:old_schedule) { + Schedule.create!(default_schedule_params.merge!(start_date: 13.month.ago, end_date: 1.months.ago)) + } + + let!(:paused_schedule) { + Schedule.create!(default_schedule_params.merge!(active: false)) + } + + describe "active" do + it 'finds active schedules' do + active = Schedule.active + expect(active.length).to eq(2) + end + end + + it 'creates a recipient_schedule for every recipient when created' do + expect(active_schedule.recipient_schedules.length).to eq(3) + end + + end +end diff --git a/spec/models/legacy/school_category_spec.rb b/spec/models/legacy/school_category_spec.rb new file mode 100644 index 00000000..9b2b8c6d --- /dev/null +++ b/spec/models/legacy/school_category_spec.rb @@ -0,0 +1,75 @@ +require 'rails_helper' + +module Legacy + RSpec.describe SchoolCategory, type: :model do + + let!(:school1) { School.create!(name: 'School 1') } + let!(:school2) { School.create!(name: 'School 2') } + + let!(:school1recipients) { create_recipients(school1, 4) } + let!(:school2recipients) { create_recipients(school2, 4) } + + let!(:category1) { Category.create!(name: 'Category 1') } + let!(:category2) { Category.create!(name: 'Category 2') } + + let!(:category1questions) { create_questions(3, category1) } + let!(:category2questions) { create_questions(3, category2) } + + let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2) } + let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1]) } + let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3) } + let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4) } + let!(:attempt5) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5) } + let!(:attempt6) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5) } + let!(:attempt7) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3) } + let!(:attempt8) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1) } + + let!(:school_category1) { SchoolCategory.for(school1, category1).first } + + describe 'aggregated_responses' do + xit 'should provide the count and sum of all attempts' do + expect(school_category1.aggregated_responses).to eq( + attempt_count: 5, + response_count: 4, + answer_index_total: 15 + ) + end + end + + describe 'answer_index_average' do + xit 'should provide the average answer_index for all responses' do + expect(school_category1.answer_index_average).to eq(15.0 / 4.0) + end + end + + describe 'sync_aggregated_responses' do + + let!(:category3) { Category.create!(name: 'Category 3', parent_category: category1) } + + let!(:category3questions) { create_questions(3, category3) } + + let!(:attempt7) { Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4) } + let!(:attempt8) { Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1) } + let!(:attempt9) { Attempt.create!(question: category3questions[0], recipient: school1recipients[2]) } + let!(:attempt10) { Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5) } + let!(:attempt11) { Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5) } + + let!(:school_category3) { SchoolCategory.for(school1, category3).first } + + xit 'should update attributes and parent_category school_category attributes' do + school_category3.sync_aggregated_responses + + school_category3.reload + expect(school_category3.attempt_count).to eq(4) + expect(school_category3.response_count).to eq(3) + expect(school_category3.answer_index_total).to eq(10) + + school_category1.reload + expect(school_category1.attempt_count).to eq(9) + expect(school_category1.response_count).to eq(7) + expect(school_category1.answer_index_total).to eq(25) + end + end + + end +end diff --git a/spec/models/legacy/student_spec.rb b/spec/models/legacy/student_spec.rb new file mode 100644 index 00000000..e91a0c0b --- /dev/null +++ b/spec/models/legacy/student_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +module Legacy + RSpec.describe Student, type: :model do + pending "add some examples to (or delete) #{__FILE__}" + end +end diff --git a/spec/models/legacy/user_school_spec.rb b/spec/models/legacy/user_school_spec.rb new file mode 100644 index 00000000..1d3d07ca --- /dev/null +++ b/spec/models/legacy/user_school_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +module Legacy + RSpec.describe UserSchool, type: :model do + pending "add some examples to (or delete) #{__FILE__}" + end +end diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb deleted file mode 100644 index b6f7a854..00000000 --- a/spec/models/question_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'rails_helper' - -RSpec.describe Question, type: :model do - - let!(:school1) { School.create!(name: 'School 1') } - let!(:school2) { School.create!(name: 'School 2') } - - let!(:school1recipients) { create_recipients(school1, 5) } - let!(:school2recipients) { create_recipients(school2, 4) } - - let!(:category1) { Category.create!(name: 'Resources') } - let!(:category2) { Category.create!(name: 'Category 2') } - - let!(:category1questions) { create_questions(3, category1) } - let!(:category2questions) { create_questions(3, category2) } - let(:question) { category1questions.first } - - let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 3)} - let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1], answer_index: 2)} - let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2])} - let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school1recipients[3], answer_index: 3)} - let!(:attempt5) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4)} - let!(:attempt6) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5)} - let!(:attempt7) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5)} - let!(:attempt8) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3)} - let!(:attempt9) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1)} - - describe 'aggregated_responses_for_school' do - - let(:aggregated_responses) { question.aggregated_responses_for_school(school1) } - - it 'aggregates all attempts with responses for the question for a given school' do - expect(aggregated_responses.count).to eq(3) - expect(aggregated_responses.responses.to_a).to eq([attempt1, attempt2, attempt4]) - expect(aggregated_responses.answer_index_total).to eq(8) - end - - it 'should calculate answer_index_average' do - expect(aggregated_responses.answer_index_average).to eq(8.0 / 3) - end - - it 'should calculate the most popular answer' do - expect(aggregated_responses.most_popular_answer).to eq(question.option3) - end - - it 'should provide access to the question and category' do - expect(aggregated_responses.question).to eq(question) - expect(aggregated_responses.category).to eq(question.category) - end - - end - - -end diff --git a/spec/models/recipient_list_spec.rb b/spec/models/recipient_list_spec.rb deleted file mode 100644 index ada6a65c..00000000 --- a/spec/models/recipient_list_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'rails_helper' - -describe RecipientList do - describe "Save" do - it "should convert the recipient_id_array into the recipient_ids attribute" do - recipient_list = RecipientList.create(name: 'Name', recipient_id_array: ['', '1', '2', '3']) - expect(recipient_list).to be_a(RecipientList) - expect(recipient_list).to be_persisted - expect(recipient_list.recipient_ids).to eq('1,2,3') - - recipient_list.update(recipient_id_array: ['3', '', '4', '5', '6']) - expect(recipient_list.reload.recipient_ids).to eq('3,4,5,6') - end - end - - describe "when edited" do - let!(:school) { School.create!(name: 'School') } - - let!(:recipients) { create_recipients(school, 3) } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) - end - - let!(:questions) { create_questions(3) } - let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) - end - - let!(:schedule) do - Schedule.create!( - name: 'Parent Schedule', - recipient_list_id: recipient_list.id, - question_list: question_list, - random: false, - frequency_hours: 24 * 7 - ) - end - - it 'should delete recipient_schedules if a recipient is removed' do - modified_recipient_ids = recipients.map(&:id)[0,2].join(',') - expect do - recipient_list.update(recipient_ids: modified_recipient_ids) - end.to change { schedule.recipient_schedules.count }.from(3).to(2) - end - - it 'should create recipient_schedules if a recipient is added' do - new_recipients = create_recipients(school, 2) - expect do - recipient_list.update(recipient_ids: (recipients + new_recipients).map(&:id).join(',')) - end.to change { schedule.recipient_schedules.count }.from(3).to(5) - end - end -end diff --git a/spec/models/recipient_schedule_spec.rb b/spec/models/recipient_schedule_spec.rb deleted file mode 100644 index 5f06e66c..00000000 --- a/spec/models/recipient_schedule_spec.rb +++ /dev/null @@ -1,133 +0,0 @@ -require 'rails_helper' - -RSpec.describe RecipientSchedule, type: :model do - - let!(:school) { School.create!(name: 'School') } - - let!(:recipient) { create_recipients(school, 1).first } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: "#{recipient.id}") - end - - let(:category) { Category.create(name: 'Category') } - let!(:questions) { create_questions(3, category) } - let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) - end - - let!(:schedule) do - Schedule.create!( - name: 'Parent Schedule', - recipient_list_id: recipient_list.id, - question_list: question_list, - random: false, - frequency_hours: 24 - ) - end - let!(:recipient_schedule) { schedule.recipient_schedules.for_recipient(recipient).first } - - let!(:not_ready_recipient_schedule) do - RecipientSchedule.create!( - recipient: recipient, - schedule: schedule, - upcoming_question_ids: '1,3', - attempted_question_ids: '2', - last_attempt_at: Date.today + (60 * 60 * schedule.frequency_hours), - next_attempt_at: 1.day.from_now + (60 * 60 * schedule.frequency_hours) - ) - end - - xdescribe 'ready' do - before :each do - now = DateTime.now - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT16:00:00%z")) - Timecop.freeze(date) - end - - subject { schedule.recipient_schedules.ready } - - it ('should only provide recipient_schedules who are ready to send a message') do - expect(subject.length).to eq(1) - expect(subject.first).to eq(recipient_schedule) - end - end - - describe 'next_question' do - it 'should provide the next question from the upcoming_question_ids list' do - expect(recipient_schedule.next_question).to eq(questions.first) - end - end - - describe 'attempt_question' do - before :each do - Timecop.freeze - end - - describe 'with an opted out recipient' do - before :each do - recipient_schedule.recipient.update(opted_out: true) - end - - let!(:attempt) { recipient_schedule.attempt_question } - - it 'should not do anything' do - expect(attempt).to be_nil - end - end - - describe 'right before a weekend' do - before :each do - friday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-21T20:00:00') - Timecop.freeze() - recipient_schedule.update(next_attempt_at: friday_time) - end - - let!(:attempt) { recipient_schedule.attempt_question } - - it 'should schedule the next attempt for after the weekend' do - next_weekday_time = ActiveSupport::TimeZone["UTC"].parse('2017-04-24T20:00:00') - expect(recipient_schedule.reload.next_attempt_at).to eq(next_weekday_time) - end - end - - describe 'with an opted in recipient' do - before :each do - date = ActiveSupport::TimeZone["UTC"].parse('2017-04-20T20:00:00') - Timecop.freeze(date) - end - - let!(:attempt) { recipient_schedule.attempt_question } - - it 'should make an attempt to ask the next question' do - expect(attempt).to be_persisted - expect(attempt.recipient).to eq(recipient) - expect(attempt.schedule).to eq(schedule) - expect(attempt.recipient_schedule).to eq(recipient_schedule) - expect(attempt.question).to eq(questions.first) - expect(attempt.sent_at.to_i).to eq(Time.new.to_i) - expect(attempt.answer_index).to be_nil - end - - it 'should update the upcoming_questions_ids' do - expect(recipient_schedule.upcoming_question_ids).to eq(questions[1..2].map(&:id).join(',')) - end - - it 'should update the attempted_question_ids' do - expect(recipient_schedule.attempted_question_ids).to eq(questions.first.id.to_s) - end - - it 'should update last_attempt_at' do - expect(recipient_schedule.last_attempt_at.to_i).to eq(Time.new.to_i) - end - - it 'should update next_attempt_at' do - now = DateTime.now - date = ActiveSupport::TimeZone["Eastern Time (US & Canada)"].parse(now.strftime("%Y-%m-%dT16:00:00%z")) - date += 1.day - date += 1.day if date.on_weekend? - - expect(recipient_schedule.reload.next_attempt_at).to eq(date.to_time) - end - end - end -end diff --git a/spec/models/recipient_spec.rb b/spec/models/recipient_spec.rb deleted file mode 100644 index 43b1d61c..00000000 --- a/spec/models/recipient_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'rails_helper' - -describe Recipient do - describe "Import" do - let(:school) { School.create!(name: 'School') } - let(:data) { "name,phone\rJared,111-222-333\rLauren,222-333-4444\rAbby,333-444-5555\r" } - let(:file) { instance_double('File', path: 'path') } - - xit "should parse file contents and return a result" do - expect(File).to receive(:open).with('path', universal_newline: false, headers: true) { StringIO.new(data) } - Recipient.import(school, file) - expect(Recipient.count).to eq(3) - expect(Recipient.all.map(&:name)).to eq(['Jared', 'Lauren', 'Abby']) - expect(Recipient.all.map(&:school).uniq).to eq([school]) - end - end - - describe "When Deleted" do - let!(:school) { School.create!(name: 'School') } - - let!(:recipients) { create_recipients(school, 3) } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) - end - - let!(:questions) { create_questions(3) } - let!(:question_list) do - QuestionList.create!(name: 'Parent Questions', question_ids: questions.map(&:id).join(',')) - end - - let!(:schedule) do - Schedule.create!( - name: 'Parent Schedule', - recipient_list_id: recipient_list.id, - question_list: question_list, - random: false, - frequency_hours: 24 * 7 - ) - end - - it 'should delete all recipient_schedules and update all recipient_lists' do - expect do - recipients[1].destroy - end.to change { schedule.recipient_schedules.count }.from(3).to(2) - - expect(recipient_list.recipient_ids).to eq("#{recipients[0].id},#{recipients[2].id}") - - end - end -end diff --git a/spec/models/schedule_spec.rb b/spec/models/schedule_spec.rb deleted file mode 100644 index dc13fe37..00000000 --- a/spec/models/schedule_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'rails_helper' - -describe Schedule do - - let!(:school) { School.create!(name: 'School') } - - let!(:recipients) { create_recipients(school, 3) } - let!(:recipient_list) do - school.recipient_lists.create!(name: 'Parents', recipient_ids: recipients.map(&:id).join(',')) - end - - let!(:kid_recipients) { create_recipients(school, 3) } - let!(:kids_recipient_list) do - school.recipient_lists.create!(name: 'Kids', recipient_ids: kid_recipients.map(&:id).join(',')) - end - - let!(:questions) { create_questions(3) } - let!(:question_list) do - QuestionList.create!(name: 'Questions', question_ids: questions.map(&:id).join(',')) - end - - let(:default_schedule_params) { - { - school: school, - recipient_list: recipient_list, - question_list: question_list, - name: 'Parents Schedule', - description: 'Schedule for parent questions', - start_date: 1.month.ago, - end_date: 11.months.from_now, - active: true - } - } - - let!(:active_schedule) do - Schedule.create!(default_schedule_params) - end - - let!(:active_schedule_kids) do - Schedule.create!(default_schedule_params.merge!(name: 'Kids Schedule', recipient_list: kids_recipient_list)) - end - - let!(:old_schedule) { - Schedule.create!(default_schedule_params.merge!(start_date: 13.month.ago, end_date: 1.months.ago)) - } - - let!(:paused_schedule) { - Schedule.create!(default_schedule_params.merge!(active: false)) - } - - describe "active" do - it 'finds active schedules' do - active = Schedule.active - expect(active.length).to eq(2) - end - end - - it 'creates a recipient_schedule for every recipient when created' do - expect(active_schedule.recipient_schedules.length).to eq(3) - end - -end diff --git a/spec/models/school_category_spec.rb b/spec/models/school_category_spec.rb deleted file mode 100644 index 4980b7ab..00000000 --- a/spec/models/school_category_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'rails_helper' - -RSpec.describe SchoolCategory, type: :model do - - let!(:school1) { School.create!(name: 'School 1') } - let!(:school2) { School.create!(name: 'School 2') } - - let!(:school1recipients) { create_recipients(school1, 4) } - let!(:school2recipients) { create_recipients(school2, 4) } - - let!(:category1) { Category.create!(name: 'Category 1') } - let!(:category2) { Category.create!(name: 'Category 2') } - - let!(:category1questions) { create_questions(3, category1) } - let!(:category2questions) { create_questions(3, category2) } - - let!(:attempt1) { Attempt.create!(question: category1questions[0], recipient: school1recipients[0], answer_index: 2)} - let!(:attempt2) { Attempt.create!(question: category1questions[0], recipient: school1recipients[1])} - let!(:attempt3) { Attempt.create!(question: category1questions[0], recipient: school1recipients[2], answer_index: 3)} - let!(:attempt4) { Attempt.create!(question: category1questions[0], recipient: school2recipients[0], answer_index: 4)} - let!(:attempt5) { Attempt.create!(question: category1questions[1], recipient: school1recipients[0], answer_index: 5)} - let!(:attempt6) { Attempt.create!(question: category1questions[2], recipient: school1recipients[0], answer_index: 5)} - let!(:attempt7) { Attempt.create!(question: category2questions[0], recipient: school1recipients[0], answer_index: 3)} - let!(:attempt8) { Attempt.create!(question: category2questions[1], recipient: school1recipients[1], answer_index: 1)} - - let!(:school_category1) { SchoolCategory.for(school1, category1).first } - - describe 'aggregated_responses' do - xit 'should provide the count and sum of all attempts' do - expect(school_category1.aggregated_responses).to eq( - attempt_count: 5, - response_count: 4, - answer_index_total: 15 - ) - end - end - - describe 'answer_index_average' do - xit 'should provide the average answer_index for all responses' do - expect(school_category1.answer_index_average).to eq(15.0/4.0) - end - end - - describe 'sync_aggregated_responses' do - - let!(:category3) { Category.create!(name: 'Category 3', parent_category: category1) } - - let!(:category3questions) { create_questions(3, category3) } - - let!(:attempt7) { Attempt.create!(question: category3questions[0], recipient: school1recipients[0], answer_index: 4)} - let!(:attempt8) { Attempt.create!(question: category3questions[0], recipient: school1recipients[1], answer_index: 1)} - let!(:attempt9) { Attempt.create!(question: category3questions[0], recipient: school1recipients[2])} - let!(:attempt10) { Attempt.create!(question: category3questions[1], recipient: school1recipients[1], answer_index: 5)} - let!(:attempt11) { Attempt.create!(question: category3questions[1], recipient: school2recipients[0], answer_index: 5)} - - let!(:school_category3) { SchoolCategory.for(school1, category3).first } - - - xit 'should update attributes and parent_category school_category attributes' do - school_category3.sync_aggregated_responses - - school_category3.reload - expect(school_category3.attempt_count).to eq(4) - expect(school_category3.response_count).to eq(3) - expect(school_category3.answer_index_total).to eq(10) - - school_category1.reload - expect(school_category1.attempt_count).to eq(9) - expect(school_category1.response_count).to eq(7) - expect(school_category1.answer_index_total).to eq(25) - end - end - -end diff --git a/spec/models/student_spec.rb b/spec/models/student_spec.rb deleted file mode 100644 index 6928c63e..00000000 --- a/spec/models/student_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe Student, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/survey_item_spec.rb b/spec/models/survey_item_spec.rb deleted file mode 100644 index 58b4e800..00000000 --- a/spec/models/survey_item_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'rails_helper' - -# FIXME remove this when seeds.rb is under test -xdescribe SurveyItem, type: :model do - it('has all the questions') do - expect(SurveyItem.count).to eq 137 - end -end diff --git a/spec/models/user_school_spec.rb b/spec/models/user_school_spec.rb deleted file mode 100644 index b6599ad5..00000000 --- a/spec/models/user_school_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe UserSchool, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/presenters/category_presenter_spec.rb b/spec/presenters/category_presenter_spec.rb index 4b0c96b6..7904e99e 100644 --- a/spec/presenters/category_presenter_spec.rb +++ b/spec/presenters/category_presenter_spec.rb @@ -5,32 +5,32 @@ describe CategoryPresenter do subcategory1 = Subcategory.new(name: 'A subcategory') subcategory2 = Subcategory.new(name: 'Another subcategory') - category = SqmCategory.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category') + category = Category.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category') return CategoryPresenter.new(category: category) end let(:teachers_and_leadership_presenter) do - category = create(:sqm_category, name: 'Teachers & Leadership') + category = create(:category, name: 'Teachers & Leadership') return CategoryPresenter.new(category: category) end let(:school_culture_presenter) do - category = create(:sqm_category, name: "School Culture") + category = create(:category, name: "School Culture") return CategoryPresenter.new(category: category) end let(:resources_presenter) do - category = create(:sqm_category, name: "Resources") + category = create(:category, name: "Resources") return CategoryPresenter.new(category: category) end let(:academic_learning_presenter) do - category = create(:sqm_category, name: "Academic Learning") + category = create(:category, name: "Academic Learning") return CategoryPresenter.new(category: category) end let(:community_and_wellbeing_presenter) do - category = create(:sqm_category, name: "Community & Wellbeing") + category = create(:category, name: "Community & Wellbeing") return CategoryPresenter.new(category: category) end diff --git a/spec/routing/categories_routing_spec.rb b/spec/routing/categories_routing_spec.rb deleted file mode 100644 index 162e5d13..00000000 --- a/spec/routing/categories_routing_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe CategoriesController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/categories").to route_to("categories#index") - end - - it "routes to #new" do - expect(:get => "/categories/new").to route_to("categories#new") - end - - it "routes to #show" do - expect(:get => "/categories/1").to route_to("categories#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/categories/1/edit").to route_to("categories#edit", :id => "1") - end - - it "routes to #create" do - expect(:post => "/categories").to route_to("categories#create") - end - - it "routes to #update via PUT" do - expect(:put => "/categories/1").to route_to("categories#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/categories/1").to route_to("categories#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/categories/1").to route_to("categories#destroy", :id => "1") - end - - end -end diff --git a/spec/routing/districts_routing_spec.rb b/spec/routing/districts_routing_spec.rb deleted file mode 100644 index e00d6da4..00000000 --- a/spec/routing/districts_routing_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe DistrictsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/districts").to route_to("districts#index") - end - - it "routes to #new" do - expect(:get => "/districts/new").to route_to("districts#new") - end - - it "routes to #show" do - expect(:get => "/districts/1").to route_to("districts#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/districts/1/edit").to route_to("districts#edit", :id => "1") - end - - it "routes to #create" do - expect(:post => "/districts").to route_to("districts#create") - end - - it "routes to #update via PUT" do - expect(:put => "/districts/1").to route_to("districts#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/districts/1").to route_to("districts#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/districts/1").to route_to("districts#destroy", :id => "1") - end - - end -end diff --git a/spec/routing/legacy/categories_routing_spec.rb b/spec/routing/legacy/categories_routing_spec.rb new file mode 100644 index 00000000..43c35f98 --- /dev/null +++ b/spec/routing/legacy/categories_routing_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +module Legacy + RSpec.describe CategoriesController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/categories").to route_to("legacy/categories#index") + end + + it "routes to #new" do + expect(:get => "/categories/new").to route_to("legacy/categories#new") + end + + it "routes to #show" do + expect(:get => "/categories/1").to route_to("legacy/categories#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/categories/1/edit").to route_to("legacy/categories#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/categories").to route_to("legacy/categories#create") + end + + it "routes to #update via PUT" do + expect(:put => "/categories/1").to route_to("legacy/categories#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/categories/1").to route_to("legacy/categories#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/categories/1").to route_to("legacy/categories#destroy", :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/districts_routing_spec.rb b/spec/routing/legacy/districts_routing_spec.rb new file mode 100644 index 00000000..534dea44 --- /dev/null +++ b/spec/routing/legacy/districts_routing_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +module Legacy + RSpec.describe DistrictsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/districts").to route_to("legacy/districts#index") + end + + it "routes to #new" do + expect(:get => "/districts/new").to route_to("legacy/districts#new") + end + + it "routes to #show" do + expect(:get => "/districts/1").to route_to("legacy/districts#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/districts/1/edit").to route_to("legacy/districts#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/districts").to route_to("legacy/districts#create") + end + + it "routes to #update via PUT" do + expect(:put => "/districts/1").to route_to("legacy/districts#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/districts/1").to route_to("legacy/districts#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/districts/1").to route_to("legacy/districts#destroy", :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/question_lists_routing_spec.rb b/spec/routing/legacy/question_lists_routing_spec.rb new file mode 100644 index 00000000..5db33621 --- /dev/null +++ b/spec/routing/legacy/question_lists_routing_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +module Legacy + RSpec.describe Legacy::QuestionListsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/question_lists").to route_to("legacy/question_lists#index") + end + + it "routes to #new" do + expect(:get => "/question_lists/new").to route_to("legacy/question_lists#new") + end + + it "routes to #show" do + expect(:get => "/question_lists/1").to route_to("legacy/question_lists#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/question_lists/1/edit").to route_to("legacy/question_lists#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/question_lists").to route_to("legacy/question_lists#create") + end + + it "routes to #update via PUT" do + expect(:put => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/question_lists/1").to route_to("legacy/question_lists#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/question_lists/1").to route_to("legacy/question_lists#destroy", :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/questions_routing_spec.rb b/spec/routing/legacy/questions_routing_spec.rb new file mode 100644 index 00000000..158d58dc --- /dev/null +++ b/spec/routing/legacy/questions_routing_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +module Legacy + RSpec.describe QuestionsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/questions").to route_to("legacy/questions#index") + end + + it "routes to #new" do + expect(:get => "/questions/new").to route_to("legacy/questions#new") + end + + it "routes to #show" do + expect(:get => "/questions/1").to route_to("legacy/questions#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/questions/1/edit").to route_to("legacy/questions#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/questions").to route_to("legacy/questions#create") + end + + it "routes to #update via PUT" do + expect(:put => "/questions/1").to route_to("legacy/questions#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/questions/1").to route_to("legacy/questions#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/questions/1").to route_to("legacy/questions#destroy", :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/recipient_lists_routing_spec.rb b/spec/routing/legacy/recipient_lists_routing_spec.rb new file mode 100644 index 00000000..60a14eb6 --- /dev/null +++ b/spec/routing/legacy/recipient_lists_routing_spec.rb @@ -0,0 +1,47 @@ +require "rails_helper" + +module Legacy + RSpec.describe RecipientListsController, type: :routing do + describe "routing" do + before(:each) do + @school = School.create!( + :name => "MyString", + :district_id => 1 + ) + end + + it "routes to #index" do + expect(:get => "schools/#{@school.id}/recipient_lists").to route_to("legacy/recipient_lists#index", school_id: @school.id.to_s) + end + + it "routes to #new" do + expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("legacy/recipient_lists#new", school_id: @school.id.to_s) + end + + it "routes to #show" do + expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#show", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #edit" do + expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("legacy/recipient_lists#edit", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #create" do + expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("legacy/recipient_lists#create", school_id: @school.id.to_s) + end + + it "routes to #update via PUT" do + expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("legacy/recipient_lists#destroy", school_id: @school.id.to_s, :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/recipients_routing_spec.rb b/spec/routing/legacy/recipients_routing_spec.rb new file mode 100644 index 00000000..6cc9e994 --- /dev/null +++ b/spec/routing/legacy/recipients_routing_spec.rb @@ -0,0 +1,47 @@ +require "rails_helper" + +module Legacy + RSpec.describe RecipientsController, type: :routing do + describe "routing" do + before(:each) do + @school = School.create!( + :name => "MyString", + :district_id => 1 + ) + end + + it "routes to #index" do + expect(:get => "schools/#{@school.id}/recipients").to route_to("legacy/recipients#index", school_id: @school.id.to_s) + end + + it "routes to #new" do + expect(:get => "schools/#{@school.id}/recipients/new").to route_to("legacy/recipients#new", school_id: @school.id.to_s) + end + + it "routes to #show" do + expect(:get => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#show", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #edit" do + expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("legacy/recipients#edit", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #create" do + expect(:post => "schools/#{@school.id}/recipients").to route_to("legacy/recipients#create", school_id: @school.id.to_s) + end + + it "routes to #update via PUT" do + expect(:put => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("legacy/recipients#destroy", school_id: @school.id.to_s, :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/schedules_routing_spec.rb b/spec/routing/legacy/schedules_routing_spec.rb new file mode 100644 index 00000000..58374261 --- /dev/null +++ b/spec/routing/legacy/schedules_routing_spec.rb @@ -0,0 +1,47 @@ +require "rails_helper" + +module Legacy + RSpec.describe SchedulesController, type: :routing do + describe "routing" do + before(:each) do + @school = School.create!( + :name => "MyString", + :district_id => 1 + ) + end + + it "routes to #index" do + expect(:get => "schools/#{@school.id}/schedules").to route_to("legacy/schedules#index", school_id: @school.id.to_s) + end + + it "routes to #new" do + expect(:get => "schools/#{@school.id}/schedules/new").to route_to("legacy/schedules#new", school_id: @school.id.to_s) + end + + it "routes to #show" do + expect(:get => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#show", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #edit" do + expect(:get => "schools/#{@school.id}/schedules/1/edit").to route_to("legacy/schedules#edit", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #create" do + expect(:post => "schools/#{@school.id}/schedules").to route_to("legacy/schedules#create", school_id: @school.id.to_s) + end + + it "routes to #update via PUT" do + expect(:put => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#update", school_id: @school.id.to_s, :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "schools/#{@school.id}/schedules/1").to route_to("legacy/schedules#destroy", school_id: @school.id.to_s, :id => "1") + end + + end + end +end diff --git a/spec/routing/legacy/schools_routing_spec.rb b/spec/routing/legacy/schools_routing_spec.rb new file mode 100644 index 00000000..d4340f9c --- /dev/null +++ b/spec/routing/legacy/schools_routing_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +module Legacy + RSpec.describe SchoolsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/schools").to route_to("legacy/schools#index") + end + + it "routes to #new" do + expect(:get => "/schools/new").to route_to("legacy/schools#new") + end + + it "routes to #show" do + expect(:get => "/schools/1").to route_to("legacy/schools#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/schools/1/edit").to route_to("legacy/schools#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/schools").to route_to("legacy/schools#create") + end + + it "routes to #update via PUT" do + expect(:put => "/schools/1").to route_to("legacy/schools#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/schools/1").to route_to("legacy/schools#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/schools/1").to route_to("legacy/schools#destroy", :id => "1") + end + + end + end +end diff --git a/spec/routing/question_lists_routing_spec.rb b/spec/routing/question_lists_routing_spec.rb deleted file mode 100644 index e3d2faa1..00000000 --- a/spec/routing/question_lists_routing_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe QuestionListsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/question_lists").to route_to("question_lists#index") - end - - it "routes to #new" do - expect(:get => "/question_lists/new").to route_to("question_lists#new") - end - - it "routes to #show" do - expect(:get => "/question_lists/1").to route_to("question_lists#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/question_lists/1/edit").to route_to("question_lists#edit", :id => "1") - end - - it "routes to #create" do - expect(:post => "/question_lists").to route_to("question_lists#create") - end - - it "routes to #update via PUT" do - expect(:put => "/question_lists/1").to route_to("question_lists#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/question_lists/1").to route_to("question_lists#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/question_lists/1").to route_to("question_lists#destroy", :id => "1") - end - - end -end diff --git a/spec/routing/questions_routing_spec.rb b/spec/routing/questions_routing_spec.rb deleted file mode 100644 index c129db8f..00000000 --- a/spec/routing/questions_routing_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe QuestionsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/questions").to route_to("questions#index") - end - - it "routes to #new" do - expect(:get => "/questions/new").to route_to("questions#new") - end - - it "routes to #show" do - expect(:get => "/questions/1").to route_to("questions#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/questions/1/edit").to route_to("questions#edit", :id => "1") - end - - it "routes to #create" do - expect(:post => "/questions").to route_to("questions#create") - end - - it "routes to #update via PUT" do - expect(:put => "/questions/1").to route_to("questions#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/questions/1").to route_to("questions#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/questions/1").to route_to("questions#destroy", :id => "1") - end - - end -end diff --git a/spec/routing/recipient_lists_routing_spec.rb b/spec/routing/recipient_lists_routing_spec.rb deleted file mode 100644 index 4bf4b5d4..00000000 --- a/spec/routing/recipient_lists_routing_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "rails_helper" - -RSpec.describe RecipientListsController, type: :routing do - describe "routing" do - before(:each) do - @school = School.create!( - :name => "MyString", - :district_id => 1 - ) - end - - it "routes to #index" do - expect(:get => "schools/#{@school.id}/recipient_lists").to route_to("recipient_lists#index", school_id: @school.id.to_s) - end - - it "routes to #new" do - expect(:get => "schools/#{@school.id}/recipient_lists/new").to route_to("recipient_lists#new", school_id: @school.id.to_s) - end - - it "routes to #show" do - expect(:get => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#show", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/recipient_lists/1/edit").to route_to("recipient_lists#edit", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #create" do - expect(:post => "schools/#{@school.id}/recipient_lists").to route_to("recipient_lists#create", school_id: @school.id.to_s) - end - - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/recipient_lists/1").to route_to("recipient_lists#destroy", school_id: @school.id.to_s, :id => "1") - end - - end -end diff --git a/spec/routing/recipients_routing_spec.rb b/spec/routing/recipients_routing_spec.rb deleted file mode 100644 index df2c0b51..00000000 --- a/spec/routing/recipients_routing_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "rails_helper" - -RSpec.describe RecipientsController, type: :routing do - describe "routing" do - before(:each) do - @school = School.create!( - :name => "MyString", - :district_id => 1 - ) - end - - it "routes to #index" do - expect(:get => "schools/#{@school.id}/recipients").to route_to("recipients#index", school_id: @school.id.to_s) - end - - it "routes to #new" do - expect(:get => "schools/#{@school.id}/recipients/new").to route_to("recipients#new", school_id: @school.id.to_s) - end - - it "routes to #show" do - expect(:get => "schools/#{@school.id}/recipients/1").to route_to("recipients#show", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/recipients/1/edit").to route_to("recipients#edit", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #create" do - expect(:post => "schools/#{@school.id}/recipients").to route_to("recipients#create", school_id: @school.id.to_s) - end - - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/recipients/1").to route_to("recipients#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/recipients/1").to route_to("recipients#destroy", school_id: @school.id.to_s, :id => "1") - end - - end -end diff --git a/spec/routing/schedules_routing_spec.rb b/spec/routing/schedules_routing_spec.rb deleted file mode 100644 index 638c3c00..00000000 --- a/spec/routing/schedules_routing_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "rails_helper" - -RSpec.describe SchedulesController, type: :routing do - describe "routing" do - before(:each) do - @school = School.create!( - :name => "MyString", - :district_id => 1 - ) - end - - it "routes to #index" do - expect(:get => "schools/#{@school.id}/schedules").to route_to("schedules#index", school_id: @school.id.to_s) - end - - it "routes to #new" do - expect(:get => "schools/#{@school.id}/schedules/new").to route_to("schedules#new", school_id: @school.id.to_s) - end - - it "routes to #show" do - expect(:get => "schools/#{@school.id}/schedules/1").to route_to("schedules#show", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #edit" do - expect(:get => "schools/#{@school.id}/schedules/1/edit").to route_to("schedules#edit", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #create" do - expect(:post => "schools/#{@school.id}/schedules").to route_to("schedules#create", school_id: @school.id.to_s) - end - - it "routes to #update via PUT" do - expect(:put => "schools/#{@school.id}/schedules/1").to route_to("schedules#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "schools/#{@school.id}/schedules/1").to route_to("schedules#update", school_id: @school.id.to_s, :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "schools/#{@school.id}/schedules/1").to route_to("schedules#destroy", school_id: @school.id.to_s, :id => "1") - end - - end -end diff --git a/spec/routing/schools_routing_spec.rb b/spec/routing/schools_routing_spec.rb deleted file mode 100644 index 6980bb9e..00000000 --- a/spec/routing/schools_routing_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe SchoolsController, type: :routing do - describe "routing" do - - it "routes to #index" do - expect(:get => "/schools").to route_to("schools#index") - end - - it "routes to #new" do - expect(:get => "/schools/new").to route_to("schools#new") - end - - it "routes to #show" do - expect(:get => "/schools/1").to route_to("schools#show", :id => "1") - end - - it "routes to #edit" do - expect(:get => "/schools/1/edit").to route_to("schools#edit", :id => "1") - end - - it "routes to #create" do - expect(:post => "/schools").to route_to("schools#create") - end - - it "routes to #update via PUT" do - expect(:put => "/schools/1").to route_to("schools#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/schools/1").to route_to("schools#update", :id => "1") - end - - it "routes to #destroy" do - expect(:delete => "/schools/1").to route_to("schools#destroy", :id => "1") - end - - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ea9911af..25d922d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -169,7 +169,7 @@ end def create_questions(count, category=nil) questions = [] count.times do |i| - questions << Question.create( + questions << Legacy::Question.create( text: "Question #{i}:#{count}", option1: "Option #{i}:#{count} A", option2: "Option #{i}:#{count} B", diff --git a/spec/system/journey_spec.rb b/spec/system/journey_spec.rb index b849ddeb..92ceb4c0 100644 --- a/spec/system/journey_spec.rb +++ b/spec/system/journey_spec.rb @@ -6,7 +6,7 @@ describe 'District Admin', js: true do let(:school) { School.find_by_slug 'winchester-high-school' } let(:school_in_same_district) { School.find_by_slug 'muraco-elementary-school' } - let(:category) { SqmCategory.find_by_name('Teachers & Leadership') } + let(:category) { Category.find_by_name('Teachers & Leadership') } let(:subcategory) { Subcategory.find_by_name('Teachers & The Teaching Environment') } let(:measures_for_subcategory) { Measure.where(subcategory: subcategory) } let(:survey_items_for_subcategory) { SurveyItem.where(measure: measures_for_subcategory) } diff --git a/spec/system/sqm_application_spec.rb b/spec/system/sqm_application_spec.rb index 89ca503d..e3dbc4e7 100644 --- a/spec/system/sqm_application_spec.rb +++ b/spec/system/sqm_application_spec.rb @@ -4,7 +4,7 @@ describe 'SQM Application' do let(:district) { create(:district) } let(:school) { create(:school, district: district) } let(:academic_year) { create(:academic_year) } - let(:category) { create(:sqm_category) } + let(:category) { create(:category) } let(:measure) { create(:measure) } before :each do @@ -51,6 +51,6 @@ describe 'SQM Application' do end def browse_path - district_school_sqm_category_path(district, school, category, year: academic_year.range) + district_school_category_path(district, school, category, year: academic_year.range) end end diff --git a/spec/views/categories/edit.html.erb_spec.rb b/spec/views/categories/edit.html.erb_spec.rb deleted file mode 100644 index b18e335c..00000000 --- a/spec/views/categories/edit.html.erb_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rails_helper' - -RSpec.describe "categories/edit", type: :view do - before(:each) do - @category = assign(:category, Category.create!( - :name => "MyString", - :blurb => "MyString", - :description => "MyText", - :external_id => "MyString", - :parent_category_id => 1 - )) - end - - it "renders the edit category form" do - render - - assert_select "form[action=?][method=?]", category_path(@category), "post" do - - assert_select "input#category_name[name=?]", "category[name]" - - assert_select "input#category_blurb[name=?]", "category[blurb]" - - assert_select "textarea#category_description[name=?]", "category[description]" - - assert_select "input#category_external_id[name=?]", "category[external_id]" - - assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" - end - end -end diff --git a/spec/views/categories/index.html.erb_spec.rb b/spec/views/categories/index.html.erb_spec.rb deleted file mode 100644 index 7165985e..00000000 --- a/spec/views/categories/index.html.erb_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'rails_helper' - -RSpec.describe "categories/index", type: :view do - before(:each) do - assign(:categories, [ - Category.create!( - :name => "Name", - :blurb => "Blurb", - :description => "MyText", - :external_id => "External", - :parent_category_id => 2 - ), - Category.create!( - :name => "Name", - :blurb => "Blurb", - :description => "MyText", - :external_id => "External", - :parent_category_id => 2 - ) - ]) - end - - it "renders a list of categories" do - render(template: "categories/index") - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "Blurb".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "External".to_s, :count => 2 - assert_select "tr>td", :text => 2.to_s, :count => 2 - end -end diff --git a/spec/views/categories/new.html.erb_spec.rb b/spec/views/categories/new.html.erb_spec.rb deleted file mode 100644 index d9af1069..00000000 --- a/spec/views/categories/new.html.erb_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rails_helper' - -RSpec.describe "categories/new", type: :view do - before(:each) do - assign(:category, Category.new( - :name => "MyString", - :blurb => "MyString", - :description => "MyText", - :external_id => "MyString", - :parent_category_id => 1 - )) - end - - it "renders new category form" do - render - - assert_select "form[action=?][method=?]", categories_path, "post" do - - assert_select "input#category_name[name=?]", "category[name]" - - assert_select "input#category_blurb[name=?]", "category[blurb]" - - assert_select "textarea#category_description[name=?]", "category[description]" - - assert_select "input#category_external_id[name=?]", "category[external_id]" - - assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" - end - end -end diff --git a/spec/views/categories/show.html.erb_spec.rb b/spec/views/categories/show.html.erb_spec.rb index 042d7fc0..0acf46dd 100644 --- a/spec/views/categories/show.html.erb_spec.rb +++ b/spec/views/categories/show.html.erb_spec.rb @@ -1,20 +1,78 @@ require 'rails_helper' -RSpec.describe "categories/show", type: :view do - before(:each) do - @school = assign(:school, School.create(name: 'School')) - @category = assign(:category, Category.create!( - :name => "Category", - :description => "MyText", - :parent_category => Category.create(name: 'Teachers And The Teaching Environment') - )) - @school_category = assign(:school_category, SchoolCategory.create(school: @school, category: @category)) - end +describe 'categories/show.html.erb' do + before :each do + academic_year = create(:academic_year, range: '1989-90') + school = create(:school, name: 'Best School') + + category = create(:category, name: 'Some Category', description: 'Some description of the category') + category_presenter = CategoryPresenter.new(category: category) + + subcategory1 = create(:subcategory, category: category, name: 'A subcategory', description: 'Some description of the subcategory') + subcategory2 = create(:subcategory_with_measures, category: category, name: 'Another subcategory', description: 'Another description of the subcategory') + + measure1 = create(:measure, subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) + survey_item1 = create(:student_survey_item, measure: measure1) + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1) + + measure2 = create(:measure, name: 'The second measure name', description: 'The second measure description', subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) + student_survey_item = create(:student_survey_item, measure: measure2, prompt: "Some prompt for student data") + create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item, academic_year: academic_year, school: school, likert_score: 5) + + teacher_survey_item = create(:teacher_survey_item, measure: measure2, prompt: "Some prompt for teacher data") + create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item, academic_year: academic_year, school: school, likert_score: 3) + + admin_data_item = create(:admin_data_item, measure: measure2, description: "Some admin data item description") + assign :category, category_presenter + + assign :categories, [category_presenter] + assign :school, school + assign :district, create(:district) + assign :academic_year, academic_year - xit "renders attributes in

" do render - expect(rendered).to match(/Category/) - expect(rendered).to match(/MyText/) - expect(rendered).to match(/Teachers And The Teaching Environment/) + end + + it 'renders the category name and description' do + expect(rendered).to match /Some Category/ + expect(rendered).to match /Some description of the category/ + end + + context 'for each subcategory' do + it 'renders the subcategory name' do + expect(rendered).to match /A subcategory/ + expect(rendered).to match /Another subcategory/ + end + + it 'renders the subcategory description' do + expect(rendered).to match /Some description of the subcategory/ + expect(rendered).to match /Another description of the subcategory/ + end + + it 'renders the zone title and fill color for the gauge graph' do + expect(rendered).to match /Growth/ + expect(rendered).to match /fill-growth/ + end + end + + context 'for each measure' do + it 'renders the measure name' do + expect(rendered).to match /The second measure name/ + end + + it 'renders the measure description' do + expect(rendered).to match /The second measure description/ + end + + it 'renders a gauge graph and the zone title color' do + expect(rendered).to match /Ideal/ + expect(rendered).to match /fill-ideal/ + end + + it 'renders the prompts for survey items and admin data that make up the measure' do + expect(rendered).to match /Some prompt for student data/ + expect(rendered).to match /Some prompt for teacher data/ + expect(rendered).to match /Some admin data item description/ + end end end diff --git a/spec/views/districts/edit.html.erb_spec.rb b/spec/views/districts/edit.html.erb_spec.rb deleted file mode 100644 index 74e0df82..00000000 --- a/spec/views/districts/edit.html.erb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe "districts/edit", type: :view do - before(:each) do - @district = assign(:district, District.create!( - :name => "MyString", - :state_id => 1 - )) - end - - it "renders the edit district form" do - render - - assert_select "form[action=?][method=?]", district_path(@district), "post" do - - assert_select "input#district_name[name=?]", "district[name]" - - assert_select "input#district_state_id[name=?]", "district[state_id]" - end - end -end diff --git a/spec/views/districts/new.html.erb_spec.rb b/spec/views/districts/new.html.erb_spec.rb deleted file mode 100644 index 8e149f0e..00000000 --- a/spec/views/districts/new.html.erb_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe "districts/new", type: :view do - before(:each) do - assign(:district, District.new( - :name => "MyString", - :state_id => 1 - )) - end - - it "renders new district form" do - render - - assert_select "form[action=?][method=?]", districts_path, "post" do - - assert_select "input#district_name[name=?]", "district[name]" - - assert_select "input#district_state_id[name=?]", "district[state_id]" - end - end -end diff --git a/spec/views/districts/show.html.erb_spec.rb b/spec/views/districts/show.html.erb_spec.rb deleted file mode 100644 index 977e38d8..00000000 --- a/spec/views/districts/show.html.erb_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'rails_helper' - -RSpec.describe "districts/show", type: :view do - before(:each) do - @district = assign(:district, District.create!( - :name => "Milford", - :state_id => 2 - )) - - schools = [] - 3.times { |i| schools << @district.schools.create!(name: "School #{i}")} - @schools = assign(:schools, schools) - end - - it "renders attributes in

" do - render(template: "districts/show") - expect(rendered).to match(/Milford/) - expect(rendered).to match(/2/) - 3.times do |i| - expect(rendered).to match(/School #{i}/) - end - end -end diff --git a/spec/views/home/index.html.erb_spec.rb b/spec/views/home/index.html.erb_spec.rb index 0237c2cb..6bb30217 100644 --- a/spec/views/home/index.html.erb_spec.rb +++ b/spec/views/home/index.html.erb_spec.rb @@ -5,7 +5,7 @@ describe 'home/index.html.erb' do before :each do assign :districts, [create(:district), create(:district)] - assign :categories, [CategoryPresenter.new(category: create(:sqm_category))] + assign :categories, [CategoryPresenter.new(category: create(:category))] render end diff --git a/spec/views/legacy/categories/edit.html.erb_spec.rb b/spec/views/legacy/categories/edit.html.erb_spec.rb new file mode 100644 index 00000000..23d8fae3 --- /dev/null +++ b/spec/views/legacy/categories/edit.html.erb_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/categories/edit", type: :view do + before(:each) do + @category = assign(:category, Category.create!( + :name => "MyString", + :blurb => "MyString", + :description => "MyText", + :external_id => "MyString", + :parent_category_id => 1 + )) + end + + it "renders the edit category form" do + render + + assert_select "form[action=?][method=?]", legacy_category_path(@category), "post" do + + assert_select "input#category_name[name=?]", "category[name]" + + assert_select "input#category_blurb[name=?]", "category[blurb]" + + assert_select "textarea#category_description[name=?]", "category[description]" + + assert_select "input#category_external_id[name=?]", "category[external_id]" + + assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" + end + end + end +end diff --git a/spec/views/legacy/categories/index.html.erb_spec.rb b/spec/views/legacy/categories/index.html.erb_spec.rb new file mode 100644 index 00000000..a5d1bde3 --- /dev/null +++ b/spec/views/legacy/categories/index.html.erb_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/categories/index", type: :view do + before(:each) do + assign(:categories, [ + Category.create!( + :name => "Name", + :blurb => "Blurb", + :description => "MyText", + :external_id => "External", + :parent_category_id => 2 + ), + Category.create!( + :name => "Name", + :blurb => "Blurb", + :description => "MyText", + :external_id => "External", + :parent_category_id => 2 + ) + ]) + end + + it "renders a list of categories" do + render(template: "legacy/categories/index") + assert_select "tr>td", :text => "Name".to_s, :count => 2 + assert_select "tr>td", :text => "Blurb".to_s, :count => 2 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + assert_select "tr>td", :text => "External".to_s, :count => 2 + assert_select "tr>td", :text => 2.to_s, :count => 2 + end + end +end diff --git a/spec/views/legacy/categories/new.html.erb_spec.rb b/spec/views/legacy/categories/new.html.erb_spec.rb new file mode 100644 index 00000000..a380c6a2 --- /dev/null +++ b/spec/views/legacy/categories/new.html.erb_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/categories/new", type: :view do + before(:each) do + assign(:category, Category.new( + :name => "MyString", + :blurb => "MyString", + :description => "MyText", + :external_id => "MyString", + :parent_category_id => 1 + )) + end + + it "renders new category form" do + render + + assert_select "form[action=?][method=?]", legacy_categories_path, "post" do + + assert_select "input#category_name[name=?]", "category[name]" + + assert_select "input#category_blurb[name=?]", "category[blurb]" + + assert_select "textarea#category_description[name=?]", "category[description]" + + assert_select "input#category_external_id[name=?]", "category[external_id]" + + assert_select "input#category_parent_category_id[name=?]", "category[parent_category_id]" + end + end + end +end diff --git a/spec/views/legacy/categories/show.html.erb_spec.rb b/spec/views/legacy/categories/show.html.erb_spec.rb new file mode 100644 index 00000000..042d7fc0 --- /dev/null +++ b/spec/views/legacy/categories/show.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe "categories/show", type: :view do + before(:each) do + @school = assign(:school, School.create(name: 'School')) + @category = assign(:category, Category.create!( + :name => "Category", + :description => "MyText", + :parent_category => Category.create(name: 'Teachers And The Teaching Environment') + )) + @school_category = assign(:school_category, SchoolCategory.create(school: @school, category: @category)) + end + + xit "renders attributes in

" do + render + expect(rendered).to match(/Category/) + expect(rendered).to match(/MyText/) + expect(rendered).to match(/Teachers And The Teaching Environment/) + end +end diff --git a/spec/views/legacy/districts/edit.html.erb_spec.rb b/spec/views/legacy/districts/edit.html.erb_spec.rb new file mode 100644 index 00000000..fe65430b --- /dev/null +++ b/spec/views/legacy/districts/edit.html.erb_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/districts/edit", type: :view do + before(:each) do + @district = assign(:district, Legacy::District.create!( + :name => "MyString", + :state_id => 1 + )) + end + + it "renders the edit district form" do + render + + assert_select "form[action=?][method=?]", district_path(@district), "post" do + + assert_select "input#district_name[name=?]", "district[name]" + + assert_select "input#district_state_id[name=?]", "district[state_id]" + end + end + end +end diff --git a/spec/views/districts/index.html.erb_spec.rb b/spec/views/legacy/districts/index.html.erb_spec.rb similarity index 100% rename from spec/views/districts/index.html.erb_spec.rb rename to spec/views/legacy/districts/index.html.erb_spec.rb diff --git a/spec/views/legacy/districts/new.html.erb_spec.rb b/spec/views/legacy/districts/new.html.erb_spec.rb new file mode 100644 index 00000000..2046dc25 --- /dev/null +++ b/spec/views/legacy/districts/new.html.erb_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/districts/new", type: :view do + before(:each) do + assign(:district, Legacy::District.new( + :name => "MyString", + :state_id => 1 + )) + end + + it "renders new district form" do + render + + assert_select "form[action=?][method=?]", legacy_districts_path, "post" do + + assert_select "input#district_name[name=?]", "district[name]" + + assert_select "input#district_state_id[name=?]", "district[state_id]" + end + end + end +end diff --git a/spec/views/legacy/districts/show.html.erb_spec.rb b/spec/views/legacy/districts/show.html.erb_spec.rb new file mode 100644 index 00000000..b45c846a --- /dev/null +++ b/spec/views/legacy/districts/show.html.erb_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/districts/show", type: :view do + before(:each) do + @district = assign(:district, Legacy::District.create!( + :name => "Milford", + :state_id => 2 + )) + + schools = [] + 3.times { |i| schools << @district.schools.create!(name: "School #{i}") } + @schools = assign(:schools, schools) + end + + it "renders attributes in

" do + render(template: "legacy/districts/show") + expect(rendered).to match(/Milford/) + expect(rendered).to match(/2/) + 3.times do |i| + expect(rendered).to match(/School #{i}/) + end + end + end +end diff --git a/spec/views/legacy/question_lists/edit.html.erb_spec.rb b/spec/views/legacy/question_lists/edit.html.erb_spec.rb new file mode 100644 index 00000000..46cd59ff --- /dev/null +++ b/spec/views/legacy/question_lists/edit.html.erb_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/question_lists/edit", type: :view do + before(:each) do + @question_list = assign(:question_list, QuestionList.create!( + :name => "MyString", + :description => "MyText", + :question_ids => "MyText" + )) + end + + it "renders the edit question_list form" do + render + + assert_select "form[action=?][method=?]", legacy_question_list_path(@question_list), "post" do + + assert_select "input#question_list_name[name=?]", "question_list[name]" + + assert_select "textarea#question_list_description[name=?]", "question_list[description]" + + assert_select "input[name=?]", "question_list[question_id_array][]" + end + end + end +end diff --git a/spec/views/legacy/question_lists/index.html.erb_spec.rb b/spec/views/legacy/question_lists/index.html.erb_spec.rb new file mode 100644 index 00000000..72da37f3 --- /dev/null +++ b/spec/views/legacy/question_lists/index.html.erb_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/question_lists/index", type: :view do + before(:each) do + assign(:question_lists, [ + QuestionList.create!( + :name => "Name", + :description => "MyText", + :question_ids => "1,2,3" + ), + QuestionList.create!( + :name => "Name", + :description => "MyText", + :question_ids => "2,3,4" + ) + ]) + end + + it "renders a list of question_lists" do + render(template: "legacy/question_lists/index") + assert_select "tr>td", :text => "Name".to_s, :count => 2 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 + assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 + end + end +end diff --git a/spec/views/legacy/question_lists/new.html.erb_spec.rb b/spec/views/legacy/question_lists/new.html.erb_spec.rb new file mode 100644 index 00000000..2bb76143 --- /dev/null +++ b/spec/views/legacy/question_lists/new.html.erb_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/question_lists/new", type: :view do + before(:each) do + assign(:question_list, QuestionList.new( + :name => "MyString", + :description => "MyText", + :question_ids => "MyText" + )) + end + + it "renders new question_list form" do + render + + assert_select "form[action=?][method=?]", legacy_question_lists_path, "post" do + + assert_select "input#question_list_name[name=?]", "question_list[name]" + + assert_select "textarea#question_list_description[name=?]", "question_list[description]" + + assert_select "input[name=?]", "question_list[question_id_array][]" + end + end + end +end diff --git a/spec/views/legacy/question_lists/show.html.erb_spec.rb b/spec/views/legacy/question_lists/show.html.erb_spec.rb new file mode 100644 index 00000000..37aae354 --- /dev/null +++ b/spec/views/legacy/question_lists/show.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/question_lists/show", type: :view do + before(:each) do + @question_list = assign(:question_list, QuestionList.create!( + :name => "Name", + :description => "MyText", + :question_ids => "MyText" + )) + end + + it "renders attributes in

" do + render(template: "legacy/question_lists/show") + expect(rendered).to match(/Name/) + expect(rendered).to match(/MyText/) + expect(rendered).to match(/MyText/) + end + end +end diff --git a/spec/views/legacy/questions/edit.html.erb_spec.rb b/spec/views/legacy/questions/edit.html.erb_spec.rb new file mode 100644 index 00000000..b87ba921 --- /dev/null +++ b/spec/views/legacy/questions/edit.html.erb_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/questions/edit", type: :view do + before(:each) do + @question = assign(:question, Question.create!( + :text => "MyString", + :option1 => "MyString", + :option2 => "MyString", + :option3 => "MyString", + :option4 => "MyString", + :option5 => "MyString", + :category_id => 1 + )) + end + + it "renders the edit question form" do + render + + assert_select "form[action=?][method=?]", legacy_question_path(@question), "post" do + + assert_select "input#question_text[name=?]", "question[text]" + + assert_select "input#question_option1[name=?]", "question[option1]" + + assert_select "input#question_option2[name=?]", "question[option2]" + + assert_select "input#question_option3[name=?]", "question[option3]" + + assert_select "input#question_option4[name=?]", "question[option4]" + + assert_select "input#question_option5[name=?]", "question[option5]" + + assert_select "input#question_category_id[name=?]", "question[category_id]" + end + end + end +end diff --git a/spec/views/legacy/questions/index.html.erb_spec.rb b/spec/views/legacy/questions/index.html.erb_spec.rb new file mode 100644 index 00000000..3de2120b --- /dev/null +++ b/spec/views/legacy/questions/index.html.erb_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/questions/index", type: :view do + before(:each) do + assign(:questions, [ + Question.create!( + :text => "Text", + :option1 => "Option1", + :option2 => "Option2", + :option3 => "Option3", + :option4 => "Option4", + :option5 => "Option5", + :category => Category.create(name: "Category 1") + ), + Question.create!( + :text => "Text", + :option1 => "Option1", + :option2 => "Option2", + :option3 => "Option3", + :option4 => "Option4", + :option5 => "Option5", + :category => Category.create(name: "Category 2") + ) + ]) + end + + it "renders a list of questions" do + render(template: "legacy/questions/index") + assert_select "tr>td", :text => "Text".to_s, :count => 2 + assert_select "tr>td", :text => "Option1".to_s, :count => 2 + assert_select "tr>td", :text => "Option2".to_s, :count => 2 + assert_select "tr>td", :text => "Option3".to_s, :count => 2 + assert_select "tr>td", :text => "Option4".to_s, :count => 2 + assert_select "tr>td", :text => "Option5".to_s, :count => 2 + assert_select "tr>td", :text => "Category 1", :count => 1 + assert_select "tr>td", :text => "Category 2", :count => 1 + end + end +end diff --git a/spec/views/legacy/questions/new.html.erb_spec.rb b/spec/views/legacy/questions/new.html.erb_spec.rb new file mode 100644 index 00000000..0ff3055d --- /dev/null +++ b/spec/views/legacy/questions/new.html.erb_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/questions/new", type: :view do + before(:each) do + assign(:question, Question.new( + :text => "MyString", + :option1 => "MyString", + :option2 => "MyString", + :option3 => "MyString", + :option4 => "MyString", + :option5 => "MyString", + :category_id => 1 + )) + end + + it "renders new question form" do + render + + assert_select "form[action=?][method=?]", legacy_questions_path, "post" do + + assert_select "input#question_text[name=?]", "question[text]" + + assert_select "input#question_option1[name=?]", "question[option1]" + + assert_select "input#question_option2[name=?]", "question[option2]" + + assert_select "input#question_option3[name=?]", "question[option3]" + + assert_select "input#question_option4[name=?]", "question[option4]" + + assert_select "input#question_option5[name=?]", "question[option5]" + + assert_select "input#question_category_id[name=?]", "question[category_id]" + end + end + end +end diff --git a/spec/views/legacy/questions/show.html.erb_spec.rb b/spec/views/legacy/questions/show.html.erb_spec.rb new file mode 100644 index 00000000..b0cf501f --- /dev/null +++ b/spec/views/legacy/questions/show.html.erb_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/questions/show", type: :view do + before(:each) do + @school = assign(:school, School.create!(name: 'School')) + @question = assign(:question, Question.create!( + :text => "Question Text", + :option1 => "Option1", + :option2 => "Option2", + :option3 => "Option3", + :option4 => "Option4", + :option5 => "Option5", + :category => Category.create!(name: 'Category Name') + )) + end + + it "renders attributes in

" do + render(template: "legacy/questions/show") + expect(rendered).to match(/School/) + expect(rendered).to match(/Question Text/) + expect(rendered).to match(/Option1/) + expect(rendered).to match(/Option2/) + expect(rendered).to match(/Option3/) + expect(rendered).to match(/Option4/) + expect(rendered).to match(/Option5/) + expect(rendered).to match(/Category Name/) + end + end +end diff --git a/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb b/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb new file mode 100644 index 00000000..07ea9b63 --- /dev/null +++ b/spec/views/legacy/recipient_lists/edit.html.erb_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipient_lists/edit", type: :view do + before(:each) do + @school = assign(:school, School.create!( + :name => "School" + )) + + @recipient_list = assign(:recipient_list, RecipientList.create!( + :name => "MyString", + :description => "MyText", + :recipient_ids => "1,2,3", + :school_id => @school.id + )) + end + + it "renders the edit recipient_list form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_list_path(@school, @recipient_list), "post" do + + assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" + + assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" + + assert_select "input[name=?]", "recipient_list[recipient_id_array][]" + end + end + end +end diff --git a/spec/views/legacy/recipient_lists/index.html.erb_spec.rb b/spec/views/legacy/recipient_lists/index.html.erb_spec.rb new file mode 100644 index 00000000..2c1544fe --- /dev/null +++ b/spec/views/legacy/recipient_lists/index.html.erb_spec.rb @@ -0,0 +1,32 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipient_lists/index", type: :view do + before(:each) do + @school = assign(:school, School.create!(name: 'School')) + + assign(:recipient_lists, [ + RecipientList.create!( + :name => "Name", + :description => "MyText", + :recipient_ids => "1,2,3", + :school_id => @school.id + ), + RecipientList.create!( + :name => "Name", + :description => "MyText", + :recipient_ids => "2,3,4", + :school_id => @school.id + ) + ]) + end + + it "renders a list of recipient_lists" do + render + assert_select "tr>td", :text => "Name".to_s, :count => 2 + assert_select "tr>td", :text => "MyText".to_s, :count => 2 + assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 + assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 + end + end +end diff --git a/spec/views/legacy/recipient_lists/new.html.erb_spec.rb b/spec/views/legacy/recipient_lists/new.html.erb_spec.rb new file mode 100644 index 00000000..85cbb74f --- /dev/null +++ b/spec/views/legacy/recipient_lists/new.html.erb_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipient_lists/new", type: :view do + before(:each) do + @school = assign(:school, School.create!(name: 'School')) + + @recipient_list = assign(:recipient_list, RecipientList.new( + :name => "MyString", + :description => "MyText", + :recipient_ids => "MyText", + :school_id => @school.id + )) + end + + it "renders new recipient_list form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_lists_path(@school, @recipient_list), "post" do + assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" + + assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" + + assert_select "input[name=?]", "recipient_list[recipient_id_array][]" + end + end + end +end diff --git a/spec/views/legacy/recipient_lists/show.html.erb_spec.rb b/spec/views/legacy/recipient_lists/show.html.erb_spec.rb new file mode 100644 index 00000000..409b145a --- /dev/null +++ b/spec/views/legacy/recipient_lists/show.html.erb_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipient_lists/show", type: :view do + before(:each) do + @school = assign(:school, School.create!(name: 'School')) + + recipients = ['Jared Cosulich', 'Lauren Cosulich'].collect do |name| + @school.recipients.create!(name: name) + end + + @recipient_list = assign(:recipient_list, RecipientList.create!( + :name => "Name", + :description => "MyText", + :recipient_id_array => recipients.map(&:id), + :school_id => @school.id + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Name/) + expect(rendered).to match(/MyText/) + expect(rendered).to match(/Jared Cosulich/) + expect(rendered).to match(/Lauren Cosulich/) + end + end +end diff --git a/spec/views/legacy/recipients/edit.html.erb_spec.rb b/spec/views/legacy/recipients/edit.html.erb_spec.rb new file mode 100644 index 00000000..0ac34507 --- /dev/null +++ b/spec/views/legacy/recipients/edit.html.erb_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipients/edit", type: :view do + before(:each) do + @school = assign(:recipient, School.create!(# TODO does this need to be :school? + :name => "School" + )) + + @recipient = assign(:recipient, Recipient.create!( + :name => "MyString", + :phone => "MyString", + :gender => "MyString", + :race => "MyString", + :ethnicity => "MyString", + :home_language_id => 1, + :income => "MyString", + :opted_out => false, + :school_id => @school.id + )) + end + + it "renders the edit recipient form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_recipient_path(@school, @recipient), "post" do + + assert_select "input#recipient_name[name=?]", "recipient[name]" + + assert_select "input#recipient_phone[name=?]", "recipient[phone]" + + assert_select "input#recipient_gender[name=?]", "recipient[gender]" + + assert_select "input#recipient_race[name=?]", "recipient[race]" + + assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" + + assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" + + assert_select "input#recipient_income[name=?]", "recipient[income]" + + end + end + end +end diff --git a/spec/views/recipients/index.html.erb_spec.rb b/spec/views/legacy/recipients/index.html.erb_spec.rb similarity index 84% rename from spec/views/recipients/index.html.erb_spec.rb rename to spec/views/legacy/recipients/index.html.erb_spec.rb index 9c3af874..171328af 100644 --- a/spec/views/recipients/index.html.erb_spec.rb +++ b/spec/views/legacy/recipients/index.html.erb_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' -RSpec.describe "recipients/index", type: :view do +RSpec.describe "legacy/recipients/index", type: :view do before(:each) do - @school = assign(:school, School.create!( + @school = assign(:school, Legacy::School.create!( name: 'School' )) assign(:recipients, [ - Recipient.create!( + Legacy::Recipient.create!( :name => "Name", :phone => "Phone", :gender => "Gender", @@ -18,7 +18,7 @@ RSpec.describe "recipients/index", type: :view do :opted_out => false, :school_id => @school.id ), - Recipient.create!( + Legacy::Recipient.create!( :name => "Name", :phone => "Phone", :gender => "Gender", @@ -33,7 +33,7 @@ RSpec.describe "recipients/index", type: :view do end it "renders a list of recipients" do - render(template: "recipients/index") + render(template: "legacy/recipients/index") assert_select "tr>td", :text => "Name".to_s, :count => 2 assert_select "tr>td", :text => "Phone".to_s, :count => 2 assert_select "tr>td", :text => "Gender".to_s, :count => 2 diff --git a/spec/views/legacy/recipients/new.html.erb_spec.rb b/spec/views/legacy/recipients/new.html.erb_spec.rb new file mode 100644 index 00000000..2b566875 --- /dev/null +++ b/spec/views/legacy/recipients/new.html.erb_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/recipients/new", type: :view do + before(:each) do + @school = assign(:school, School.create!( + name: 'School' + )) + + @recipient = assign(:recipient, Recipient.new( + :name => "MyString", + :phone => "MyString", + :gender => "MyString", + :race => "MyString", + :ethnicity => "MyString", + :home_language_id => 1, + :income => "MyString", + :opted_out => false, + :school_id => @school.to_param + )) + end + + it "renders new recipient form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_recipients_path(@school, @recipient), "post" do + + assert_select "input#recipient_name[name=?]", "recipient[name]" + + assert_select "input#recipient_phone[name=?]", "recipient[phone]" + + assert_select "input#recipient_gender[name=?]", "recipient[gender]" + + assert_select "input#recipient_race[name=?]", "recipient[race]" + + assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" + + assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" + + assert_select "input#recipient_income[name=?]", "recipient[income]" + + end + end + end +end diff --git a/spec/views/recipients/show.html.erb_spec.rb b/spec/views/legacy/recipients/show.html.erb_spec.rb similarity index 80% rename from spec/views/recipients/show.html.erb_spec.rb rename to spec/views/legacy/recipients/show.html.erb_spec.rb index df4f34cf..7ef6c30b 100644 --- a/spec/views/recipients/show.html.erb_spec.rb +++ b/spec/views/legacy/recipients/show.html.erb_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -RSpec.describe "recipients/show", type: :view do +RSpec.describe "legacy/recipients/show", type: :view do before(:each) do - @school = assign(:school, School.create!( + @school = assign(:school, Legacy::School.create!( name: 'School' )) - @recipient = assign(:recipient, Recipient.create!( + @recipient = assign(:recipient, Legacy::Recipient.create!( :name => "Name", :phone => "Phone", :gender => "Gender", diff --git a/spec/views/legacy/schedules/edit.html.erb_spec.rb b/spec/views/legacy/schedules/edit.html.erb_spec.rb new file mode 100644 index 00000000..ddadb10f --- /dev/null +++ b/spec/views/legacy/schedules/edit.html.erb_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/schedules/edit", type: :view do + before(:each) do + question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) + + @school = assign(:school, School.create!(name: 'School')) + + recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) + + @schedule = assign(:schedule, Schedule.create!( + :name => "MyString", + :description => "MyText", + :school_id => @school.id, + :frequency_hours => 1, + :active => false, + :random => false, + :recipient_list_id => recipient_list.id, + :question_list_id => question_list.id + )) + end + + it "renders the edit schedule form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_schedule_path(@school, @schedule), "post" do + + assert_select "input#schedule_name[name=?]", "schedule[name]" + + assert_select "textarea#schedule_description[name=?]", "schedule[description]" + + assert_select "select[name=?]", "schedule[frequency_hours]" + + assert_select "input#schedule_active[name=?]", "schedule[active]" + + assert_select "input#schedule_random[name=?]", "schedule[random]" + + assert_select "select[name=?]", "schedule[recipient_list_id]" + + assert_select "select[name=?]", "schedule[question_list_id]" + end + end + end +end diff --git a/spec/views/legacy/schedules/new.html.erb_spec.rb b/spec/views/legacy/schedules/new.html.erb_spec.rb new file mode 100644 index 00000000..fe65e7d4 --- /dev/null +++ b/spec/views/legacy/schedules/new.html.erb_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/schedules/new", type: :view do + before(:each) do + question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) + + @school = assign(:school, School.create!(name: 'School')) + + recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) + + assign(:schedule, Schedule.new( + :name => "MyString", + :description => "MyText", + :school => @school, + :frequency_hours => 1, + :active => false, + :random => false, + :recipient_list => @recipient_list, + :question_list => @question_list + )) + end + + it "renders new schedule form" do + render + + assert_select "form[action=?][method=?]", legacy_school_legacy_schedules_path(@school), "post" do + + assert_select "input#schedule_name[name=?]", "schedule[name]" + + assert_select "textarea#schedule_description[name=?]", "schedule[description]" + + assert_select "select[name=?]", "schedule[frequency_hours]" + + assert_select "input#schedule_active[name=?]", "schedule[active]" + + assert_select "input#schedule_random[name=?]", "schedule[random]" + + assert_select "select[name=?]", "schedule[recipient_list_id]" + + assert_select "select[name=?]", "schedule[question_list_id]" + end + end + end +end diff --git a/spec/views/legacy/schedules/show.html.erb_spec.rb b/spec/views/legacy/schedules/show.html.erb_spec.rb new file mode 100644 index 00000000..4667ff5e --- /dev/null +++ b/spec/views/legacy/schedules/show.html.erb_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/schedules/show", type: :view do + before(:each) do + @question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) + + @school = assign(:school, School.create!(name: 'School')) + + @recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) + + @schedule = assign(:schedule, Schedule.create!( + :name => "Name", + :description => "MyText", + :school => @school, + :frequency_hours => 2 * 24 * 7, + :active => false, + :random => false, + :recipient_list => @recipient_list, + :question_list => @question_list + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Name/) + expect(rendered).to match(/MyText/) + expect(rendered).to match(/#{@school.name}/) + expect(rendered).to match(/Every Other Week/) + expect(rendered).to match(/false/) + expect(rendered).to match(/false/) + expect(rendered).to match(/#{@recipient_list.name}/) + expect(rendered).to match(/#{@question_list.name}/) + end + end +end diff --git a/spec/views/schools/edit.html.erb_spec.rb b/spec/views/legacy/schools/edit.html.erb_spec.rb similarity index 55% rename from spec/views/schools/edit.html.erb_spec.rb rename to spec/views/legacy/schools/edit.html.erb_spec.rb index efd2019a..624e09b8 100644 --- a/spec/views/schools/edit.html.erb_spec.rb +++ b/spec/views/legacy/schools/edit.html.erb_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' -RSpec.describe "schools/edit", type: :view do +RSpec.describe "legacy/schools/edit", type: :view do before(:each) do - @school = assign(:school, School.create!( + @school = assign(:school, Legacy::School.create!( :name => "MyString", :district_id => 1 )) @@ -11,7 +11,7 @@ RSpec.describe "schools/edit", type: :view do it "renders the edit school form" do render - assert_select "form[action=?][method=?]", school_path(@school), "post" do + assert_select "form[action=?][method=?]", legacy_school_path(@school), "post" do assert_select "input#school_name[name=?]", "school[name]" diff --git a/spec/views/legacy/schools/new.html.erb_spec.rb b/spec/views/legacy/schools/new.html.erb_spec.rb new file mode 100644 index 00000000..55b45ea5 --- /dev/null +++ b/spec/views/legacy/schools/new.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/schools/new", type: :view do + before(:each) do + assign(:school, School.new( + :name => "MyString", + :district_id => 1 + )) + end + + it "renders new school form" do + render + + assert_select "form[action=?][method=?]", legacy_schools_path, "post" do + + assert_select "input#school_name[name=?]", "school[name]" + + end + end + end +end diff --git a/spec/views/legacy/schools/show.html.erb_spec.rb b/spec/views/legacy/schools/show.html.erb_spec.rb new file mode 100644 index 00000000..b12fe4ea --- /dev/null +++ b/spec/views/legacy/schools/show.html.erb_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +module Legacy + RSpec.describe "legacy/schools/show", type: :view do + before(:each) do + @school_categories = [] + @school = assign(:school, School.create!( + :name => "School", + :district => District.create(name: 'District') + )) + end + + it "renders attributes in

" do + render(template: "legacy/schools/show") + expect(rendered).to match(/School/) + expect(rendered).to match(/District/) + end + end +end diff --git a/spec/views/question_lists/edit.html.erb_spec.rb b/spec/views/question_lists/edit.html.erb_spec.rb deleted file mode 100644 index 222db034..00000000 --- a/spec/views/question_lists/edit.html.erb_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -RSpec.describe "question_lists/edit", type: :view do - before(:each) do - @question_list = assign(:question_list, QuestionList.create!( - :name => "MyString", - :description => "MyText", - :question_ids => "MyText" - )) - end - - it "renders the edit question_list form" do - render - - assert_select "form[action=?][method=?]", question_list_path(@question_list), "post" do - - assert_select "input#question_list_name[name=?]", "question_list[name]" - - assert_select "textarea#question_list_description[name=?]", "question_list[description]" - - assert_select "input[name=?]", "question_list[question_id_array][]" - end - end -end diff --git a/spec/views/question_lists/index.html.erb_spec.rb b/spec/views/question_lists/index.html.erb_spec.rb deleted file mode 100644 index 519a4d87..00000000 --- a/spec/views/question_lists/index.html.erb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe "question_lists/index", type: :view do - before(:each) do - assign(:question_lists, [ - QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "1,2,3" - ), - QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "2,3,4" - ) - ]) - end - - it "renders a list of question_lists" do - render(template: "question_lists/index" ) - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 - assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 - end -end diff --git a/spec/views/question_lists/new.html.erb_spec.rb b/spec/views/question_lists/new.html.erb_spec.rb deleted file mode 100644 index b22fe34b..00000000 --- a/spec/views/question_lists/new.html.erb_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -RSpec.describe "question_lists/new", type: :view do - before(:each) do - assign(:question_list, QuestionList.new( - :name => "MyString", - :description => "MyText", - :question_ids => "MyText" - )) - end - - it "renders new question_list form" do - render - - assert_select "form[action=?][method=?]", question_lists_path, "post" do - - assert_select "input#question_list_name[name=?]", "question_list[name]" - - assert_select "textarea#question_list_description[name=?]", "question_list[description]" - - assert_select "input[name=?]", "question_list[question_id_array][]" - end - end -end diff --git a/spec/views/question_lists/show.html.erb_spec.rb b/spec/views/question_lists/show.html.erb_spec.rb deleted file mode 100644 index 572f88e0..00000000 --- a/spec/views/question_lists/show.html.erb_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'rails_helper' - -RSpec.describe "question_lists/show", type: :view do - before(:each) do - @question_list = assign(:question_list, QuestionList.create!( - :name => "Name", - :description => "MyText", - :question_ids => "MyText" - )) - end - - it "renders attributes in

" do - render(template: "question_lists/show") - expect(rendered).to match(/Name/) - expect(rendered).to match(/MyText/) - expect(rendered).to match(/MyText/) - end -end diff --git a/spec/views/questions/edit.html.erb_spec.rb b/spec/views/questions/edit.html.erb_spec.rb deleted file mode 100644 index ee7c0211..00000000 --- a/spec/views/questions/edit.html.erb_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rails_helper' - -RSpec.describe "questions/edit", type: :view do - before(:each) do - @question = assign(:question, Question.create!( - :text => "MyString", - :option1 => "MyString", - :option2 => "MyString", - :option3 => "MyString", - :option4 => "MyString", - :option5 => "MyString", - :category_id => 1 - )) - end - - it "renders the edit question form" do - render - - assert_select "form[action=?][method=?]", question_path(@question), "post" do - - assert_select "input#question_text[name=?]", "question[text]" - - assert_select "input#question_option1[name=?]", "question[option1]" - - assert_select "input#question_option2[name=?]", "question[option2]" - - assert_select "input#question_option3[name=?]", "question[option3]" - - assert_select "input#question_option4[name=?]", "question[option4]" - - assert_select "input#question_option5[name=?]", "question[option5]" - - assert_select "input#question_category_id[name=?]", "question[category_id]" - end - end -end diff --git a/spec/views/questions/index.html.erb_spec.rb b/spec/views/questions/index.html.erb_spec.rb deleted file mode 100644 index 99673258..00000000 --- a/spec/views/questions/index.html.erb_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'rails_helper' - -RSpec.describe "questions/index", type: :view do - before(:each) do - assign(:questions, [ - Question.create!( - :text => "Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create(name: "Category 1") - ), - Question.create!( - :text => "Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create(name: "Category 2") - ) - ]) - end - - it "renders a list of questions" do - render(template: "questions/index") - assert_select "tr>td", :text => "Text".to_s, :count => 2 - assert_select "tr>td", :text => "Option1".to_s, :count => 2 - assert_select "tr>td", :text => "Option2".to_s, :count => 2 - assert_select "tr>td", :text => "Option3".to_s, :count => 2 - assert_select "tr>td", :text => "Option4".to_s, :count => 2 - assert_select "tr>td", :text => "Option5".to_s, :count => 2 - assert_select "tr>td", :text => "Category 1", :count => 1 - assert_select "tr>td", :text => "Category 2", :count => 1 - end -end diff --git a/spec/views/questions/new.html.erb_spec.rb b/spec/views/questions/new.html.erb_spec.rb deleted file mode 100644 index c90dc16f..00000000 --- a/spec/views/questions/new.html.erb_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rails_helper' - -RSpec.describe "questions/new", type: :view do - before(:each) do - assign(:question, Question.new( - :text => "MyString", - :option1 => "MyString", - :option2 => "MyString", - :option3 => "MyString", - :option4 => "MyString", - :option5 => "MyString", - :category_id => 1 - )) - end - - it "renders new question form" do - render - - assert_select "form[action=?][method=?]", questions_path, "post" do - - assert_select "input#question_text[name=?]", "question[text]" - - assert_select "input#question_option1[name=?]", "question[option1]" - - assert_select "input#question_option2[name=?]", "question[option2]" - - assert_select "input#question_option3[name=?]", "question[option3]" - - assert_select "input#question_option4[name=?]", "question[option4]" - - assert_select "input#question_option5[name=?]", "question[option5]" - - assert_select "input#question_category_id[name=?]", "question[category_id]" - end - end -end diff --git a/spec/views/questions/show.html.erb_spec.rb b/spec/views/questions/show.html.erb_spec.rb deleted file mode 100644 index 3106e277..00000000 --- a/spec/views/questions/show.html.erb_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'rails_helper' - -RSpec.describe "questions/show", type: :view do - before(:each) do - @school = assign(:school, School.create!(name: 'School')) - @question = assign(:question, Question.create!( - :text => "Question Text", - :option1 => "Option1", - :option2 => "Option2", - :option3 => "Option3", - :option4 => "Option4", - :option5 => "Option5", - :category => Category.create!(name: 'Category Name') - )) - end - - it "renders attributes in

" do - render(template: "questions/show") - expect(rendered).to match(/School/) - expect(rendered).to match(/Question Text/) - expect(rendered).to match(/Option1/) - expect(rendered).to match(/Option2/) - expect(rendered).to match(/Option3/) - expect(rendered).to match(/Option4/) - expect(rendered).to match(/Option5/) - expect(rendered).to match(/Category Name/) - end -end diff --git a/spec/views/recipient_lists/edit.html.erb_spec.rb b/spec/views/recipient_lists/edit.html.erb_spec.rb deleted file mode 100644 index 70841308..00000000 --- a/spec/views/recipient_lists/edit.html.erb_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipient_lists/edit", type: :view do - before(:each) do - @school = assign(:school, School.create!( - :name => "School" - )) - - @recipient_list = assign(:recipient_list, RecipientList.create!( - :name => "MyString", - :description => "MyText", - :recipient_ids => "1,2,3", - :school_id => @school.id - )) - end - - it "renders the edit recipient_list form" do - render - - assert_select "form[action=?][method=?]", school_recipient_list_path(@school, @recipient_list), "post" do - - assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" - - assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" - - assert_select "input[name=?]", "recipient_list[recipient_id_array][]" - end - end -end diff --git a/spec/views/recipient_lists/index.html.erb_spec.rb b/spec/views/recipient_lists/index.html.erb_spec.rb deleted file mode 100644 index e1efd65b..00000000 --- a/spec/views/recipient_lists/index.html.erb_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipient_lists/index", type: :view do - before(:each) do - @school = assign(:school, School.create!(name: 'School')) - - assign(:recipient_lists, [ - RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_ids => "1,2,3", - :school_id => @school.id - ), - RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_ids => "2,3,4", - :school_id => @school.id - ) - ]) - end - - it "renders a list of recipient_lists" do - render - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => "1,2,3".to_s, :count => 1 - assert_select "tr>td", :text => "2,3,4".to_s, :count => 1 - end -end diff --git a/spec/views/recipient_lists/new.html.erb_spec.rb b/spec/views/recipient_lists/new.html.erb_spec.rb deleted file mode 100644 index b47a0909..00000000 --- a/spec/views/recipient_lists/new.html.erb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipient_lists/new", type: :view do - before(:each) do - @school = assign(:school, School.create!(name: 'School')) - - @recipient_list = assign(:recipient_list, RecipientList.new( - :name => "MyString", - :description => "MyText", - :recipient_ids => "MyText", - :school_id => @school.id - )) - end - - it "renders new recipient_list form" do - render - - assert_select "form[action=?][method=?]", school_recipient_lists_path(@school, @recipient_list), "post" do - assert_select "input#recipient_list_name[name=?]", "recipient_list[name]" - - assert_select "textarea#recipient_list_description[name=?]", "recipient_list[description]" - - assert_select "input[name=?]", "recipient_list[recipient_id_array][]" - end - end -end diff --git a/spec/views/recipient_lists/show.html.erb_spec.rb b/spec/views/recipient_lists/show.html.erb_spec.rb deleted file mode 100644 index 14b57efc..00000000 --- a/spec/views/recipient_lists/show.html.erb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipient_lists/show", type: :view do - before(:each) do - @school = assign(:school, School.create!(name: 'School')) - - recipients = ['Jared Cosulich', 'Lauren Cosulich'].collect do |name| - @school.recipients.create!(name: name) - end - - @recipient_list = assign(:recipient_list, RecipientList.create!( - :name => "Name", - :description => "MyText", - :recipient_id_array => recipients.map(&:id), - :school_id => @school.id - )) - end - - it "renders attributes in

" do - render - expect(rendered).to match(/Name/) - expect(rendered).to match(/MyText/) - expect(rendered).to match(/Jared Cosulich/) - expect(rendered).to match(/Lauren Cosulich/) - end -end diff --git a/spec/views/recipients/edit.html.erb_spec.rb b/spec/views/recipients/edit.html.erb_spec.rb deleted file mode 100644 index c1130661..00000000 --- a/spec/views/recipients/edit.html.erb_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipients/edit", type: :view do - before(:each) do - @school = assign(:recipient, School.create!( - :name => "School" - )) - - @recipient = assign(:recipient, Recipient.create!( - :name => "MyString", - :phone => "MyString", - :gender => "MyString", - :race => "MyString", - :ethnicity => "MyString", - :home_language_id => 1, - :income => "MyString", - :opted_out => false, - :school_id => @school.id - )) - end - - it "renders the edit recipient form" do - render - - assert_select "form[action=?][method=?]", school_recipient_path(@school, @recipient), "post" do - - assert_select "input#recipient_name[name=?]", "recipient[name]" - - assert_select "input#recipient_phone[name=?]", "recipient[phone]" - - assert_select "input#recipient_gender[name=?]", "recipient[gender]" - - assert_select "input#recipient_race[name=?]", "recipient[race]" - - assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" - - assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" - - assert_select "input#recipient_income[name=?]", "recipient[income]" - - end - end -end diff --git a/spec/views/recipients/new.html.erb_spec.rb b/spec/views/recipients/new.html.erb_spec.rb deleted file mode 100644 index a152c41a..00000000 --- a/spec/views/recipients/new.html.erb_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' - -RSpec.describe "recipients/new", type: :view do - before(:each) do - @school = assign(:school, School.create!( - name: 'School' - )) - - @recipient = assign(:recipient, Recipient.new( - :name => "MyString", - :phone => "MyString", - :gender => "MyString", - :race => "MyString", - :ethnicity => "MyString", - :home_language_id => 1, - :income => "MyString", - :opted_out => false, - :school_id => @school.to_param - )) - end - - it "renders new recipient form" do - render - - assert_select "form[action=?][method=?]", school_recipients_path(@school, @recipient), "post" do - - assert_select "input#recipient_name[name=?]", "recipient[name]" - - assert_select "input#recipient_phone[name=?]", "recipient[phone]" - - assert_select "input#recipient_gender[name=?]", "recipient[gender]" - - assert_select "input#recipient_race[name=?]", "recipient[race]" - - assert_select "input#recipient_ethnicity[name=?]", "recipient[ethnicity]" - - assert_select "input#recipient_home_language_id[name=?]", "recipient[home_language_id]" - - assert_select "input#recipient_income[name=?]", "recipient[income]" - - end - end -end diff --git a/spec/views/schedules/edit.html.erb_spec.rb b/spec/views/schedules/edit.html.erb_spec.rb deleted file mode 100644 index 84329ad3..00000000 --- a/spec/views/schedules/edit.html.erb_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' - -RSpec.describe "schedules/edit", type: :view do - before(:each) do - question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) - - @school = assign(:school, School.create!(name: 'School')) - - recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) - - @schedule = assign(:schedule, Schedule.create!( - :name => "MyString", - :description => "MyText", - :school_id => @school.id, - :frequency_hours => 1, - :active => false, - :random => false, - :recipient_list_id => recipient_list.id, - :question_list_id => question_list.id - )) - end - - it "renders the edit schedule form" do - render - - assert_select "form[action=?][method=?]", school_schedule_path(@school, @schedule), "post" do - - assert_select "input#schedule_name[name=?]", "schedule[name]" - - assert_select "textarea#schedule_description[name=?]", "schedule[description]" - - assert_select "select[name=?]", "schedule[frequency_hours]" - - assert_select "input#schedule_active[name=?]", "schedule[active]" - - assert_select "input#schedule_random[name=?]", "schedule[random]" - - assert_select "select[name=?]", "schedule[recipient_list_id]" - - assert_select "select[name=?]", "schedule[question_list_id]" - end - end -end diff --git a/spec/views/schedules/new.html.erb_spec.rb b/spec/views/schedules/new.html.erb_spec.rb deleted file mode 100644 index aa18d30b..00000000 --- a/spec/views/schedules/new.html.erb_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' - -RSpec.describe "schedules/new", type: :view do - before(:each) do - question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) - - @school = assign(:school, School.create!(name: 'School')) - - recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) - - assign(:schedule, Schedule.new( - :name => "MyString", - :description => "MyText", - :school => @school, - :frequency_hours => 1, - :active => false, - :random => false, - :recipient_list => @recipient_list, - :question_list => @question_list - )) - end - - it "renders new schedule form" do - render - - assert_select "form[action=?][method=?]", school_schedules_path(@school), "post" do - - assert_select "input#schedule_name[name=?]", "schedule[name]" - - assert_select "textarea#schedule_description[name=?]", "schedule[description]" - - assert_select "select[name=?]", "schedule[frequency_hours]" - - assert_select "input#schedule_active[name=?]", "schedule[active]" - - assert_select "input#schedule_random[name=?]", "schedule[random]" - - assert_select "select[name=?]", "schedule[recipient_list_id]" - - assert_select "select[name=?]", "schedule[question_list_id]" - end - end -end diff --git a/spec/views/schedules/show.html.erb_spec.rb b/spec/views/schedules/show.html.erb_spec.rb deleted file mode 100644 index 2a584e18..00000000 --- a/spec/views/schedules/show.html.erb_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'rails_helper' - -RSpec.describe "schedules/show", type: :view do - before(:each) do - @question_list = QuestionList.create!(name: 'Parents Questions', question_id_array: [1, 2, 3]) - - @school = assign(:school, School.create!(name: 'School')) - - @recipient_list = RecipientList.create!(name: 'Parents', recipient_id_array: [1, 2, 3], school: @school) - - @schedule = assign(:schedule, Schedule.create!( - :name => "Name", - :description => "MyText", - :school => @school, - :frequency_hours => 2 * 24 * 7, - :active => false, - :random => false, - :recipient_list => @recipient_list, - :question_list => @question_list - )) - end - - it "renders attributes in

" do - render - expect(rendered).to match(/Name/) - expect(rendered).to match(/MyText/) - expect(rendered).to match(/#{@school.name}/) - expect(rendered).to match(/Every Other Week/) - expect(rendered).to match(/false/) - expect(rendered).to match(/false/) - expect(rendered).to match(/#{@recipient_list.name}/) - expect(rendered).to match(/#{@question_list.name}/) - end -end diff --git a/spec/views/schools/new.html.erb_spec.rb b/spec/views/schools/new.html.erb_spec.rb deleted file mode 100644 index 7304621f..00000000 --- a/spec/views/schools/new.html.erb_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'rails_helper' - -RSpec.describe "schools/new", type: :view do - before(:each) do - assign(:school, School.new( - :name => "MyString", - :district_id => 1 - )) - end - - it "renders new school form" do - render - - assert_select "form[action=?][method=?]", schools_path, "post" do - - assert_select "input#school_name[name=?]", "school[name]" - - end - end -end diff --git a/spec/views/schools/show.html.erb_spec.rb b/spec/views/schools/show.html.erb_spec.rb deleted file mode 100644 index dac41399..00000000 --- a/spec/views/schools/show.html.erb_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rails_helper' - -RSpec.describe "schools/show", type: :view do - before(:each) do - @school_categories = [] - @school = assign(:school, School.create!( - :name => "School", - :district => District.create(name: 'District') - )) - end - - it "renders attributes in

" do - render(template: "schools/show") - expect(rendered).to match(/School/) - expect(rendered).to match(/District/) - end -end diff --git a/spec/views/sqm_categories/show.html.erb_spec.rb b/spec/views/sqm_categories/show.html.erb_spec.rb deleted file mode 100644 index 5bc53fa1..00000000 --- a/spec/views/sqm_categories/show.html.erb_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'rails_helper' - -describe 'sqm_categories/show.html.erb' do - before :each do - academic_year = create(:academic_year, range: '1989-90') - school = create(:school, name: 'Best School') - - category = create(:sqm_category, name: 'Some Category', description: 'Some description of the category') - category_presenter = CategoryPresenter.new(category: category) - - subcategory1 = create(:subcategory, sqm_category: category, name: 'A subcategory', description: 'Some description of the subcategory') - subcategory2 = create(:subcategory_with_measures, sqm_category: category, name: 'Another subcategory', description: 'Another description of the subcategory') - - measure1 = create(:measure, subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) - survey_item1 = create(:student_survey_item, measure: measure1) - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1) - - measure2 = create(:measure, name: 'The second measure name', description: 'The second measure description', subcategory: subcategory1, watch_low_benchmark: 1.5, growth_low_benchmark: 2.5, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.5) - student_survey_item = create(:student_survey_item, measure: measure2, prompt: "Some prompt for student data") - create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: student_survey_item, academic_year: academic_year, school: school, likert_score: 5) - - teacher_survey_item = create(:teacher_survey_item, measure: measure2, prompt: "Some prompt for teacher data") - create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: teacher_survey_item, academic_year: academic_year, school: school, likert_score: 3) - - admin_data_item = create(:admin_data_item, measure: measure2, description: "Some admin data item description") - assign :category, category_presenter - - assign :categories, [category_presenter] - assign :school, school - assign :district, create(:district) - assign :academic_year, academic_year - - render - end - - it 'renders the category name and description' do - expect(rendered).to match /Some Category/ - expect(rendered).to match /Some description of the category/ - end - - context 'for each subcategory' do - it 'renders the subcategory name' do - expect(rendered).to match /A subcategory/ - expect(rendered).to match /Another subcategory/ - end - - it 'renders the subcategory description' do - expect(rendered).to match /Some description of the subcategory/ - expect(rendered).to match /Another description of the subcategory/ - end - - it 'renders the zone title and fill color for the gauge graph' do - expect(rendered).to match /Growth/ - expect(rendered).to match /fill-growth/ - end - end - - context 'for each measure' do - it 'renders the measure name' do - expect(rendered).to match /The second measure name/ - end - - it 'renders the measure description' do - expect(rendered).to match /The second measure description/ - end - - it 'renders a gauge graph and the zone title color' do - expect(rendered).to match /Ideal/ - expect(rendered).to match /fill-ideal/ - end - - it 'renders the prompts for survey items and admin data that make up the measure' do - expect(rendered).to match /Some prompt for student data/ - expect(rendered).to match /Some prompt for teacher data/ - expect(rendered).to match /Some admin data item description/ - end - end -end