diff options
Diffstat (limited to 'spec/presenters/packages')
-rw-r--r-- | spec/presenters/packages/nuget/packages_metadata_presenter_spec.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/spec/presenters/packages/nuget/packages_metadata_presenter_spec.rb b/spec/presenters/packages/nuget/packages_metadata_presenter_spec.rb index 39682a3311c..87a87cd8d70 100644 --- a/spec/presenters/packages/nuget/packages_metadata_presenter_spec.rb +++ b/spec/presenters/packages/nuget/packages_metadata_presenter_spec.rb @@ -2,12 +2,13 @@ require 'spec_helper' -RSpec.describe Packages::Nuget::PackagesMetadataPresenter do +RSpec.describe Packages::Nuget::PackagesMetadataPresenter, feature_category: :package_registry do include_context 'with expected presenters dependency groups' let_it_be(:project) { create(:project) } let_it_be(:packages) { create_list(:nuget_package, 5, :with_metadatum, name: 'Dummy.Package', project: project) } - let_it_be(:presenter) { described_class.new(packages) } + + let(:presenter) { described_class.new(project.packages) } describe '#count' do subject { presenter.count } @@ -28,6 +29,14 @@ RSpec.describe Packages::Nuget::PackagesMetadataPresenter do end end + it 'avoids N+1 database queries' do + control = ActiveRecord::QueryRecorder.new { described_class.new(project.packages).items } + + create(:nuget_package, :with_metadatum, name: 'Dummy.Package', project: project) + + expect { described_class.new(project.packages).items }.not_to exceed_query_limit(control) + end + it 'returns an array' do items = subject |