2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-20 13:23:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Projects::RepositoryLanguagesService do
|
2022-01-19 19:15:02 -05:00
|
|
|
let(:service) { described_class.new(project, project.first_owner) }
|
2019-03-20 13:23:23 -04:00
|
|
|
|
|
|
|
context 'when detected_repository_languages flag is set' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
context 'when a project is without detected programming languages' do
|
|
|
|
it 'schedules a worker and returns the empty result' do
|
2019-05-04 05:11:06 -04:00
|
|
|
expect(::DetectRepositoryLanguagesWorker).to receive(:perform_async).with(project.id)
|
2019-03-20 13:23:23 -04:00
|
|
|
expect(service.execute).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a project is with detected programming languages' do
|
|
|
|
let!(:repository_language) { create(:repository_language, project: project) }
|
|
|
|
|
|
|
|
it 'does not schedule a worker and returns the detected languages' do
|
2019-05-04 05:11:06 -04:00
|
|
|
expect(::DetectRepositoryLanguagesWorker).not_to receive(:perform_async).with(project.id)
|
2019-03-20 13:23:23 -04:00
|
|
|
|
|
|
|
languages = service.execute
|
|
|
|
|
|
|
|
expect(languages.size).to eq(1)
|
|
|
|
expect(languages.last.attributes.values).to eq(
|
|
|
|
[project.id, repository_language.programming_language_id, repository_language.share]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets detected_repository_languages flag' do
|
|
|
|
expect { service.execute }.to change(project, :detected_repository_languages).from(nil).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when detected_repository_languages flag is not set' do
|
|
|
|
let!(:repository_language) { create(:repository_language, project: project) }
|
|
|
|
let(:project) { create(:project, detected_repository_languages: true) }
|
|
|
|
let(:languages) { service.execute }
|
|
|
|
|
|
|
|
it 'returns repository languages' do
|
|
|
|
expect(languages.size).to eq(1)
|
|
|
|
expect(languages.last.attributes.values).to eq(
|
|
|
|
[project.id, repository_language.programming_language_id, repository_language.share]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|