From ed4883c9fb3a989676f06ffc70604e105eeb09af Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Wed, 3 May 2017 10:14:56 -0400 Subject: [PATCH] texting change --- app/models/attempt.rb | 8 +++++--- spec/lib/tasks/survey_rake_spec.rb | 14 +++++++------- spec/models/attempt_spec.rb | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/models/attempt.rb b/app/models/attempt.rb index 89eee44a..85b14dee 100644 --- a/app/models/attempt.rb +++ b/app/models/attempt.rb @@ -22,11 +22,13 @@ class Attempt < ApplicationRecord scope :last_sent, -> { order(sent_at: :desc) } def messages - child_specific = student.present? ? "\n(for #{student.name})" : '' + child_specific = student.present? ? " (for #{student.name})" : '' + + cancel_text = "\nSkip question: skip\nStop all questions: stop" [ - #question.text, - "#{question.text}#{child_specific}\n\r#{question.option1}: Reply 1\n#{question.option2}: 2\n#{question.option3}: 3\n#{question.option4}: 4\n#{question.option5}: 5\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 diff --git a/spec/lib/tasks/survey_rake_spec.rb b/spec/lib/tasks/survey_rake_spec.rb index e323ec79..58b7cc75 100644 --- a/spec/lib/tasks/survey_rake_spec.rb +++ b/spec/lib/tasks/survey_rake_spec.rb @@ -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 + 1) + 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 @@ -214,7 +214,7 @@ describe "survey:attempt_questions" do end it 'should create one attempt per recipient regardless of students' do - expect(FakeSMS.messages.length).to eq(3) + expect(FakeSMS.messages.length).to eq(6) recipients.each do |recipient| expect(recipient.attempts.count).to eq(1) end @@ -257,7 +257,7 @@ describe "survey:attempt_questions" do end it 'should mention the students name in the text' do - expect(FakeSMS.messages[1].body).to match(/\(for Student0\)/) + expect(FakeSMS.messages[2].body).to match(/\(for Student0\)/) end it 'should not mention the students name in the text if the recipient has no student specified' do @@ -267,9 +267,9 @@ describe "survey:attempt_questions" do 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(/\(for Student0\)/) - expect(FakeSMS.messages.last.body).to match(questions.first.text) + 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 @@ -317,7 +317,7 @@ describe "survey:attempt_questions" do end it 'should create one attempt per recipient regardless of students' do - expect(FakeSMS.messages.length).to eq(3) + expect(FakeSMS.messages.length).to eq(6) recipients.each do |recipient| expect(recipient.attempts.count).to eq(1) end diff --git a/spec/models/attempt_spec.rb b/spec/models/attempt_spec.rb index c687d9af..a7a16f9a 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(1) + 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.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("Question 0:1\n\rOption 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\nSkip question: skip\nStop all questions: stop") + 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