2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ProjectAuthorization do
|
2021-12-11 22:18:48 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project1) { create(:project) }
|
|
|
|
let_it_be(:project2) { create(:project) }
|
|
|
|
let_it_be(:project3) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '.insert_authorizations' do
|
|
|
|
it 'inserts the authorizations' do
|
2017-09-10 17:25:29 +05:30
|
|
|
described_class
|
2018-11-18 11:00:15 +05:30
|
|
|
.insert_authorizations([[user.id, project1.id, Gitlab::Access::MAINTAINER]])
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(user.project_authorizations.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inserts rows in batches' do
|
|
|
|
described_class.insert_authorizations([
|
2018-11-18 11:00:15 +05:30
|
|
|
[user.id, project1.id, Gitlab::Access::MAINTAINER],
|
|
|
|
[user.id, project2.id, Gitlab::Access::MAINTAINER]
|
2017-08-17 22:00:37 +05:30
|
|
|
], 1)
|
|
|
|
|
|
|
|
expect(user.project_authorizations.count).to eq(2)
|
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
it 'skips duplicates and inserts the remaining rows without error' do
|
|
|
|
create(:project_authorization, user: user, project: project1, access_level: Gitlab::Access::MAINTAINER)
|
|
|
|
|
|
|
|
rows = [
|
|
|
|
[user.id, project1.id, Gitlab::Access::MAINTAINER],
|
|
|
|
[user.id, project2.id, Gitlab::Access::MAINTAINER],
|
|
|
|
[user.id, project3.id, Gitlab::Access::MAINTAINER]
|
|
|
|
]
|
|
|
|
|
|
|
|
described_class.insert_authorizations(rows)
|
|
|
|
|
|
|
|
expect(user.project_authorizations.pluck(:user_id, :project_id, :access_level)).to match_array(rows)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|