Commit 46476acf authored by Tetiana Chupryna's avatar Tetiana Chupryna

User proper stubs for testing

parent e13ab34a
......@@ -239,28 +239,22 @@ RSpec.describe Namespace do
create(:project, namespace: namespace, container_repositories: repositories)
stub_container_registry_config(enabled: true)
stub_container_registry_tags(repository: :any, tags: ['tag'])
end
it 'finds tags' do
allow_next_found_instance_of(ContainerRepository) do |repository|
allow(repository).to receive(:has_tags?).and_return(true)
end
stub_container_registry_tags(repository: :any, tags: ['tag'])
is_expected.to be_truthy
end
it 'does not cause N+1 query' do
allow_next_found_instance_of(ContainerRepository) do |repository|
allow(repository).to receive(:has_tags?).and_return(false)
end
it 'does not cause N+1 query in fetching registries' do
stub_container_registry_tags(repository: :any, tags: [])
control_count = ActiveRecord::QueryRecorder.new { namespace.any_project_has_container_registry_tags? }.count
other_repositories = create_list(:container_repository, 2)
create(:project, namespace: namespace, container_repositories: other_repositories)
expect { namespace.any_project_has_container_registry_tags? }.not_to exceed_query_limit(control_count)
expect { namespace.any_project_has_container_registry_tags? }.not_to exceed_query_limit(control_count + 1)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment