Skip to content

Commit

Permalink
Capitalize TwiML tags; ignore slim-lint offense
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
monfresh committed Dec 4, 2017
1 parent 216ef37 commit c516be4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
7 changes: 6 additions & 1 deletion .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
Expand All @@ -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
8 changes: 4 additions & 4 deletions 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 /
30 changes: 15 additions & 15 deletions spec/controllers/voice/otp_controller_spec.rb
Expand Up @@ -28,19 +28,19 @@
let(:code) { '1234' }
let(:encrypted_code) { cipher.encrypt(code) }

it 'tells Twilio to <say> the code with pauses in between' do
it 'tells Twilio to <Say> 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

it 'sets the lang attribute to english' do
action

doc = Nokogiri::XML(response.body)
say = doc.css('say').first
say = doc.css('Say').first

expect(say[:language]).to eq('en')
end
Expand All @@ -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 <gather> action URL' do
it 'passes locale into the <Gather> 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')
Expand All @@ -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 <gather> action URL' do
it 'passes locale into the <Gather> 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 <gather> with instructions to repeat with a repeat_count' do
it 'has a <Gather> 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 <gather> action' do
it 'puts the encrypted code in the <Gather> 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)
Expand All @@ -113,11 +113,11 @@
context 'when repeat_count counts down to 1' do
let(:repeat_count) { 1 }

it 'does not have a <gather> in the response' do
it 'does not have a <Gather> 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
Expand Down

0 comments on commit c516be4

Please sign in to comment.