Commit 465d69012d31b71eeb8825dd83f4845069eb3112
1 parent
483cc5f9
Exists in
master
use username field if configured
Showing
2 changed files
with
21 additions
and
4 deletions
Show diff stats
spec/acceptance/acceptance_helper.rb
@@ -22,7 +22,13 @@ end | @@ -22,7 +22,13 @@ end | ||
22 | 22 | ||
23 | def log_in(user) | 23 | def log_in(user) |
24 | visit '/' | 24 | visit '/' |
25 | - fill_in :user_email, with: user.email | 25 | + |
26 | + if Errbit::Config.user_has_username | ||
27 | + fill_in :user_username, with: user.username | ||
28 | + else | ||
29 | + fill_in :user_email, with: user.email | ||
30 | + end | ||
31 | + | ||
26 | fill_in :user_password, with: 'password' | 32 | fill_in :user_password, with: 'password' |
27 | click_on I18n.t('devise.sessions.new.sign_in') | 33 | click_on I18n.t('devise.sessions.new.sign_in') |
28 | end | 34 | end |
spec/controllers/devise_sessions_controller_spec.rb
@@ -10,13 +10,24 @@ describe Devise::SessionsController, type: 'controller' do | @@ -10,13 +10,24 @@ describe Devise::SessionsController, type: 'controller' do | ||
10 | let(:user) { Fabricate(:user) } | 10 | let(:user) { Fabricate(:user) } |
11 | 11 | ||
12 | it 'redirects to app index page if there are no apps for the user' do | 12 | it 'redirects to app index page if there are no apps for the user' do |
13 | - post :create, user: { 'email' => user.email, 'password' => user.password } | 13 | + details = { 'email' => user.email, 'password' => user.password } |
14 | + if Errbit::Config.user_has_username | ||
15 | + details['username'] = user.username | ||
16 | + end | ||
17 | + | ||
18 | + post :create, user: details | ||
14 | expect(response).to redirect_to(root_path) | 19 | expect(response).to redirect_to(root_path) |
15 | end | 20 | end |
16 | 21 | ||
17 | it 'displays a friendly error when credentials are invalid' do | 22 | it 'displays a friendly error when credentials are invalid' do |
18 | - post :create, user: { 'email' => 'whatever', 'password' => 'somethinginvalid' } | ||
19 | - expect(request.flash["alert"]).to eq(I18n.t 'devise.failure.user.email_invalid') | 23 | + details = { 'email' => 'whatever', 'password' => 'somethinginvalid' } |
24 | + msg = I18n.t('devise.failure.user.email_invalid') | ||
25 | + if Errbit::Config.user_has_username | ||
26 | + details['username'] = 'somethinginvalid' | ||
27 | + msg = I18n.t('devise.failure.user.username_invalid') | ||
28 | + end | ||
29 | + post :create, user: details | ||
30 | + expect(request.flash["alert"]).to eq(msg) | ||
20 | end | 31 | end |
21 | end | 32 | end |
22 | end | 33 | end |