2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-11 12:25:17 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AuthorizedProjectsWorker do
|
|
|
|
describe '#perform' do
|
2017-08-15 12:56:04 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-03-08 16:50:55 +00:00
|
|
|
|
2017-08-15 12:56:04 +00:00
|
|
|
subject(:job) { described_class.new }
|
2016-10-11 12:25:17 +00:00
|
|
|
|
2017-08-15 12:56:04 +00:00
|
|
|
it "refreshes user's authorized projects" do
|
2016-12-06 16:31:58 +00:00
|
|
|
expect_any_instance_of(User).to receive(:refresh_authorized_projects)
|
2016-10-11 12:25:17 +00:00
|
|
|
|
2017-08-15 12:56:04 +00:00
|
|
|
job.perform(user.id)
|
|
|
|
end
|
|
|
|
|
2016-11-24 09:40:44 +00:00
|
|
|
context "when the user is not found" do
|
2016-10-11 12:25:17 +00:00
|
|
|
it "does nothing" do
|
2016-12-06 16:31:58 +00:00
|
|
|
expect_any_instance_of(User).not_to receive(:refresh_authorized_projects)
|
2016-10-11 12:25:17 +00:00
|
|
|
|
2017-08-15 12:56:04 +00:00
|
|
|
job.perform(-1)
|
2016-10-11 12:25:17 +00:00
|
|
|
end
|
|
|
|
end
|
2020-03-13 12:09:22 +00:00
|
|
|
|
|
|
|
it_behaves_like "an idempotent worker" do
|
|
|
|
let(:job_args) { user.id }
|
|
|
|
|
|
|
|
it "does not change authorizations when run twice" do
|
|
|
|
group = create(:group)
|
|
|
|
create(:project, namespace: group)
|
|
|
|
group.add_developer(user)
|
|
|
|
|
|
|
|
# Delete the authorization created by the after save hook of the member
|
|
|
|
# created above.
|
|
|
|
user.project_authorizations.delete_all
|
|
|
|
|
|
|
|
expect { job.perform(user.id) }.to change { user.project_authorizations.reload.size }.by(1)
|
|
|
|
expect { job.perform(user.id) }.not_to change { user.project_authorizations.reload.size }
|
|
|
|
end
|
|
|
|
end
|
2016-10-11 12:25:17 +00:00
|
|
|
end
|
|
|
|
end
|