Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/repositories/changelog_service_spec.rb')
-rw-r--r--spec/services/repositories/changelog_service_spec.rb48
1 files changed, 47 insertions, 1 deletions
diff --git a/spec/services/repositories/changelog_service_spec.rb b/spec/services/repositories/changelog_service_spec.rb
index ddb8e7e1182..82546ae810b 100644
--- a/spec/services/repositories/changelog_service_spec.rb
+++ b/spec/services/repositories/changelog_service_spec.rb
@@ -78,7 +78,7 @@ RSpec.describe Repositories::ChangelogService do
recorder = ActiveRecord::QueryRecorder.new { service.execute(commit_to_changelog: commit_to_changelog) }
changelog = project.repository.blob_at('master', 'CHANGELOG.md')&.data
- expect(recorder.count).to eq(9)
+ expect(recorder.count).to eq(10)
expect(changelog).to include('Title 1', 'Title 2')
end
@@ -148,6 +148,52 @@ RSpec.describe Repositories::ChangelogService do
expect(changelog).to include('Title 1', 'Title 2')
end
end
+
+ it 'avoids N+1 queries', :request_store do
+ RequestStore.clear!
+
+ request = ->(to) do
+ described_class
+ .new(project, creator, version: '1.0.0', from: sha1, to: to)
+ .execute(commit_to_changelog: false)
+ end
+
+ control = ActiveRecord::QueryRecorder.new { request.call(sha2) }
+
+ RequestStore.clear!
+
+ expect { request.call(sha3) }.not_to exceed_query_limit(control.count)
+ end
+
+ context 'when one of commits does not exist' do
+ let(:service) { described_class.new(project, creator, version: '1.0.0', from: 'master', to: '54321') }
+
+ it 'raises an exception' do
+ expect { service.execute(commit_to_changelog: false) }.to raise_error(Gitlab::Changelog::Error)
+ end
+ end
+
+ context 'when commit range exceeds the limit' do
+ let(:service) { described_class.new(project, creator, version: '1.0.0', from: sha1) }
+
+ before do
+ stub_const("#{described_class.name}::COMMITS_LIMIT", 2)
+ end
+
+ it 'raises an exception' do
+ expect { service.execute(commit_to_changelog: false) }.to raise_error(Gitlab::Changelog::Error)
+ end
+
+ context 'when feature flag is off' do
+ before do
+ stub_feature_flags(changelog_commits_limitation: false)
+ end
+
+ it 'returns the changelog' do
+ expect(service.execute(commit_to_changelog: false)).to include('Title 1', 'Title 2', 'Title 3')
+ end
+ end
+ end
end
describe '#start_of_commit_range' do