2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::RepositoryLanguagesService do
|
|
|
|
let(:service) { described_class.new(project, project.owner) }
|
|
|
|
|
|
|
|
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-09-04 21:01:54 +05:30
|
|
|
expect(::DetectRepositoryLanguagesWorker).to receive(:perform_async).with(project.id)
|
2019-07-07 11:18:12 +05:30
|
|
|
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-09-04 21:01:54 +05:30
|
|
|
expect(::DetectRepositoryLanguagesWorker).not_to receive(:perform_async).with(project.id)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
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
|