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>2021-07-20 12:55:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-20 12:55:51 +0300
commite8d2c2579383897a1dd7f9debd359abe8ae8373d (patch)
treec42be41678c2586d49a75cabce89322082698334 /spec/lib/api
parentfc845b37ec3a90aaa719975f607740c22ba6a113 (diff)
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/lib/api')
-rw-r--r--spec/lib/api/entities/basic_project_details_spec.rb27
-rw-r--r--spec/lib/api/entities/bulk_import_spec.rb19
-rw-r--r--spec/lib/api/entities/bulk_imports/entity_failure_spec.rb19
-rw-r--r--spec/lib/api/entities/bulk_imports/entity_spec.rb26
-rw-r--r--spec/lib/api/entities/ci/job_request/image_spec.rb (renamed from spec/lib/api/entities/job_request/image_spec.rb)2
-rw-r--r--spec/lib/api/entities/ci/job_request/port_spec.rb (renamed from spec/lib/api/entities/job_request/port_spec.rb)2
-rw-r--r--spec/lib/api/entities/group_detail_spec.rb19
-rw-r--r--spec/lib/api/entities/plan_limit_spec.rb3
-rw-r--r--spec/lib/api/entities/user_spec.rb2
-rw-r--r--spec/lib/api/helpers/caching_spec.rb138
10 files changed, 156 insertions, 101 deletions
diff --git a/spec/lib/api/entities/basic_project_details_spec.rb b/spec/lib/api/entities/basic_project_details_spec.rb
new file mode 100644
index 00000000000..dc7c4fdce4e
--- /dev/null
+++ b/spec/lib/api/entities/basic_project_details_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::BasicProjectDetails do
+ let_it_be(:project) { create(:project) }
+
+ let(:current_user) { project.owner }
+
+ subject(:output) { described_class.new(project, current_user: current_user).as_json }
+
+ describe '#default_branch' do
+ it 'delegates to Project#default_branch_or_main' do
+ expect(project).to receive(:default_branch_or_main).twice.and_call_original
+
+ expect(output).to include(default_branch: project.default_branch_or_main)
+ end
+
+ context 'anonymous user' do
+ let(:current_user) { nil }
+
+ it 'is not included' do
+ expect(output.keys).not_to include(:default_branch)
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/entities/bulk_import_spec.rb b/spec/lib/api/entities/bulk_import_spec.rb
new file mode 100644
index 00000000000..2db6862b079
--- /dev/null
+++ b/spec/lib/api/entities/bulk_import_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::BulkImport do
+ let_it_be(:import) { create(:bulk_import) }
+
+ subject { described_class.new(import).as_json }
+
+ it 'has the correct attributes' do
+ expect(subject).to include(
+ :id,
+ :status,
+ :source_type,
+ :created_at,
+ :updated_at
+ )
+ end
+end
diff --git a/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb
new file mode 100644
index 00000000000..adc8fdcdd9c
--- /dev/null
+++ b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::BulkImports::EntityFailure do
+ let_it_be(:failure) { create(:bulk_import_failure) }
+
+ subject { described_class.new(failure).as_json }
+
+ it 'has the correct attributes' do
+ expect(subject).to include(
+ :pipeline_class,
+ :pipeline_step,
+ :exception_class,
+ :correlation_id_value,
+ :created_at
+ )
+ end
+end
diff --git a/spec/lib/api/entities/bulk_imports/entity_spec.rb b/spec/lib/api/entities/bulk_imports/entity_spec.rb
new file mode 100644
index 00000000000..f91ae1fc5a1
--- /dev/null
+++ b/spec/lib/api/entities/bulk_imports/entity_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::BulkImports::Entity do
+ let_it_be(:entity) { create(:bulk_import_entity) }
+
+ subject { described_class.new(entity).as_json }
+
+ it 'has the correct attributes' do
+ expect(subject).to include(
+ :id,
+ :bulk_import_id,
+ :status,
+ :source_full_path,
+ :destination_name,
+ :destination_namespace,
+ :parent_id,
+ :namespace_id,
+ :project_id,
+ :created_at,
+ :updated_at,
+ :failures
+ )
+ end
+end
diff --git a/spec/lib/api/entities/job_request/image_spec.rb b/spec/lib/api/entities/ci/job_request/image_spec.rb
index f13eab6a752..55aade03129 100644
--- a/spec/lib/api/entities/job_request/image_spec.rb
+++ b/spec/lib/api/entities/ci/job_request/image_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe API::Entities::JobRequest::Image do
+RSpec.describe API::Entities::Ci::JobRequest::Image do
let(:ports) { [{ number: 80, protocol: 'http', name: 'name' }]}
let(:image) { double(name: 'image_name', entrypoint: ['foo'], ports: ports)}
let(:entity) { described_class.new(image) }
diff --git a/spec/lib/api/entities/job_request/port_spec.rb b/spec/lib/api/entities/ci/job_request/port_spec.rb
index 4820c4a691b..8e0d2cabcfc 100644
--- a/spec/lib/api/entities/job_request/port_spec.rb
+++ b/spec/lib/api/entities/ci/job_request/port_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe ::API::Entities::JobRequest::Port do
+RSpec.describe ::API::Entities::Ci::JobRequest::Port do
let(:port) { double(number: 80, protocol: 'http', name: 'name')}
let(:entity) { described_class.new(port) }
diff --git a/spec/lib/api/entities/group_detail_spec.rb b/spec/lib/api/entities/group_detail_spec.rb
new file mode 100644
index 00000000000..8fcb120c809
--- /dev/null
+++ b/spec/lib/api/entities/group_detail_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Entities::GroupDetail do
+ describe '#as_json' do
+ it 'includes prevent_sharing_groups_outside_hierarchy for a root group' do
+ group = create(:group)
+
+ expect(described_class.new(group).as_json).to include(prevent_sharing_groups_outside_hierarchy: false)
+ end
+
+ it 'excludes prevent_sharing_groups_outside_hierarchy for a subgroup' do
+ subgroup = build(:group, :nested)
+
+ expect(described_class.new(subgroup).as_json.keys).not_to include(:prevent_sharing_groups_outside_hierarchy)
+ end
+ end
+end
diff --git a/spec/lib/api/entities/plan_limit_spec.rb b/spec/lib/api/entities/plan_limit_spec.rb
index ee42c67f9b6..75e39e4f074 100644
--- a/spec/lib/api/entities/plan_limit_spec.rb
+++ b/spec/lib/api/entities/plan_limit_spec.rb
@@ -14,7 +14,8 @@ RSpec.describe API::Entities::PlanLimit do
:maven_max_file_size,
:npm_max_file_size,
:nuget_max_file_size,
- :pypi_max_file_size
+ :pypi_max_file_size,
+ :terraform_module_max_file_size
)
end
diff --git a/spec/lib/api/entities/user_spec.rb b/spec/lib/api/entities/user_spec.rb
index e35deeb6263..860f007f284 100644
--- a/spec/lib/api/entities/user_spec.rb
+++ b/spec/lib/api/entities/user_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe API::Entities::User do
subject { described_class.new(user, current_user: current_user).as_json }
it 'exposes correct attributes' do
- expect(subject).to include(:bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :work_information)
+ expect(subject).to include(:bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :work_information, :pronouns)
end
it 'exposes created_at if the current user can read the user profile' do
diff --git a/spec/lib/api/helpers/caching_spec.rb b/spec/lib/api/helpers/caching_spec.rb
index f94c44c7382..38b7b386d5c 100644
--- a/spec/lib/api/helpers/caching_spec.rb
+++ b/spec/lib/api/helpers/caching_spec.rb
@@ -3,7 +3,7 @@
require "spec_helper"
RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
- subject(:instance) { Class.new.include(described_class).new }
+ subject(:instance) { Class.new.include(described_class, Grape::DSL::Headers).new }
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
@@ -44,108 +44,16 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
}
end
- context "single object" do
+ context 'single object' do
let_it_be(:presentable) { create(:todo, project: project) }
- it { is_expected.to be_a(Gitlab::Json::PrecompiledJson) }
-
- it "uses the presenter" do
- expect(presenter).to receive(:represent).with(presentable, project: project)
-
- subject
- end
-
- it "is valid JSON" do
- parsed = Gitlab::Json.parse(subject.to_s)
-
- expect(parsed).to be_a(Hash)
- expect(parsed["id"]).to eq(presentable.id)
- end
-
- it "fetches from the cache" do
- expect(instance.cache).to receive(:fetch).with("#{presentable.cache_key}:#{user.cache_key}", expires_in: described_class::DEFAULT_EXPIRY).once
-
- subject
- end
-
- context "when a cache context is supplied" do
- before do
- kwargs[:cache_context] = -> (todo) { todo.project.cache_key }
- end
-
- it "uses the context to augment the cache key" do
- expect(instance.cache).to receive(:fetch).with("#{presentable.cache_key}:#{project.cache_key}", expires_in: described_class::DEFAULT_EXPIRY).once
-
- subject
- end
- end
-
- context "when expires_in is supplied" do
- it "sets the expiry when accessing the cache" do
- kwargs[:expires_in] = 7.days
-
- expect(instance.cache).to receive(:fetch).with("#{presentable.cache_key}:#{user.cache_key}", expires_in: 7.days).once
-
- subject
- end
- end
+ it_behaves_like 'object cache helper'
end
- context "for a collection of objects" do
+ context 'collection of objects' do
let_it_be(:presentable) { Array.new(5).map { create(:todo, project: project) } }
- it { is_expected.to be_an(Gitlab::Json::PrecompiledJson) }
-
- it "uses the presenter" do
- presentable.each do |todo|
- expect(presenter).to receive(:represent).with(todo, project: project)
- end
-
- subject
- end
-
- it "is valid JSON" do
- parsed = Gitlab::Json.parse(subject.to_s)
-
- expect(parsed).to be_an(Array)
-
- presentable.each_with_index do |todo, i|
- expect(parsed[i]["id"]).to eq(todo.id)
- end
- end
-
- it "fetches from the cache" do
- keys = presentable.map { |todo| "#{todo.cache_key}:#{user.cache_key}" }
-
- expect(instance.cache).to receive(:fetch_multi).with(*keys, expires_in: described_class::DEFAULT_EXPIRY).once.and_call_original
-
- subject
- end
-
- context "when a cache context is supplied" do
- before do
- kwargs[:cache_context] = -> (todo) { todo.project.cache_key }
- end
-
- it "uses the context to augment the cache key" do
- keys = presentable.map { |todo| "#{todo.cache_key}:#{project.cache_key}" }
-
- expect(instance.cache).to receive(:fetch_multi).with(*keys, expires_in: described_class::DEFAULT_EXPIRY).once.and_call_original
-
- subject
- end
- end
-
- context "expires_in is supplied" do
- it "sets the expiry when accessing the cache" do
- keys = presentable.map { |todo| "#{todo.cache_key}:#{user.cache_key}" }
- kwargs[:expires_in] = 7.days
-
- expect(instance.cache).to receive(:fetch_multi).with(*keys, expires_in: 7.days).once.and_call_original
-
- subject
- end
- end
+ it_behaves_like 'collection cache helper'
end
end
@@ -187,6 +95,42 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
expect(nested_call.to_s).to eq(subject.to_s)
end
+
+ context 'Cache versioning' do
+ it 'returns cache based on version parameter' do
+ result_1 = instance.cache_action(cache_key, **kwargs.merge(version: 1)) { 'Cache 1' }
+ result_2 = instance.cache_action(cache_key, **kwargs.merge(version: 2)) { 'Cache 2' }
+
+ expect(result_1.to_s).to eq('Cache 1'.to_json)
+ expect(result_2.to_s).to eq('Cache 2'.to_json)
+ end
+ end
+
+ context 'Cache for pagination headers' do
+ described_class::PAGINATION_HEADERS.each do |pagination_header|
+ context pagination_header do
+ before do
+ instance.header(pagination_header, 100)
+ end
+
+ it 'stores and recovers pagination headers from cache' do
+ expect { perform }.not_to change { instance.header[pagination_header] }
+
+ instance.header.delete(pagination_header)
+
+ expect { perform }.to change { instance.header[pagination_header] }.from(nil).to(100)
+ end
+
+ it 'prefers headers from request than from cache' do
+ expect { perform }.not_to change { instance.header[pagination_header] }
+
+ instance.header(pagination_header, 50)
+
+ expect { perform }.not_to change { instance.header[pagination_header] }.from(50)
+ end
+ end
+ end
+ end
end
describe "#cache_action_if" do