0
0
Fork 0

Combine shared-setup examples across spec/controllers/auth/* specs (#32906)

This commit is contained in:
Matt Jankowski 2024-11-15 11:07:26 -05:00 committed by GitHub
parent 54a7c1898e
commit 7bd7705f59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 121 additions and 124 deletions

View file

@ -57,29 +57,30 @@ RSpec.describe Auth::PasswordsController do
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: token } }
end
it 'redirect to sign in' do
expect(response).to redirect_to '/auth/sign_in'
end
it 'resets the password' do
expect(response)
.to redirect_to '/auth/sign_in'
it 'changes password' do
this_user = User.find(user.id)
# Change password
expect(User.find(user.id))
.to be_present
.and be_valid_password(password)
expect(this_user).to_not be_nil
expect(this_user.valid_password?(password)).to be true
end
# Deactivate session
expect(user.session_activations.count)
.to eq 0
expect { session_activation.reload }
.to raise_error(ActiveRecord::RecordNotFound)
it 'deactivates all sessions' do
expect(user.session_activations.count).to eq 0
expect { session_activation.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
# Revoke tokens
expect(Doorkeeper::AccessToken.active_for(user).count)
.to eq 0
it 'revokes all access tokens' do
expect(Doorkeeper::AccessToken.active_for(user).count).to eq 0
end
it 'removes push subscriptions' do
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count).to eq 0
expect { web_push_subscription.reload }.to raise_error(ActiveRecord::RecordNotFound)
# Remove push subs
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count)
.to eq 0
expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -88,15 +89,13 @@ RSpec.describe Auth::PasswordsController do
post :update, params: { user: { password: password, password_confirmation: password, reset_password_token: 'some_invalid_value' } }
end
it 'renders reset password' do
expect(response).to render_template(:new)
end
it 'renders reset password and retains password' do
expect(response)
.to render_template(:new)
it 'retains password' do
this_user = User.find(user.id)
expect(this_user).to_not be_nil
expect(this_user.external_or_valid_password?(user.password)).to be true
expect(User.find(user.id))
.to be_present
.and be_external_or_valid_password(user.password)
end
end
end