debian-mirror-gitlab/spec/workers/authorized_projects_worker_spec.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe AuthorizedProjectsWorker do
describe '#perform' do
2018-03-17 18:26:18 +05:30
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
subject(:job) { described_class.new }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it "refreshes user's authorized projects" do
2017-08-17 22:00:37 +05:30
expect_any_instance_of(User).to receive(:refresh_authorized_projects)
2018-03-17 18:26:18 +05:30
job.perform(user.id)
end
2017-08-17 22:00:37 +05:30
context "when the user is not found" do
it "does nothing" do
expect_any_instance_of(User).not_to receive(:refresh_authorized_projects)
2018-03-17 18:26:18 +05:30
job.perform(-1)
2017-08-17 22:00:37 +05:30
end
end
2020-04-08 14:13:33 +05:30
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
2017-08-17 22:00:37 +05:30
end
end