diff options
author | David Yip <yipdw@member.fsf.org> | 2018-04-12 03:30:57 -0500 |
---|---|---|
committer | David Yip <yipdw@member.fsf.org> | 2018-04-12 03:30:57 -0500 |
commit | a817f084eafaf5527445c29ab1d68f42b1a2872f (patch) | |
tree | f146e6c8ff958d60804e33e40e1970784f5b7b90 /spec/controllers | |
parent | eb72c3398cd70c6b595fae5a0cb6730a3e49bd61 (diff) | |
parent | 8e88a18316d45a459a31d67487bccc247592d187 (diff) |
Merge remote-tracking branch 'tootsuite/master'
Conflicts: app/controllers/statuses_controller.rb
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/auth/sessions_controller_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index 88f0a4734..d5fed17d6 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -48,6 +48,57 @@ RSpec.describe Auth::SessionsController, type: :controller do request.env['devise.mapping'] = Devise.mappings[:user] end + context 'using PAM authentication' do + context 'using a valid password' do + before do + post :create, params: { user: { email: "pam_user1", password: '123456' } } + end + + it 'redirects to home' do + expect(response).to redirect_to(root_path) + end + + it 'logs the user in' do + expect(controller.current_user).to be_instance_of(User) + end + end + + context 'using an invalid password' do + before do + post :create, params: { user: { email: "pam_user1", password: 'WRONGPW' } } + end + + it 'shows a login error' do + expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email') + end + + it "doesn't log the user in" do + expect(controller.current_user).to be_nil + end + end + + context 'using a valid email and existing user' do + let(:user) do + account = Fabricate.build(:account, username: 'pam_user1') + account.save!(validate: false) + user = Fabricate(:user, email: 'pam@example.com', password: nil, account: account) + user + end + + before do + post :create, params: { user: { email: user.email, password: '123456' } } + end + + it 'redirects to home' do + expect(response).to redirect_to(root_path) + end + + it 'logs the user in' do + expect(controller.current_user).to eq user + end + end + end + context 'using password authentication' do let(:user) { Fabricate(:user, email: 'foo@bar.com', password: 'abcdefgh') } |