2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-06 11:31:58 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ProjectAuthorization do
|
2021-11-12 07:10:27 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project1) { create(:project) }
|
|
|
|
let_it_be(:project2) { create(:project) }
|
|
|
|
let_it_be(:project3) { create(:project) }
|
2016-12-06 11:31:58 -05:00
|
|
|
|
|
|
|
describe '.insert_authorizations' do
|
|
|
|
it 'inserts the authorizations' do
|
2017-06-21 09:48:12 -04:00
|
|
|
described_class
|
2018-07-11 10:36:08 -04:00
|
|
|
.insert_authorizations([[user.id, project1.id, Gitlab::Access::MAINTAINER]])
|
2016-12-06 11:31:58 -05:00
|
|
|
|
|
|
|
expect(user.project_authorizations.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inserts rows in batches' do
|
|
|
|
described_class.insert_authorizations([
|
2018-07-11 10:36:08 -04:00
|
|
|
[user.id, project1.id, Gitlab::Access::MAINTAINER],
|
|
|
|
[user.id, project2.id, Gitlab::Access::MAINTAINER]
|
2016-12-06 11:31:58 -05:00
|
|
|
], 1)
|
|
|
|
|
|
|
|
expect(user.project_authorizations.count).to eq(2)
|
|
|
|
end
|
2021-11-12 07:10:27 -05:00
|
|
|
|
|
|
|
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
|
2016-12-06 11:31:58 -05:00
|
|
|
end
|
|
|
|
end
|