debian-mirror-gitlab/spec/services/projects/repository_languages_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Projects::RepositoryLanguagesService, feature_category: :source_code_management do
2022-03-02 08:16:31 +05:30
let(:service) { described_class.new(project, project.first_owner) }
2019-07-07 11:18:12 +05:30
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