From f4a2c103d66c6699ad3fef843f3f5b4527795427 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Tue, 18 Apr 2017 16:32:02 -0400 Subject: [PATCH 1/7] working on sibling students --- app/models/attempt.rb | 4 +- app/models/recipient.rb | 2 + app/models/recipient_schedule.rb | 23 ++++++++- app/models/student.rb | 3 ++ data/parent_pilot_questions.json | 22 ++++---- db/migrate/20170418173141_create_students.rb | 18 +++++++ db/schema.rb | 22 ++++++-- spec/lib/tasks/survey_rake_spec.rb | 54 ++++++++++++++++++++ spec/models/student_spec.rb | 5 ++ 9 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 app/models/student.rb create mode 100644 db/migrate/20170418173141_create_students.rb create mode 100644 spec/models/student_spec.rb diff --git a/app/models/attempt.rb b/app/models/attempt.rb index 8e15d13d..5ddf65a9 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -18,8 +18,8 @@ class Attempt < ApplicationRecord def messages [ - question.text, - "#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'stop' to stop these messages." + #question.text, + "#{question.text}\r\n#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'stop' to stop these messages." ] end diff --git a/app/models/recipient.rb b/app/models/recipient.rb index aa3cfba6..dd39040a 100644 --- a/app/models/recipient.rb +++ b/app/models/recipient.rb @@ -7,6 +7,8 @@ class Recipient < ApplicationRecord has_many :recipient_schedules has_many :attempts + has_many :students + validates :name, presence: true scope :for_school, -> (school) { where(school: school) } diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb index 4ad8fd1e..55b6a313 100644 --- a/app/models/recipient_schedule.rb +++ b/app/models/recipient_schedule.rb @@ -9,12 +9,18 @@ class RecipientSchedule < ApplicationRecord validates :next_attempt_at, presence: true scope :ready, -> { where('next_attempt_at <= ?', Time.new) } - scope :for, -> (recipient_or_recipient_id) { + 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? @@ -31,11 +37,24 @@ class RecipientSchedule < ApplicationRecord return if question.nil? && unanswered_attempt.nil? + student = nil + if unanswered_attempt.nil? + if question.for_recipient_students? + students = recipient.students + student = students.first + queued = queued_question_ids.try(:split, /,/) || [] + students[1...students.length].each do + queued << "#{question.id}:#{student.id}" + end + self.queued_question_ids = queued.join(',') + end + attempt = recipient.attempts.create( schedule: schedule, recipient_schedule: self, - question: question + question: question, + student: student ) end diff --git a/app/models/student.rb b/app/models/student.rb new file mode 100644 index 00000000..1ffc5e9a --- /dev/null +++ b/app/models/student.rb @@ -0,0 +1,3 @@ +class Student < ApplicationRecord + belongs_to :recipient +end diff --git a/data/parent_pilot_questions.json b/data/parent_pilot_questions.json index 08dc0193..2b3d391b 100644 --- a/data/parent_pilot_questions.json +++ b/data/parent_pilot_questions.json @@ -1,29 +1,27 @@ [ {"category": "6-A-i", "text": "How often do you meet in person with teachers or administrators at your child's school?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, - {"category": "6-A-i", "text": "In the past year, how often have you discussed your child's school with other parents from the school?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, {"category": "6-A-i", "text": "How involved have you been in activities at your child's school?", "answers": ["Not involved at all", "A little bit involved ", "Somewhat involved", "Quite involved", "Extremely involved"]}, {"category": "6-A-i", "text": "In the past year, how often have you helped out at your child's school?", "answers": ["Almost never", "Once or twice ", "Every few months", "Monthly", "Weekly or more"]}, - {"category": "6-A-i", "text": "How confident are you in your ability to connect with other parents? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, - {"category": "6-A-i", "text": "How confident are you in your ability to make sure your child's school meets your child's learning needs? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, - {"category": "6-A-i", "text": "How confident are you in your ability to make choices about your child's schooling? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, - {"category": "6-A-i", "text": "How confident are you that you can motivate your child to try hard in school? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, - {"category": "6-A-i", "text": "How confident are you in your ability to support your child's learning at home? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, - {"category": "6-A-i", "text": "How confident are you that you can help your child develop good friendships? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, + {"category": "6-A-i", "child": true, "text": "How confident are you in your ability to make sure your child's school meets your child's learning needs? ", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, + {"category": "6-A-i", "text": "How confident are you in your ability to make choices about your child's schooling?", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, + {"category": "6-A-i", "child": true, "text": "How confident are you that you can motivate your child to try hard in school?", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, + {"category": "6-A-i", "child": true, "text": "How confident are you in your ability to support your child's learning at home?", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, + {"category": "6-A-i", "child": true, "text": "How confident are you that you can help your child develop good friendships?", "answers": ["Not confident at all", "A little bit confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, {"category": "6-A-i", "text": "Overall, how good is this school at communicating with parents?", "answers": ["Not good at all", "Slightly good", "Somewhat good", "Quite good", "Extremely good"]}, - {"category": "6-A-i", "text": "How often do you visit your child's school for an event, activity, or to volunteer? ", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, - {"category": "6-A-i", "text": "How often do you discuss your child's school with other parents from the school? ", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, + {"category": "6-A-i", "text": "How often do you visit your child's school for an event, activity, or to volunteer?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, + {"category": "6-A-i", "text": "How often do you discuss your child's school with other parents from the school?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, {"category": "6-A-i", "text": "How confident are you in your ability to connect with other parents at the school? ", "answers": ["Not confident at all", "Slightly confident", "Somewhat confident", "Quite confident", "Extremely confident"]}, {"category": "6-A-ii", "text": "How often would you like the school to host social events for families?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, {"category": "6-A-ii", "text": "How often would you like to meet with school staff to talk about helping children succeed academically?", "answers": ["Almost never", "Once or twice a year", "Every few months", "Monthly", "Weekly or more"]}, - {"category": "6-A-ii", "text": "How much would you enjoy spending an hour in your child’s classroom?", "answers": ["Would not enjoy that at all", "Would enjoy that a little bit", "Would enjoy that somewhat", "Would enjoy that quite a bit", "Would enjoy that a tremendous amount"]}, + {"category": "6-A-ii", "child": true, "text": "How much would you enjoy spending an hour in your child’s classroom?", "answers": ["Would not enjoy that at all", "Would enjoy that a little bit", "Would enjoy that somewhat", "Would enjoy that quite a bit", "Would enjoy that a tremendous amount"]}, {"category": "6-A-ii", "text": "How much would you like to receive text messages from the school about upcoming events?", "answers": ["Would not like that at all", "Would like that a little bit", "Would like that somewhat", "Would like that quite a bit", "Would like that a tremendous amount"]}, {"category": "6-A-ii", "text": "How much would you like to receive messages from the school translated into another language?", "answers": ["Would not like that at all", "Would like that a little bit", "Would like that somewhat", "Would like that quite a bit", "Would like that a tremendous amount"]}, {"category": "6-A-iii", "text": "How would you describe your sense of belonging in the school community? ", "answers": ["Very weak", "Weak", "Neutral", "Strong", "Very strong"]}, {"category": "6-A-iii", "text": "Overall, how good is this school?", "answers": ["Not good at all", "Slightly good", "Somewhat good", "Quite good", "Extremely good"]}, {"category": "6-A-iii", "text": "Overall, how welcome do you feel at this school?", "answers": ["Not welcome at all", "Slightly welcome", "Somewhat welcome", "Quite welcome", "Extremely welcome"]}, - {"category": "6-A-iii", "text": "Overall, how well do you get along well with your child’s teacher(s)?", "answers": ["Do not get along well at all", "Get along a little bit", "Get along somewhat", "Get along quite well", "Get along extremely well"]}, - {"category": "6-A-iii", "text": "Overall, how much do the teachers at this school care about your child?", "answers": ["Do not care about my child at all", "Care about my child a little bit", "Care about my child somewhat", "Care about my child quite a bit", "Care about my child a tremendous amount"]}, + {"category": "6-A-iii", "child": true, "text": "Overall, how well do you get along well with your child’s teacher(s)?", "answers": ["Do not get along well at all", "Get along a little bit", "Get along somewhat", "Get along quite well", "Get along extremely well"]}, + {"category": "6-A-iii", "child": true, "text": "Overall, how much do the teachers at this school care about your child?", "answers": ["Do not care about my child at all", "Care about my child a little bit", "Care about my child somewhat", "Care about my child quite a bit", "Care about my child a tremendous amount"]}, {"category": "6-A-iii", "text": "Overall, how much do people at this school care about your family?", "answers": ["Don’t care at all", "Care a little bit", "Care about my family somewhat ", "Care about my family quite a bit", "Care about my family a tremendous amount"]} ] diff --git a/db/migrate/20170418173141_create_students.rb b/db/migrate/20170418173141_create_students.rb new file mode 100644 index 00000000..cadc1786 --- /dev/null +++ b/db/migrate/20170418173141_create_students.rb @@ -0,0 +1,18 @@ +class CreateStudents < ActiveRecord::Migration[5.0] + def change + create_table :students do |t| + t.string :name + t.string :teacher + t.date :birthdate + t.string :gender + t.string :age + t.string :ethnicity + t.integer :recipient_id + + t.timestamps + end + + add_column :questions, :for_recipient_students, :boolean, default: false + add_column :attempts, :student_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 74c1f97e..92f50695 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170417203127) do +ActiveRecord::Schema.define(version: 20170418173141) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20170417203127) do t.datetime "updated_at", null: false t.text "twilio_details" t.string "twilio_sid" + t.integer "student_id" t.index ["twilio_sid"], name: "index_attempts_on_twilio_sid", using: :btree end @@ -67,9 +68,10 @@ ActiveRecord::Schema.define(version: 20170417203127) do t.string "option4" t.string "option5" t.integer "category_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "target_group", default: 0 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "target_group", default: 0 + t.boolean "for_recipient_students", default: false end create_table "recipient_lists", force: :cascade do |t| @@ -155,6 +157,18 @@ ActiveRecord::Schema.define(version: 20170417203127) do t.index ["slug"], name: "index_schools_on_slug", unique: true, using: :btree end + create_table "students", force: :cascade do |t| + t.string "name" + t.string "teacher" + t.date "birthdate" + t.string "gender" + t.string "age" + t.string "ethnicity" + t.integer "recipient_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "user_schools", force: :cascade do |t| t.integer "user_id" t.integer "school_id" diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 7eae2c07..0c2c25aa 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -192,6 +192,60 @@ describe "survey:attempt_questions" do end end + describe 'Multiple Students In A Family' do + + before :each do + 3.times do |i| + recipients[1].students.create(name: "Student#{i}") + end + end + + describe 'With A FOR_CHILD Question Is Asked' do + before :each do + questions.first.update_attributes(for_recipient_students: true) + date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) + Timecop.freeze(date) { subject.invoke } + end + + it 'should create one attempt per recipient regardless of students' do + expect(FakeSMS.messages.length).to eq(3) + recipients.each do |recipient| + expect(recipient.attempts.count).to eq(1) + end + end + + it 'should store queued questions when an attempt is made on first student' do + recipients.each do |recipient| + recipient_schedule = recipient.recipient_schedules.for_schedule(schedule).first + expect(recipient_schedule.queued_question_ids).to be_present + queued_question_ids = recipient_schedule.queued_question_ids.split(/,/) + expect(queued_question_ids.length).to eq(2) + expect(queued_question_ids.first).to eq("#{questions[0].id}:#{students[1].id}") + expect(queued_question_ids.last).to eq("#{questions[0].id}:#{students[2].id}") + end + end + + it 'should set the next_attempt_at to now when attempt is made on first student' + + it 'should set the next_attempt_at to now when attempt is made on second student' + + it 'should set the next_attempt_at in the future when an attempt is made on last student' + + it 'should mention the students name in the text' + end + + describe 'With A General Question Is Asked' do + before :each do + subject.invoke + end + + it 'should not queue up an questions regardless of how many students there are' + + it 'should not mention the students name in the text' + + end + end + describe 'Opted Out Recipient' do before :each do diff --git a/spec/models/student_spec.rb b/spec/models/student_spec.rb new file mode 100644 index 00000000..6928c63e --- /dev/null +++ b/spec/models/student_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Student, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 720b59d8150f9391d4d015e551531737d101a348 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Tue, 18 Apr 2017 21:20:05 -0400 Subject: [PATCH 2/7] working on siblings --- app/models/attempt.rb | 3 ++ app/models/recipient_schedule.rb | 63 ++++++++++++++++++++++++------ spec/lib/tasks/survey_rake_spec.rb | 61 +++++++++++++++++++++++------ 3 files changed, 105 insertions(+), 22 deletions(-) diff --git a/app/models/attempt.rb b/app/models/attempt.rb index 5ddf65a9..7f80d578 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -6,11 +6,14 @@ class Attempt < ApplicationRecord 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_response, -> { where('answer_index is not null or open_response_id is not null')} diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb index 55b6a313..bd95f014 100644 --- a/app/models/recipient_schedule.rb +++ b/app/models/recipient_schedule.rb @@ -31,30 +31,71 @@ class RecipientSchedule < ApplicationRecord Question.where(id: next_question_id).first 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_ids.try(:split, /,/) || [] + queued = queued_question_ids.try(:split, /,/) || [] + attempted = attempted_question_ids.try(:split, /,/) || [] + + 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_attributes( + 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.with_no_response.last return if question.nil? && unanswered_attempt.nil? - student = nil - if unanswered_attempt.nil? if question.for_recipient_students? - students = recipient.students - student = students.first - queued = queued_question_ids.try(:split, /,/) || [] - students[1...students.length].each do - queued << "#{question.id}:#{student.id}" - end - self.queued_question_ids = queued.join(',') + return attempt_question_for_recipient_students(question: question) end attempt = recipient.attempts.create( schedule: schedule, recipient_schedule: self, - question: question, - student: student + question: question ) end diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 0c2c25aa..41b89572 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -200,6 +200,11 @@ describe "survey:attempt_questions" do end end + let(:students_recipient) { recipients[1] } + let(:students_recipient_schedule) { + recipient_schedule = students_recipient.recipient_schedules.for_schedule(schedule).first + } + describe 'With A FOR_CHILD Question Is Asked' do before :each do questions.first.update_attributes(for_recipient_students: true) @@ -215,23 +220,57 @@ describe "survey:attempt_questions" do end it 'should store queued questions when an attempt is made on first student' do - recipients.each do |recipient| - recipient_schedule = recipient.recipient_schedules.for_schedule(schedule).first - expect(recipient_schedule.queued_question_ids).to be_present - queued_question_ids = recipient_schedule.queued_question_ids.split(/,/) - expect(queued_question_ids.length).to eq(2) - expect(queued_question_ids.first).to eq("#{questions[0].id}:#{students[1].id}") - expect(queued_question_ids.last).to eq("#{questions[0].id}:#{students[2].id}") - end + expect(students_recipient_schedule.queued_question_ids).to be_present + queued_question_ids = students_recipient_schedule.queued_question_ids.split(/,/) + expect(queued_question_ids.length).to eq(1) + expect(queued_question_ids.first).to eq("#{questions[0].id}") + end + + it 'should set the next_attempt_at to now when attempt is made on first student' do + recipient.attempts.last.save_response(answer_index: 3) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) + end + + it 'should set the next_attempt_at to now when attempt is made on second student' do + students_recipient.attempts.last.save_response(answer_index: 3) + expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) + expect(students_recipient_schedule.reload.queued_question_ids).to be_present + + attempt = students_recipient.attempts.last + expect(attempt.student).to eq(students_recipient.students[1]) + attempt.save_response(answer_index: 4) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) end - it 'should set the next_attempt_at to now when attempt is made on first student' + it 'should set the next_attempt_at in the future when an attempt is made on last student' do + students_recipient.attempts.last.save_response(answer_index: 3) + expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) + expect(students_recipient_schedule.reload.queued_question_ids).to be_present + + attempt = students_recipient.attempts.last + expect(attempt.student).to eq(students_recipient.students[1]) + attempt.save_response(answer_index: 4) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) - it 'should set the next_attempt_at to now when attempt is made on second student' + 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(Time.new) - it 'should set the next_attempt_at in the future when an attempt is made on last student' + attempt = students_recipient.attempts.last + expect(attempt.student).to eq(students_recipient.students[2]) + attempt.save_response(answer_index: 2) + expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(Time.new) + end it 'should mention the students name in the text' + + it 'resends the question about the same student if not responded to' + + it 'still sends when no students are present' + + it 'doesnt store any queued_question_ids when no students are present' + + it 'doesnt store any queued_question_ids when just one student is present' end describe 'With A General Question Is Asked' do From 2e796899f864d0a8e02bf3b7c276933750a4a7ce Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Wed, 19 Apr 2017 09:23:41 -0400 Subject: [PATCH 3/7] working on siblings --- app/models/recipient_list.rb | 2 +- spec/lib/tasks/survey_rake_spec.rb | 21 +++++++++++++-------- spec/models/attempt_spec.rb | 10 +++++----- spec/models/recipient_schedule_spec.rb | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/models/recipient_list.rb b/app/models/recipient_list.rb index 98a0a2df..dc4a046d 100644 --- a/app/models/recipient_list.rb +++ b/app/models/recipient_list.rb @@ -33,7 +33,7 @@ class RecipientList < ApplicationRecord new_ids = recipient_ids.split(/,/) (old_ids - new_ids).each do |deleted_recipient| schedules.each do |schedule| - schedule.recipient_schedules.for(deleted_recipient).first.destroy + schedule.recipient_schedules.for_recipient(deleted_recipient).first.destroy end end diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 41b89572..4ac40645 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -105,7 +105,7 @@ describe "survey:attempt_questions" do describe 'Second Attempts' do before :each do recipients.each do |recipient| - recipient_schedule = schedule.recipient_schedules.for(recipient).first + recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first recipient_schedule.attempt_question end end @@ -161,7 +161,7 @@ describe "survey:attempt_questions" do Timecop.freeze(now + 7) recipients.each do |recipient| - recipient_schedule = schedule.recipient_schedules.for(recipient).first + recipient_schedule = schedule.recipient_schedules.for_recipient(recipient).first recipient_schedule.attempt_question end @@ -185,7 +185,7 @@ describe "survey:attempt_questions" do end it 'should not send anything to anyone else' do - expect(FakeSMS.messages.length).to eq(@existing_message_count + 2) + expect(FakeSMS.messages.length).to eq(@existing_message_count + 1) expect(recipients[0].attempts.count).to eq(1) expect(recipients[1].attempts.count).to eq(2) end @@ -206,9 +206,10 @@ describe "survey:attempt_questions" do } 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_attributes(for_recipient_students: true) - date = ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) Timecop.freeze(date) { subject.invoke } end @@ -227,7 +228,7 @@ describe "survey:attempt_questions" do end it 'should set the next_attempt_at to now when attempt is made on first student' do - recipient.attempts.last.save_response(answer_index: 3) + students_recipient.attempts.last.save_response(answer_index: 3) expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) end @@ -249,17 +250,21 @@ describe "survey:attempt_questions" do attempt = students_recipient.attempts.last expect(attempt.student).to eq(students_recipient.students[1]) + + Timecop.freeze(date + 1.day) attempt.save_response(answer_index: 4) - expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) + expect(students_recipient_schedule.reload.next_attempt_at).to eq(date + 1.day) expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) expect(students_recipient_schedule.reload.queued_question_ids).to be_nil - expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(Time.new) + expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + (60 * 60 * schedule.frequency_hours)) attempt = students_recipient.attempts.last expect(attempt.student).to eq(students_recipient.students[2]) + + Timecop.freeze(date + 2.days) attempt.save_response(answer_index: 2) - expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(Time.new) + expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days) end it 'should mention the students name in the text' diff --git a/spec/models/attempt_spec.rb b/spec/models/attempt_spec.rb index 4c4e3776..86b04a40 100644 --- a/spec/models/attempt_spec.rb +++ b/spec/models/attempt_spec.rb @@ -92,13 +92,13 @@ RSpec.describe Attempt, type: :model do 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.length).to eq(1) + + # 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\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.") + expect(FakeSMS.messages.last.body).to eq("Question 0:1\r\nOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.") end it 'should update sent_at' do diff --git a/spec/models/recipient_schedule_spec.rb b/spec/models/recipient_schedule_spec.rb index 47c84cff..6243ac83 100644 --- a/spec/models/recipient_schedule_spec.rb +++ b/spec/models/recipient_schedule_spec.rb @@ -24,7 +24,7 @@ RSpec.describe RecipientSchedule, type: :model do frequency_hours: 24 ) end - let!(:recipient_schedule) { schedule.recipient_schedules.for(recipient).first } + let!(:recipient_schedule) { schedule.recipient_schedules.for_recipient(recipient).first } let!(:not_ready_recipient_schedule) do RecipientSchedule.create!( @@ -121,7 +121,7 @@ RSpec.describe RecipientSchedule, type: :model do date += 1.day date += 1.day if date.on_weekend? - expect(recipient_schedule.next_attempt_at).to eq(date.to_time) + expect(recipient_schedule.reload.next_attempt_at).to eq(date.to_time) end end end From 25a7035861efd786fab610c2e614676b66cd8160 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 20 Apr 2017 08:18:46 -0400 Subject: [PATCH 4/7] fixing tests --- spec/models/recipient_schedule_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/models/recipient_schedule_spec.rb b/spec/models/recipient_schedule_spec.rb index 6243ac83..dfdcb7a3 100644 --- a/spec/models/recipient_schedule_spec.rb +++ b/spec/models/recipient_schedule_spec.rb @@ -91,6 +91,11 @@ RSpec.describe RecipientSchedule, type: :model do 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 From 85d5252301db1126892248979aed4e07055f3e9b Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 20 Apr 2017 09:25:51 -0400 Subject: [PATCH 5/7] all sibling tests --- app/models/attempt.rb | 10 +++- spec/lib/tasks/survey_rake_spec.rb | 79 ++++++++++++++++++++++-------- spec/models/attempt_spec.rb | 2 +- 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/app/models/attempt.rb b/app/models/attempt.rb index 7f80d578..9f1ae468 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -20,9 +20,17 @@ class Attempt < ApplicationRecord scope :with_no_response, -> { where('answer_index is null and open_response_id is null')} def messages + if student.present? + intro = "#{student.name}'s school, " + else + intro = "Your child's school, " + end + + intro += "#{recipient.school.name}, would love your opinion on this question:" + [ #question.text, - "#{question.text}\r\n#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'stop' to stop these messages." + "#{intro}\n\r#{question.text}\n\r#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'stop' to stop these messages." ] end diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index 4ac40645..733b12ab 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -202,7 +202,7 @@ describe "survey:attempt_questions" do let(:students_recipient) { recipients[1] } let(:students_recipient_schedule) { - recipient_schedule = students_recipient.recipient_schedules.for_schedule(schedule).first + students_recipient.recipient_schedules.for_schedule(schedule).first } describe 'With A FOR_CHILD Question Is Asked' do @@ -232,18 +232,7 @@ describe "survey:attempt_questions" do expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) end - it 'should set the next_attempt_at to now when attempt is made on second student' do - students_recipient.attempts.last.save_response(answer_index: 3) - expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(1) - expect(students_recipient_schedule.reload.queued_question_ids).to be_present - - attempt = students_recipient.attempts.last - expect(attempt.student).to eq(students_recipient.students[1]) - attempt.save_response(answer_index: 4) - expect(students_recipient_schedule.reload.next_attempt_at).to eq(Time.new) - end - - it 'should set the next_attempt_at in the future when an attempt is made on last student' do + 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 @@ -267,15 +256,27 @@ describe "survey:attempt_questions" do expect(students_recipient_schedule.reload.next_attempt_at).to_not eq(date + 2.days) end - it 'should mention the students name in the text' + it 'should mention the students name in the text' do + expect(FakeSMS.messages[1].body).to match(/Student0's school, School, would love your opinion on this question/) + end - it 'resends the question about the same student if not responded to' + it 'should not mention the students name in the text if the recipient has no student specified' do + expect(FakeSMS.messages[0].body).to match(/Your child's school, School, would love your opinion on this question/) + end - it 'still sends when no students are present' + 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 + 1) + expect(FakeSMS.messages.last.body).to match(/Student0's school, School/) + expect(FakeSMS.messages.last.body).to match(questions.first.text) + end - it 'doesnt store any queued_question_ids when no students are present' + 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 - it 'doesnt store any queued_question_ids when just one student is present' end describe 'With A General Question Is Asked' do @@ -283,10 +284,48 @@ describe "survey:attempt_questions" do subject.invoke end - it 'should not queue up an questions regardless of how many students there are' + it 'should not queue up an questions regardless of how many students there are' do + expect(students_recipient_schedule.queued_question_ids).to be_nil + end + + it 'should not mention the students name in the text' do + FakeSMS.messages.each do |message| + expect(message.body).to match(/Your child's school, School, would love your opinion on this question/) + end + end + + end + end + + describe 'One Student In A Family' do - it 'should not mention the students name in the text' + before :each do + recipients[1].students.create(name: "Only Student") + end + + let(:students_recipient) { recipients[1] } + let(:students_recipient_schedule) { + students_recipient.recipient_schedules.for_schedule(schedule).first + } + + describe 'With A FOR_CHILD Question Is Asked' do + let!(:date) { ActiveSupport::TimeZone["UTC"].parse(now.strftime("%Y-%m-%dT20:00:00%z")) } + + before :each do + questions.first.update_attributes(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(3) + recipients.each do |recipient| + expect(recipient.attempts.count).to eq(1) + end + end + + it 'doesnt store any queued_question_ids' do + expect(students_recipient_schedule.queued_question_ids).to be_nil + end end end diff --git a/spec/models/attempt_spec.rb b/spec/models/attempt_spec.rb index 86b04a40..bfd2474f 100644 --- a/spec/models/attempt_spec.rb +++ b/spec/models/attempt_spec.rb @@ -98,7 +98,7 @@ RSpec.describe Attempt, type: :model do # 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("Question 0:1\r\nOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.") + expect(FakeSMS.messages.last.body).to eq("Your child's school, School, would love your opinion on this question:\n\rQuestion 0:1\n\rOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.") end it 'should update sent_at' do From 36d061fca21927afcf3ea9b669b4088cf85e8243 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 20 Apr 2017 10:29:11 -0400 Subject: [PATCH 6/7] skipping a question --- app/controllers/attempts_controller.rb | 13 ++++++--- app/models/attempt.rb | 9 +++--- app/models/question.rb | 2 +- app/models/recipient_schedule.rb | 2 +- spec/controllers/attempts_controller_spec.rb | 29 ++++++++++++++++++-- spec/models/attempt_spec.rb | 2 +- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/app/controllers/attempts_controller.rb b/app/controllers/attempts_controller.rb index f1d5fe4b..ec571f83 100644 --- a/app/controllers/attempts_controller.rb +++ b/app/controllers/attempts_controller.rb @@ -14,15 +14,20 @@ class AttemptsController < ApplicationController end attempt.save_response( - answer_index: twilio_params[:Body].to_i, + answer_index: twilio_params[:Body].to_i > 0 ? twilio_params[:Body].to_i : nil, twilio_details: twilio_params.to_h.to_yaml ) + if (twilio_params[:Body].downcase == 'skip') + render plain: 'Thank you, this question has been skipped.' + return + end + response_message = ["We've registered your response of \"#{attempt.response}\"."] - response_count = Attempt.for_question(attempt.question).for_school(recipient.school).with_response.count - if response_count > 1 - response_message << "#{response_count} people have responded to this question so far. To see all responses visit:" + 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 diff --git a/app/models/attempt.rb b/app/models/attempt.rb index 9f1ae468..c96cfc50 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -16,8 +16,9 @@ class Attempt < ApplicationRecord 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_response, -> { where('answer_index is not null or open_response_id is not null')} - scope :with_no_response, -> { where('answer_index is null and open_response_id is null')} + 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) } def messages if student.present? @@ -30,7 +31,7 @@ class Attempt < ApplicationRecord [ #question.text, - "#{intro}\n\r#{question.text}\n\r#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'stop' to stop these messages." + "#{intro}\n\r#{question.text}\n\r#{question.option1}: Reply 1\n\r#{question.option2}: Reply 2\n\r#{question.option3}: Reply 3\n\r#{question.option4}: Reply 4\n\r#{question.option5}: Reply 5\n\rReply 'skip' to skip this question.\n\rReply 'stop' to stop these messages." ] end @@ -81,7 +82,7 @@ class Attempt < ApplicationRecord def update_counts recipient.update_attributes( attempts_count: recipient.attempts.count, - responses_count: recipient.attempts.with_response.count + responses_count: recipient.attempts.with_answer.count ) end diff --git a/app/models/question.rb b/app/models/question.rb index d3a1db17..0fc232cd 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -37,7 +37,7 @@ class Question < ApplicationRecord end def aggregated_responses_for_school(school) - school_responses = attempts.for_school(school).with_response.order(id: :asc) + 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 } diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb index bd95f014..a7c1584f 100644 --- a/app/models/recipient_schedule.rb +++ b/app/models/recipient_schedule.rb @@ -83,7 +83,7 @@ class RecipientSchedule < ApplicationRecord def attempt_question(send_message: true, question: next_question) return if recipient.opted_out? - unanswered_attempt = recipient.attempts.with_no_response.last + unanswered_attempt = recipient.attempts.not_yet_responded.last return if question.nil? && unanswered_attempt.nil? diff --git a/spec/controllers/attempts_controller_spec.rb b/spec/controllers/attempts_controller_spec.rb index 11e517ac..5c9cf2a8 100644 --- a/spec/controllers/attempts_controller_spec.rb +++ b/spec/controllers/attempts_controller_spec.rb @@ -58,7 +58,7 @@ RSpec.describe AttemptsController, type: :controller do end it 'creates the first attempt with response for the question' do - expect(attempt.question.attempts.for_school(school).with_response.count).to eq(1) + expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(1) end it "updates the last attempt by recipient phone number" do @@ -86,7 +86,7 @@ RSpec.describe AttemptsController, type: :controller do end it 'updates the second attempt with response for the school' do - expect(attempt.question.attempts.for_school(school).with_response.count).to eq(2) + expect(attempt.question.attempts.for_school(school).with_answer.count).to eq(2) end it "updates the attempt from the second recipient" do @@ -120,5 +120,30 @@ RSpec.describe AttemptsController, type: :controller do expect(response.body).to eq('Thank you, you have been opted out of these messages and will no longer receive them.') end end + + context 'with skip params' do + let(:twilio_skip_attributes) { + {'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+0000000000','To' => '2223334444','Body' => 'SkIP','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 diff --git a/spec/models/attempt_spec.rb b/spec/models/attempt_spec.rb index bfd2474f..8c63903d 100644 --- a/spec/models/attempt_spec.rb +++ b/spec/models/attempt_spec.rb @@ -98,7 +98,7 @@ RSpec.describe Attempt, type: :model do # 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("Your child's school, School, would love your opinion on this question:\n\rQuestion 0:1\n\rOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'stop' to stop these messages.") + expect(FakeSMS.messages.last.body).to eq("Your child's school, School, would love your opinion on this question:\n\rQuestion 0:1\n\rOption 0:1 A: Reply 1\n\rOption 0:1 B: Reply 2\n\rOption 0:1 C: Reply 3\n\rOption 0:1 D: Reply 4\n\rOption 0:1 E: Reply 5\n\rReply 'skip' to skip this question.\n\rReply 'stop' to stop these messages.") end it 'should update sent_at' do From 4ed8aa00bbda698211c7278889299a2c489a6334 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 20 Apr 2017 10:52:19 -0400 Subject: [PATCH 7/7] adding students to seeds --- app/models/recipient_schedule.rb | 24 ++++++++++++++++++------ db/seeds.rb | 9 +++++++++ lib/tasks/data.rake | 6 ++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/models/recipient_schedule.rb b/app/models/recipient_schedule.rb index a7c1584f..55b3b3d0 100644 --- a/app/models/recipient_schedule.rb +++ b/app/models/recipient_schedule.rb @@ -31,6 +31,18 @@ class RecipientSchedule < ApplicationRecord 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? @@ -55,9 +67,9 @@ class RecipientSchedule < ApplicationRecord ) if send_message && attempt.send_message - upcoming = upcoming_question_ids.try(:split, /,/) || [] - queued = queued_question_ids.try(:split, /,/) || [] - attempted = attempted_question_ids.try(:split, /,/) || [] + upcoming = upcoming_question_id_array + queued = queued_question_id_array + attempted = attempted_question_id_array if question.present? question_id = [question.id.to_s] @@ -100,9 +112,9 @@ class RecipientSchedule < ApplicationRecord end if send_message && (unanswered_attempt || attempt).send_message - upcoming = upcoming_question_ids.try(:split, /,/) || [] - queued = queued_question_ids.try(:split, /,/) || [] - attempted = attempted_question_ids.try(:split, /,/) || [] + upcoming = upcoming_question_id_array + queued = queued_question_id_array + attempted = attempted_question_id_array if question.present? question_id = [question.id.to_s] diff --git a/db/seeds.rb b/db/seeds.rb index 0f5ee8ca..7ba325d0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -21,6 +21,15 @@ recipients = [ school.recipients.create(name: 'Lynisse Patin', phone: '19176566892'), school.recipients.create(name: 'Khemenec Patin', phone: '(347) 534-6437'), ] + +recipients[0].students.create(name: 'Abigail') +recipients[0].students.create(name: 'Clara') + +recipients[3].students.creaet(name: 'Zara') +recipients[3].students.creaet(name: 'Cole') +recipients[4].students.creaet(name: 'Zara') +recipients[4].students.creaet(name: 'Cole') + recipient_list = school.recipient_lists.create(name: 'Pilot Parent Test', recipient_id_array: recipients.map(&:id)) user.user_schools.create(school: school) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 7905df9d..db01675e 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -102,7 +102,8 @@ namespace :data do option2: question['answers'][1], option3: question['answers'][2], option4: question['answers'][3], - option5: question['answers'][4] + option5: question['answers'][4], + for_recipient_students: question['child'].present? ) else variations.each do |variation| @@ -112,7 +113,8 @@ namespace :data do option2: question['answers'][1], option3: question['answers'][2], option4: question['answers'][3], - option5: question['answers'][4] + option5: question['answers'][4], + for_recipient_students: question['child'].present? ) end end