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:
Diffstat (limited to 'spec/lib/api/helpers')
-rw-r--r--spec/lib/api/helpers/members_helpers_spec.rb53
-rw-r--r--spec/lib/api/helpers/packages_helpers_spec.rb29
-rw-r--r--spec/lib/api/helpers/pagination_strategies_spec.rb8
-rw-r--r--spec/lib/api/helpers/rate_limiter_spec.rb4
4 files changed, 90 insertions, 4 deletions
diff --git a/spec/lib/api/helpers/members_helpers_spec.rb b/spec/lib/api/helpers/members_helpers_spec.rb
new file mode 100644
index 00000000000..987d5ba9f6c
--- /dev/null
+++ b/spec/lib/api/helpers/members_helpers_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe API::Helpers::MembersHelpers, feature_category: :subgroups do
+ let(:helper) do
+ Class.new.include(described_class).new
+ end
+
+ describe '#source_members' do
+ subject(:source_members) { helper.source_members(source) }
+
+ shared_examples_for 'returns all direct members' do
+ specify do
+ expect(source_members).to match_array(direct_members)
+ end
+ end
+
+ context 'for a group' do
+ let_it_be(:source) { create(:group) }
+ let_it_be(:direct_members) { create_list(:group_member, 2, group: source) }
+
+ it_behaves_like 'returns all direct members'
+ it_behaves_like 'query with source filters'
+
+ context 'when project_members_index_by_project_namespace feature flag is disabled' do
+ before do
+ stub_feature_flags(project_members_index_by_project_namespace: false)
+ end
+
+ it_behaves_like 'returns all direct members'
+ it_behaves_like 'query with source filters'
+ end
+ end
+
+ context 'for a project' do
+ let_it_be(:source) { create(:project, group: create(:group)) }
+ let_it_be(:direct_members) { create_list(:project_member, 2, project: source) }
+
+ it_behaves_like 'returns all direct members'
+ it_behaves_like 'query without source filters'
+
+ context 'when project_members_index_by_project_namespace feature flag is disabled' do
+ before do
+ stub_feature_flags(project_members_index_by_project_namespace: false)
+ end
+
+ it_behaves_like 'returns all direct members'
+ it_behaves_like 'query with source filters'
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/helpers/packages_helpers_spec.rb b/spec/lib/api/helpers/packages_helpers_spec.rb
index a3b21059334..de9d139a7b6 100644
--- a/spec/lib/api/helpers/packages_helpers_spec.rb
+++ b/spec/lib/api/helpers/packages_helpers_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe API::Helpers::PackagesHelpers do
+RSpec.describe API::Helpers::PackagesHelpers, feature_category: :package_registry do
let_it_be(:helper) { Class.new.include(API::Helpers).include(described_class).new }
let_it_be(:project) { create(:project) }
let_it_be(:group) { create(:group) }
@@ -17,6 +17,31 @@ RSpec.describe API::Helpers::PackagesHelpers do
expect(subject).to eq nil
end
+
+ context 'with an allowed required permission' do
+ subject { helper.authorize_packages_access!(project, :read_group) }
+
+ it 'authorizes packages access' do
+ expect(helper).to receive(:require_packages_enabled!)
+ expect(helper).not_to receive(:authorize_read_package!)
+ expect(helper).to receive(:authorize!).with(:read_group, project)
+
+ expect(subject).to eq nil
+ end
+ end
+
+ context 'with a not allowed permission' do
+ subject { helper.authorize_packages_access!(project, :read_permission) }
+
+ it 'rejects packages access' do
+ expect(helper).to receive(:require_packages_enabled!)
+ expect(helper).not_to receive(:authorize_read_package!)
+ expect(helper).not_to receive(:authorize!).with(:test_permission, project)
+ expect(helper).to receive(:forbidden!)
+
+ expect(subject).to eq nil
+ end
+ end
end
describe 'authorize_read_package!' do
@@ -32,7 +57,7 @@ RSpec.describe API::Helpers::PackagesHelpers do
it 'calls authorize! with correct subject' do
expect(helper).to receive(:authorize!).with(:read_package, have_attributes(id: subject.id, class: expected_class))
- expect(helper.send('authorize_read_package!', subject)).to eq nil
+ expect(helper.send(:authorize_read_package!, subject)).to eq nil
end
end
end
diff --git a/spec/lib/api/helpers/pagination_strategies_spec.rb b/spec/lib/api/helpers/pagination_strategies_spec.rb
index 16cc10182b0..f6e8e3cc756 100644
--- a/spec/lib/api/helpers/pagination_strategies_spec.rb
+++ b/spec/lib/api/helpers/pagination_strategies_spec.rb
@@ -43,6 +43,14 @@ RSpec.describe API::Helpers::PaginationStrategies do
expect(result).to eq(return_value)
end
+
+ context "with paginator_params" do
+ it 'correctly passes multiple parameters' do
+ expect(paginator).to receive(:paginate).with(relation, parameter_one: true, parameter_two: 'two')
+
+ subject.paginate_with_strategies(relation, nil, paginator_params: { parameter_one: true, parameter_two: 'two' })
+ end
+ end
end
describe '#paginator' do
diff --git a/spec/lib/api/helpers/rate_limiter_spec.rb b/spec/lib/api/helpers/rate_limiter_spec.rb
index 3640c7e30e7..531140a32a3 100644
--- a/spec/lib/api/helpers/rate_limiter_spec.rb
+++ b/spec/lib/api/helpers/rate_limiter_spec.rb
@@ -31,8 +31,8 @@ RSpec.describe API::Helpers::RateLimiter do
end
describe '#check_rate_limit!' do
- it 'calls ApplicationRateLimiter#throttled? with the right arguments' do
- expect(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).with(key, scope: scope).and_return(false)
+ it 'calls ApplicationRateLimiter#throttled_request? with the right arguments' do
+ expect(::Gitlab::ApplicationRateLimiter).to receive(:throttled_request?).with(request, user, key, scope: scope).and_return(false)
expect(subject).not_to receive(:render_api_error!)
subject.check_rate_limit!(key, scope: scope)