From 2b450d1a833d6087f39f8e2f8c358ba50d7bcbfa Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Thu, 20 Apr 2017 21:38:41 -0400 Subject: [PATCH] testing bad response logic --- spec/controllers/attempts_controller_spec.rb | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/controllers/attempts_controller_spec.rb b/spec/controllers/attempts_controller_spec.rb index ec96ad2b..a6fc6508 100644 --- a/spec/controllers/attempts_controller_spec.rb +++ b/spec/controllers/attempts_controller_spec.rb @@ -149,4 +149,35 @@ RSpec.describe AttemptsController, type: :controller do end end end + + describe "POST #twilio with response to repeated question" do + context "with valid params" do + + let!(:recent_first_attempt) { + first_attempt.update_attributes(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