From 91a16142bfcec9d5446351bfb36bd984ce406168 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 18 Jan 2016 17:32:27 +0100 Subject: [PATCH] Refactors confirm_email & uses it in user_auth_spec --- spec/features/users_auth_spec.rb | 8 +++----- spec/support/common_actions.rb | 7 ++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/features/users_auth_spec.rb b/spec/features/users_auth_spec.rb index b23d956ac..9fba71df4 100644 --- a/spec/features/users_auth_spec.rb +++ b/spec/features/users_auth_spec.rb @@ -18,8 +18,7 @@ feature 'Users' do expect(page).to have_content "You have been sent a message containing a verification link. Please click on this link to activate your account." - sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] - visit user_confirmation_path(confirmation_token: sent_token) + confirm_email expect(page).to have_content "Your account has been confirmed." end @@ -124,8 +123,7 @@ feature 'Users' do fill_in 'user_email', with: 'manueladelascarmenas@example.com' click_button 'Register' - sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] - visit user_confirmation_path(confirmation_token: sent_token) + confirm_email expect(page).to have_content "Your email address has been successfully confirmed" @@ -134,7 +132,7 @@ feature 'Users' do scenario 'Sign in, user was already signed up with OAuth' do user = create(:user, email: 'manuela@madrid.es', password: 'judgementday') - identity = create(:identity, uid: '12345', provider: 'twitter', user: user) + create(:identity, uid: '12345', provider: 'twitter', user: user) omniauth_twitter_hash = { 'provider' => 'twitter', 'uid' => '12345', 'info' => { diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 4521a1e9f..437a3c7ca 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -36,12 +36,13 @@ module CommonActions end def confirm_email - expect(page).to have_content "A message with a confirmation link has been sent to your email address." + body = ActionMailer::Base.deliveries.last.try(:body) + expect(body).to be_present - sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1] + sent_token = /.*confirmation_token=(.*)".*/.match(body.to_s)[1] visit user_confirmation_path(confirmation_token: sent_token) - expect(page).to have_content "Your email address has been successfully confirmed" + expect(page).to have_content "Your account has been confirmed" end def reset_password