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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-18 13:50:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-18 13:50:51 +0300
commitdb384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch)
tree34beaef37df5f47ccbcf5729d7583aae093cffa0 /spec/support/shared_examples/lib/gitlab
parent54fd7b1bad233e3944434da91d257fa7f63c3996 (diff)
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
-rw-r--r--spec/support/shared_examples/lib/gitlab/cache/json_cache_shared_examples.rb46
-rw-r--r--spec/support/shared_examples/lib/gitlab/search_archived_filter_shared_examples.rb33
2 files changed, 46 insertions, 33 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/cache/json_cache_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cache/json_cache_shared_examples.rb
index 0472bb87e62..f60974beaf8 100644
--- a/spec/support/shared_examples/lib/gitlab/cache/json_cache_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/cache/json_cache_shared_examples.rb
@@ -18,7 +18,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'parses the cached value' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(broadcast_message))
- expect(cache.read(key, BroadcastMessage)).to eq(broadcast_message)
+ expect(cache.read(key, System::BroadcastMessage)).to eq(broadcast_message)
end
it 'returns nil when klass is nil' do
@@ -30,14 +30,14 @@ RSpec.shared_examples 'Json Cache class' do
it 'gracefully handles an empty hash' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value({}))
- expect(cache.read(key, BroadcastMessage)).to be_a(BroadcastMessage)
+ expect(cache.read(key, System::BroadcastMessage)).to be_a(System::BroadcastMessage)
end
context 'when the cached value is a JSON true value' do
it 'parses the cached value' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(true))
- expect(cache.read(key, BroadcastMessage)).to eq(true)
+ expect(cache.read(key, System::BroadcastMessage)).to eq(true)
end
end
@@ -45,7 +45,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'parses the cached value' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value(false))
- expect(cache.read(key, BroadcastMessage)).to eq(false)
+ expect(cache.read(key, System::BroadcastMessage)).to eq(false)
end
end
@@ -53,23 +53,23 @@ RSpec.shared_examples 'Json Cache class' do
it 'gracefully handles bad cached entry' do
allow(backend).to receive(:read).with(expanded_key).and_return('{')
- expect(cache.read(key, BroadcastMessage)).to be_nil
+ expect(cache.read(key, System::BroadcastMessage)).to be_nil
end
it 'gracefully handles unknown attributes' do
read_value = json_value(broadcast_message.attributes.merge(unknown_attribute: 1))
allow(backend).to receive(:read).with(expanded_key).and_return(read_value)
- expect(cache.read(key, BroadcastMessage)).to be_nil
+ expect(cache.read(key, System::BroadcastMessage)).to be_nil
end
it 'gracefully handles excluded fields from attributes during serialization' do
read_value = json_value(broadcast_message.attributes.except("message_html"))
allow(backend).to receive(:read).with(expanded_key).and_return(read_value)
- result = cache.read(key, BroadcastMessage)
+ result = cache.read(key, System::BroadcastMessage)
- BroadcastMessage.cached_markdown_fields.html_fields.each do |field|
+ System::BroadcastMessage.cached_markdown_fields.html_fields.each do |field|
expect(result.public_send(field)).to be_nil
end
end
@@ -79,7 +79,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'parses the cached value' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value([broadcast_message]))
- expect(cache.read(key, BroadcastMessage)).to eq([broadcast_message])
+ expect(cache.read(key, System::BroadcastMessage)).to eq([broadcast_message])
end
it 'returns an empty array when klass is nil' do
@@ -91,20 +91,20 @@ RSpec.shared_examples 'Json Cache class' do
it 'gracefully handles bad cached entry' do
allow(backend).to receive(:read).with(expanded_key).and_return('[')
- expect(cache.read(key, BroadcastMessage)).to be_nil
+ expect(cache.read(key, System::BroadcastMessage)).to be_nil
end
it 'gracefully handles an empty array' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value([]))
- expect(cache.read(key, BroadcastMessage)).to eq([])
+ expect(cache.read(key, System::BroadcastMessage)).to eq([])
end
it 'gracefully handles items with unknown attributes' do
read_value = json_value([{ unknown_attribute: 1 }, broadcast_message.attributes])
allow(backend).to receive(:read).with(expanded_key).and_return(read_value)
- expect(cache.read(key, BroadcastMessage)).to eq([broadcast_message])
+ expect(cache.read(key, System::BroadcastMessage)).to eq([broadcast_message])
end
end
end
@@ -206,20 +206,20 @@ RSpec.shared_examples 'Json Cache class' do
end
it 'parses the cached value' do
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to eq(broadcast_message)
end
it 'decodes enums correctly' do
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result.broadcast_type).to eq(broadcast_message.broadcast_type)
end
context 'when the cached value is an instance of ActiveRecord::Base' do
it 'returns a persisted record when id is set' do
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to be_persisted
end
@@ -227,7 +227,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'returns a new record when id is nil' do
backend.write(expanded_key, json_value(build(:broadcast_message)))
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to be_new_record
end
@@ -235,7 +235,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'returns a new record when id is missing' do
backend.write(expanded_key, json_value(build(:broadcast_message).attributes.except('id')))
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to be_new_record
end
@@ -243,7 +243,7 @@ RSpec.shared_examples 'Json Cache class' do
it 'gracefully handles bad cached entry' do
allow(backend).to receive(:read).with(expanded_key).and_return('{')
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to eq 'block result'
end
@@ -251,14 +251,14 @@ RSpec.shared_examples 'Json Cache class' do
it 'gracefully handles an empty hash' do
allow(backend).to receive(:read).with(expanded_key).and_return(json_value({}))
- expect(cache.fetch(key, as: BroadcastMessage)).to be_a(BroadcastMessage)
+ expect(cache.fetch(key, as: System::BroadcastMessage)).to be_a(System::BroadcastMessage)
end
it 'gracefully handles unknown attributes' do
read_value = json_value(broadcast_message.attributes.merge(unknown_attribute: 1))
allow(backend).to receive(:read).with(expanded_key).and_return(read_value)
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to eq 'block result'
end
@@ -267,9 +267,9 @@ RSpec.shared_examples 'Json Cache class' do
read_value = json_value(broadcast_message.attributes.except("message_html"))
allow(backend).to receive(:read).with(expanded_key).and_return(read_value)
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
- BroadcastMessage.cached_markdown_fields.html_fields.each do |field|
+ System::BroadcastMessage.cached_markdown_fields.html_fields.each do |field|
expect(result.public_send(field)).to be_nil
end
end
@@ -294,7 +294,7 @@ RSpec.shared_examples 'Json Cache class' do
end
it 'parses the cached value' do
- result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+ result = cache.fetch(key, as: System::BroadcastMessage) { 'block result' }
expect(result).to eq([broadcast_message])
end
diff --git a/spec/support/shared_examples/lib/gitlab/search_archived_filter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/search_archived_filter_shared_examples.rb
index 7bcefd07fc4..6b296d0e78a 100644
--- a/spec/support/shared_examples/lib/gitlab/search_archived_filter_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/search_archived_filter_shared_examples.rb
@@ -1,30 +1,43 @@
# frozen_string_literal: true
-RSpec.shared_examples 'search results filtered by archived' do
+RSpec.shared_examples 'search results filtered by archived' do |feature_flag_name|
context 'when filter not provided (all behavior)' do
let(:filters) { {} }
- it 'returns unarchived results only', :aggregate_failures do
- expect(results.objects('projects')).to include unarchived_project
- expect(results.objects('projects')).not_to include archived_project
+ it 'returns unarchived results only' do
+ expect(results.objects(scope)).to include unarchived_result
+ expect(results.objects(scope)).not_to include archived_result
end
end
context 'when include_archived is true' do
let(:filters) { { include_archived: true } }
- it 'returns archived and unarchived results', :aggregate_failures do
- expect(results.objects('projects')).to include unarchived_project
- expect(results.objects('projects')).to include archived_project
+ it 'returns archived and unarchived results' do
+ expect(results.objects(scope)).to include unarchived_result
+ expect(results.objects(scope)).to include archived_result
end
end
context 'when include_archived filter is false' do
let(:filters) { { include_archived: false } }
- it 'returns unarchived results only', :aggregate_failures do
- expect(results.objects('projects')).to include unarchived_project
- expect(results.objects('projects')).not_to include archived_project
+ it 'returns unarchived results only' do
+ expect(results.objects(scope)).to include unarchived_result
+ expect(results.objects(scope)).not_to include archived_result
+ end
+ end
+
+ context "when the #{feature_flag_name} feature flag is disabled" do
+ let(:filters) { {} }
+
+ before do
+ stub_feature_flags("#{feature_flag_name}": false)
+ end
+
+ it 'returns archived and unarchived results' do
+ expect(results.objects(scope)).to include unarchived_result
+ expect(results.objects(scope)).to include archived_result
end
end
end