From c516be46681bef85c207726961323d37b409ded3 Mon Sep 17 00:00:00 2001 From: Moncef Belyamani Date: Mon, 4 Dec 2017 15:38:18 -0500 Subject: [PATCH] Capitalize TwiML tags; ignore slim-lint offense **Why**: TwiML tags are case-sensitive according to Twilio documentation, so we need to ignore the `TagCase` slim-lint offense for `app/views/voice/otp/show.xml.slim`. For some reason, using the exclude option under `TagCase` doesn't work, so I had to ignore the file globally. --- .slim-lint.yml | 7 ++++- app/views/voice/otp/show.xml.slim | 8 ++--- spec/controllers/voice/otp_controller_spec.rb | 30 +++++++++---------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.slim-lint.yml b/.slim-lint.yml index 611aae3da75..85f16120b2e 100644 --- a/.slim-lint.yml +++ b/.slim-lint.yml @@ -1,6 +1,11 @@ exclude: - 'app/views/shared/_flashes.html.slim' - 'app/views/shared/_null.html.slim' + # The file below is ignored globally because for some reason, + # excluding it under the `TagCase` section below doesn't work. + # We need to exclude this file because slim-lint wants all XML + # tags to be lowercase, but Twilio requires them to be uppercase. + - 'app/views/voice/otp/show.xml.slim' linters: LineLength: max: 100 @@ -9,6 +14,6 @@ linters: - 'app/views/pages/privacy_policy.html.slim' TagCase: exclude: - - 'app/views/voice/otp/show.xml.slim' + - 'app/views/voice/otp/show.xml.slim' RuboCop: enabled: true diff --git a/app/views/voice/otp/show.xml.slim b/app/views/voice/otp/show.xml.slim index 86086e2b3c1..0e09ddbfb73 100644 --- a/app/views/voice/otp/show.xml.slim +++ b/app/views/voice/otp/show.xml.slim @@ -1,9 +1,9 @@ doctype xml response - say language="#{I18n.locale}" + Say language="#{I18n.locale}" = @message - if @action_url - gather numDigits="1" action=@action_url - say language="#{I18n.locale}" + Gather numDigits="1" action=@action_url + Say language="#{I18n.locale}" = t('voice.otp.repeat_instructions') - hangup / + Hangup / diff --git a/spec/controllers/voice/otp_controller_spec.rb b/spec/controllers/voice/otp_controller_spec.rb index 04548cce242..419f7c78c50 100644 --- a/spec/controllers/voice/otp_controller_spec.rb +++ b/spec/controllers/voice/otp_controller_spec.rb @@ -28,11 +28,11 @@ let(:code) { '1234' } let(:encrypted_code) { cipher.encrypt(code) } - it 'tells Twilio to the code with pauses in between' do + it 'tells Twilio to the code with pauses in between' do action doc = Nokogiri::XML(response.body) - say = doc.css('say').first + say = doc.css('Say').first expect(say.text).to include('1, 2, 3, 4,') end @@ -40,7 +40,7 @@ action doc = Nokogiri::XML(response.body) - say = doc.css('say').first + say = doc.css('Say').first expect(say[:language]).to eq('en') end @@ -52,16 +52,16 @@ action doc = Nokogiri::XML(response.body) - say = doc.css('say').first + say = doc.css('Say').first expect(say[:language]).to eq('es') end - it 'passes locale into the action URL' do + it 'passes locale into the action URL' do action doc = Nokogiri::XML(response.body) - gather = doc.css('gather').first + gather = doc.css('Gather').first params = URIService.params(gather[:action]) expect(params[:locale]).to eq('es') @@ -75,36 +75,36 @@ action doc = Nokogiri::XML(response.body) - say = doc.css('say').first + say = doc.css('Say').first expect(say[:language]).to eq('fr') end - it 'passes locale into the action URL' do + it 'passes locale into the action URL' do action doc = Nokogiri::XML(response.body) - gather = doc.css('gather').first + gather = doc.css('Gather').first params = URIService.params(gather[:action]) expect(params[:locale]).to eq('fr') end end - it 'has a with instructions to repeat with a repeat_count' do + it 'has a with instructions to repeat with a repeat_count' do action doc = Nokogiri::XML(response.body) - gather = doc.css('gather').first + gather = doc.css('Gather').first expect(gather[:action]).to include('repeat_count=4') end - it 'puts the encrypted code in the action' do + it 'puts the encrypted code in the action' do action doc = Nokogiri::XML(response.body) - gather = doc.css('gather').first + gather = doc.css('Gather').first params = URIService.params(gather[:action]) expect(cipher.decrypt(params[:encrypted_code])).to eq(code) @@ -113,11 +113,11 @@ context 'when repeat_count counts down to 1' do let(:repeat_count) { 1 } - it 'does not have a in the response' do + it 'does not have a in the response' do action doc = Nokogiri::XML(response.body) - expect(doc.css('gather')).to be_empty + expect(doc.css('Gather')).to be_empty end end end