summaryrefslogtreecommitdiff
path: root/spec/requests/api/users_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-06-27 12:41:51 -0700
committerStan Hu <stanhu@gmail.com>2019-06-27 13:25:37 -0700
commitd6f20b55b8048442c06896fb5e2abed2a2e2574b (patch)
treee76b96c49f1a50c80c83b8d29fa36957200247d0 /spec/requests/api/users_spec.rb
parente29a51360fb3a2b3f96e697110fd9542d6773880 (diff)
downloadgitlab-ce-d6f20b55b8048442c06896fb5e2abed2a2e2574b.tar.gz
Add support for creating random passwords in user creation APIsh-add-force-random-password-user-api
To avoid having to specify an actual password to create users, admins can now use the `force_random_password` parameter to let Devise generate a password. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63826
Diffstat (limited to 'spec/requests/api/users_spec.rb')
-rw-r--r--spec/requests/api/users_spec.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index bab1520b960..46925daf40a 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -416,7 +416,6 @@ describe API::Users do
expect(response).to have_gitlab_http_status(201)
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq(nil)
expect(new_user.admin).to eq(true)
expect(new_user.can_create_group).to eq(true)
end
@@ -435,7 +434,6 @@ describe API::Users do
expect(response).to have_gitlab_http_status(201)
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq(nil)
expect(new_user.admin).to eq(false)
expect(new_user.can_create_group).to eq(false)
end
@@ -445,7 +443,6 @@ describe API::Users do
expect(response).to have_gitlab_http_status(201)
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq(nil)
expect(new_user.admin).to eq(false)
end
@@ -460,7 +457,6 @@ describe API::Users do
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq nil
expect(new_user.external).to be_falsy
end
@@ -470,7 +466,6 @@ describe API::Users do
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq nil
expect(new_user.external).to be_truthy
end
@@ -482,7 +477,19 @@ describe API::Users do
user_id = json_response['id']
new_user = User.find(user_id)
- expect(new_user).not_to eq(nil)
+ expect(new_user.recently_sent_password_reset?).to eq(true)
+ end
+
+ it "creates user with random password" do
+ params = attributes_for(:user, force_random_password: true, reset_password: true)
+ post api('/users', admin), params: params
+
+ expect(response).to have_gitlab_http_status(201)
+
+ user_id = json_response['id']
+ new_user = User.find(user_id)
+
+ expect(new_user.valid_password?(params[:password])).to eq(false)
expect(new_user.recently_sent_password_reset?).to eq(true)
end