Browse Source

SmsProvider class naming

get_specs_running
baarkerlounger 3 years ago
parent
commit
d415a7c8c3
  1. 14
      spec/features/two_factor_authenticatable_spec.rb
  2. 2
      spec/rails_app/app/models/user.rb
  3. 2
      spec/rails_app/lib/sms_provider.rb
  4. 2
      spec/support/sms_provider.rb

14
spec/features/two_factor_authenticatable_spec.rb

@ -12,7 +12,7 @@ feature "User of two factor authentication" do
end end
it 'does not send an SMS before the user has signed in' do it 'does not send an SMS before the user has signed in' do
expect(SMSProvider.messages).to be_empty expect(SmsProvider.messages).to be_empty
end end
it 'sends code via SMS after sign in' do it 'sends code via SMS after sign in' do
@ -21,8 +21,8 @@ feature "User of two factor authentication" do
expect(page).to have_content 'Enter the code that was sent to you' expect(page).to have_content 'Enter the code that was sent to you'
expect(SMSProvider.messages.size).to eq(1) expect(SmsProvider.messages.size).to eq(1)
message = SMSProvider.last_message message = SmsProvider.last_message
expect(message.to).to eq(user.phone_number) expect(message.to).to eq(user.phone_number)
expect(message.body).to eq(user.reload.direct_otp) expect(message.body).to eq(user.reload.direct_otp)
end end
@ -33,7 +33,7 @@ feature "User of two factor authentication" do
expect(page).to have_content('You are signed in as Marissa') expect(page).to have_content('You are signed in as Marissa')
fill_in 'code', with: SMSProvider.last_message.body fill_in 'code', with: SmsProvider.last_message.body
click_button 'Submit' click_button 'Submit'
within('.flash.notice') do within('.flash.notice') do
@ -67,7 +67,7 @@ feature "User of two factor authentication" do
expect(page).to_not have_content("Your Personal Dashboard") expect(page).to_not have_content("Your Personal Dashboard")
fill_in "code", with: SMSProvider.last_message.body fill_in "code", with: SmsProvider.last_message.body
click_button "Submit" click_button "Submit"
expect(page).to have_content("Your Personal Dashboard") expect(page).to have_content("Your Personal Dashboard")
@ -154,9 +154,9 @@ feature "User of two factor authentication" do
end end
def sms_sign_in def sms_sign_in
SMSProvider.messages.clear() SmsProvider.messages.clear()
visit user_two_factor_authentication_path visit user_two_factor_authentication_path
fill_in 'code', with: SMSProvider.last_message.body fill_in 'code', with: SmsProvider.last_message.body
click_button 'Submit' click_button 'Submit'
end end

2
spec/rails_app/app/models/user.rb

@ -5,7 +5,7 @@ class User < ActiveRecord::Base
has_one_time_password has_one_time_password
def send_two_factor_authentication_code(code) def send_two_factor_authentication_code(code)
SMSProvider.send_message(to: phone_number, body: code) SmsProvider.send_message(to: phone_number, body: code)
end end
def phone_number def phone_number

2
spec/rails_app/lib/sms_provider.rb

@ -1,6 +1,6 @@
require 'ostruct' require 'ostruct'
class SMSProvider class SmsProvider
Message = Class.new(OpenStruct) Message = Class.new(OpenStruct)
class_attribute :messages class_attribute :messages

2
spec/support/sms_provider.rb

@ -1,5 +1,5 @@
RSpec.configure do |c| RSpec.configure do |c|
c.before(:each) do c.before(:each) do
SMSProvider.messages.clear SmsProvider.messages.clear
end end
end end

Loading…
Cancel
Save