changing from cancel to stop

pull/1/head
Jared Cosulich 9 years ago
parent cc82f74525
commit 5c3ceb3687

@ -5,7 +5,7 @@ class AttemptsController < ApplicationController
def twilio def twilio
attempt = Recipient.where(phone: twilio_params['From']).first.attempts.last attempt = Recipient.where(phone: twilio_params['From']).first.attempts.last
if (twilio_params[:Body].downcase == 'cancel') if (twilio_params[:Body].downcase == 'stop')
attempt.recipient.update_attributes(opted_out: true) attempt.recipient.update_attributes(opted_out: true)
attempt.update_attributes(twilio_details: twilio_params.to_h.to_yaml) attempt.update_attributes(twilio_details: twilio_params.to_h.to_yaml)
render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.' render plain: 'Thank you, you have been opted out of these messages and will no longer receive them.'
@ -17,7 +17,7 @@ class AttemptsController < ApplicationController
responded_at: Time.new, responded_at: Time.new,
twilio_details: twilio_params.to_h.to_yaml twilio_details: twilio_params.to_h.to_yaml
) )
render plain: """We've registered your response of #{attempt.response}. render plain: """We've registered your response of \"#{attempt.response}\".
To see how others responded to the same question please visit To see how others responded to the same question please visit
#{school_category_url(attempt.recipient.school, attempt.question.category)}""" #{school_category_url(attempt.recipient.school, attempt.question.category)}"""
end end

@ -17,7 +17,7 @@ class Attempt < ApplicationRecord
def messages def messages
[ [
question.text, 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 'cancel' to stop these messages." "#{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 end

@ -48,15 +48,15 @@ RSpec.describe AttemptsController, type: :controller do
it "sends back a message" do it "sends back a message" do
post :twilio, params: twilio_attributes post :twilio, params: twilio_attributes
expect(response.body).to eq """We\'ve registered your response of Option 0:1 C. expect(response.body).to eq """We\'ve registered your response of \"Option 0:1 C\".
To see how others responded to the same question please visit To see how others responded to the same question please visit
http://test.host/schools/school/categories/category""" http://test.host/schools/school/categories/category"""
end end
end end
context 'with cancel params' do context 'with stop params' do
let(:twilio_attributes) { let(:twilio_attributes) {
{'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+11231231234','To' => '2223334444','Body' => 'cAnCel','NumMedia' => '0'} {'MessageSid' => 'ewuefhwieuhfweiuhfewiuhf','AccountSid' => 'wefiuwhefuwehfuwefinwefw','MessagingServiceSid' => 'efwneufhwuefhweiufhiuewhf','From' => '+11231231234','To' => '2223334444','Body' => 'sToP','NumMedia' => '0'}
} }
it "updates the last attempt by recipient phone number" do it "updates the last attempt by recipient phone number" do

@ -94,7 +94,7 @@ RSpec.describe Attempt, type: :model do
it 'should contact the Twilio API' do it 'should contact the Twilio API' do
expect(FakeSMS.messages.length).to eq(2) expect(FakeSMS.messages.length).to eq(2)
expect(FakeSMS.messages.first.body).to eq("Question 0:1") expect(FakeSMS.messages.first.body).to eq("Question 0:1")
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 'cancel' to stop these messages.") 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.first.to).to eq('1111111111') expect(FakeSMS.messages.first.to).to eq('1111111111')
end end

Loading…
Cancel
Save