Skip to content

Commit

Permalink
Fix failing rspecs (#5554)
Browse files Browse the repository at this point in the history
* Fix failing rspecs

* more tests
  • Loading branch information
farhatahmad authored Nov 21, 2023
1 parent 43db66c commit b3c3d0e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions spec/controllers/migrations/external_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
name: 'user',
email: '[email protected]',
provider: 'greenlight',
password_digest: 'fake_password_digest',
language: 'language',
role: valid_user_role.name
}
Expand Down Expand Up @@ -185,8 +186,8 @@
expect(user.role).to eq(valid_user_role)
expect(user.session_token).to be_present
expect(user.provider).to eq('greenlight')
expect(user.password_digest).to eq(valid_user_params[:password_digest])
expect(response).to have_http_status(:created)
expect(user.password_digest).to be_present
end

it 'creates the user without a password if provider is not greenlight' do
Expand Down Expand Up @@ -251,8 +252,8 @@
expect(user.role).to eq(valid_user_role)
expect(user.session_token).to be_present
expect(user.provider).to eq('greenlight')
expect(user.password_digest).to eq(valid_user_params[:password_digest])
expect(response).to have_http_status(:created)
expect(user.password_digest).to be_blank
end
end

Expand Down Expand Up @@ -296,22 +297,25 @@
end
end

context 'when providing a :provider or a :password' do
before { valid_user_params.merge!(password: 'Password1!') }
context 'when providing a valid :password_digest' do
before do
temp_user = create(:user, password: 'Password1!')
valid_user_params.merge!(password_digest: temp_user.password_digest)
end

it 'returns :created and creates a user while ignoring the extra values' do
encrypted_params = encrypt_params({ user: valid_user_params }, expires_in: 10.seconds)
expect { post :create_user, params: { v2: { encrypted_params: } } }.to change(User, :count).from(0).to(1)
expect { post :create_user, params: { v2: { encrypted_params: } } }.to change(User, :count).by(1)

user = User.take
user = User.find_by(email: valid_user_params[:email])
expect(user.name).to eq(valid_user_params[:name])
expect(user.email).to eq(valid_user_params[:email])
expect(user.language).to eq(valid_user_params[:language])
expect(user.role).to eq(valid_user_role)
expect(user.session_token).to be_present
expect(user.provider).to eq(valid_user_params[:provider])
expect(response).to have_http_status(:created)
expect(user.authenticate('Password1!')).to be_falsy
expect(user.authenticate('Password1!')).to be_truthy
end
end

Expand Down

0 comments on commit b3c3d0e

Please sign in to comment.