texting change

pull/1/head
Jared Cosulich 9 years ago
parent 986ef0086b
commit ed4883c9fb

@ -22,11 +22,13 @@ class Attempt < ApplicationRecord
scope :last_sent, -> { order(sent_at: :desc) } scope :last_sent, -> { order(sent_at: :desc) }
def messages 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}",
"#{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.option1}: Reply 1\n#{question.option2}: 2\n#{question.option3}: 3\n#{question.option4}: 4\n#{question.option5}: 5"
] ]
end end

@ -185,7 +185,7 @@ describe "survey:attempt_questions" do
end end
it 'should not send anything to anyone else' do 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[0].attempts.count).to eq(1)
expect(recipients[1].attempts.count).to eq(2) expect(recipients[1].attempts.count).to eq(2)
end end
@ -214,7 +214,7 @@ describe "survey:attempt_questions" do
end end
it 'should create one attempt per recipient regardless of students' do 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| recipients.each do |recipient|
expect(recipient.attempts.count).to eq(1) expect(recipient.attempts.count).to eq(1)
end end
@ -257,7 +257,7 @@ describe "survey:attempt_questions" do
end end
it 'should mention the students name in the text' do 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 end
it 'should not mention the students name in the text if the recipient has no student specified' do 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 it 'resends the question about the same student if not responded to' do
message_count = FakeSMS.messages.length message_count = FakeSMS.messages.length
expect{students_recipient_schedule.attempt_question}.to change{students_recipient.attempts.count}.by(0) 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.length).to eq(message_count + 2)
expect(FakeSMS.messages.last.body).to match(/\(for Student0\)/) expect(FakeSMS.messages[message_count].body).to match(questions.first.text)
expect(FakeSMS.messages.last.body).to match(questions.first.text) expect(FakeSMS.messages[message_count].body).to match(/\(for Student0\)/)
end end
it 'doesnt store any queued_question_ids when no students are present' do it 'doesnt store any queued_question_ids when no students are present' do
@ -317,7 +317,7 @@ describe "survey:attempt_questions" do
end end
it 'should create one attempt per recipient regardless of students' do 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| recipients.each do |recipient|
expect(recipient.attempts.count).to eq(1) expect(recipient.attempts.count).to eq(1)
end end

@ -92,13 +92,13 @@ RSpec.describe Attempt, type: :model do
end end
it 'should contact the Twilio API' do 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.to).to eq('111111111')
# expect(FakeSMS.messages.first.body).to eq("Question 0:1") expect(FakeSMS.messages.first.body).to eq("Question 0:1")
expect(FakeSMS.messages.last.to).to eq('111111111') 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 end
it 'should update sent_at' do it 'should update sent_at' do

Loading…
Cancel
Save