summaryrefslogtreecommitdiff
path: root/spec/requests/api/invitations_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 15:40:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 15:40:28 +0000
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/requests/api/invitations_spec.rb
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
downloadgitlab-ce-b595cb0c1dec83de5bdee18284abe86614bed33b.tar.gz
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/requests/api/invitations_spec.rb')
-rw-r--r--spec/requests/api/invitations_spec.rb40
1 files changed, 36 insertions, 4 deletions
diff --git a/spec/requests/api/invitations_spec.rb b/spec/requests/api/invitations_spec.rb
index 64ad5733c1b..53154aef21e 100644
--- a/spec/requests/api/invitations_spec.rb
+++ b/spec/requests/api/invitations_spec.rb
@@ -69,6 +69,20 @@ RSpec.describe API::Invitations do
end
end
+ context 'when invitee is already an invited member' do
+ it 'updates the member for that email' do
+ member = source.add_developer(email)
+
+ expect do
+ post invitations_url(source, maintainer),
+ params: { email: email, access_level: Member::MAINTAINER }
+
+ expect(response).to have_gitlab_http_status(:created)
+ end.to change { member.reset.access_level }.from(Member::DEVELOPER).to(Member::MAINTAINER)
+ .and not_change { source.members.invite.count }
+ end
+ end
+
it 'adds a new member by email' do
expect do
post invitations_url(source, maintainer),
@@ -320,7 +334,7 @@ RSpec.describe API::Invitations do
let(:source) { project }
end
- it 'records queries', :request_store, :use_sql_query_cache do
+ it 'does not exceed expected queries count for emails', :request_store, :use_sql_query_cache do
post invitations_url(project, maintainer), params: { email: email, access_level: Member::DEVELOPER }
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
@@ -336,7 +350,25 @@ RSpec.describe API::Invitations do
end.not_to exceed_all_query_limit(control.count).with_threshold(unresolved_n_plus_ones)
end
- it 'records queries with secondary emails', :request_store, :use_sql_query_cache do
+ it 'does not exceed expected queries count for user_ids', :request_store, :use_sql_query_cache do
+ stranger2 = create(:user)
+
+ post invitations_url(project, maintainer), params: { user_id: stranger.id, access_level: Member::DEVELOPER }
+
+ control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ post invitations_url(project, maintainer), params: { user_id: stranger2.id, access_level: Member::DEVELOPER }
+ end
+
+ users = create_list(:user, 5)
+
+ unresolved_n_plus_ones = 136 # 54 for 1 vs 190 for 5 - currently there are 34 queries added per user
+
+ expect do
+ post invitations_url(project, maintainer), params: { user_id: users.map(&:id).join(','), access_level: Member::DEVELOPER }
+ end.not_to exceed_all_query_limit(control.count).with_threshold(unresolved_n_plus_ones)
+ end
+
+ it 'does not exceed expected queries count with secondary emails', :request_store, :use_sql_query_cache do
create(:email, email: email, user: create(:user))
post invitations_url(project, maintainer), params: { email: email, access_level: Member::DEVELOPER }
@@ -365,7 +397,7 @@ RSpec.describe API::Invitations do
let(:source) { group }
end
- it 'records queries', :request_store, :use_sql_query_cache do
+ it 'does not exceed expected queries count for emails', :request_store, :use_sql_query_cache do
post invitations_url(group, maintainer), params: { email: email, access_level: Member::DEVELOPER }
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
@@ -381,7 +413,7 @@ RSpec.describe API::Invitations do
end.not_to exceed_all_query_limit(control.count).with_threshold(unresolved_n_plus_ones)
end
- it 'records queries with secondary emails', :request_store, :use_sql_query_cache do
+ it 'does not exceed expected queries count for secondary emails', :request_store, :use_sql_query_cache do
create(:email, email: email, user: create(:user))
post invitations_url(group, maintainer), params: { email: email, access_level: Member::DEVELOPER }