diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:10:04 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:10:04 +0000 |
commit | 1bf4fece121298260663c6ca73d39716d3548a03 (patch) | |
tree | 5c82dd2fa63552ecb67fcb034740ec7e8fdba25a /spec/support/shared_examples/models | |
parent | 254ec28f5448f6f353cd98f637985de3d1405854 (diff) | |
download | gitlab-ce-1bf4fece121298260663c6ca73d39716d3548a03.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples/models')
-rw-r--r-- | spec/support/shared_examples/models/concerns/composite_id_shared_examples.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/concerns/composite_id_shared_examples.rb b/spec/support/shared_examples/models/concerns/composite_id_shared_examples.rb new file mode 100644 index 00000000000..cd925659311 --- /dev/null +++ b/spec/support/shared_examples/models/concerns/composite_id_shared_examples.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'a where_composite scope' do |scope_name| + let(:result) { described_class.public_send(scope_name, ids) } + + context 'we pass an empty array' do + let(:ids) { [] } + + it 'returns a null relation' do + expect(result).to be_empty + end + end + + context 'we pass nil' do + let(:ids) { nil } + + it 'returns a null relation' do + expect(result).to be_empty + end + end + + context 'we pass a singleton composite id' do + let(:ids) { composite_ids.first } + + it 'finds the first result' do + expect(result).to contain_exactly(first_result) + end + end + + context 'we pass group of ids' do + let(:ids) { composite_ids } + + it 'finds all the results' do + expect(result).to contain_exactly(*all_results) + end + end + + describe 'performance' do + it 'is not O(N)' do + all_ids = composite_ids + one_id = composite_ids.first + + expect { described_class.public_send(scope_name, all_ids) } + .to issue_same_number_of_queries_as { described_class.public_send(scope_name, one_id) } + end + end +end |