summaryrefslogtreecommitdiff
path: root/spec/lib/api/entities
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/api/entities')
-rw-r--r--spec/lib/api/entities/basic_project_details_spec.rb47
-rw-r--r--spec/lib/api/entities/bulk_imports/entity_spec.rb3
-rw-r--r--spec/lib/api/entities/ml/mlflow/run_info_spec.rb14
3 files changed, 58 insertions, 6 deletions
diff --git a/spec/lib/api/entities/basic_project_details_spec.rb b/spec/lib/api/entities/basic_project_details_spec.rb
index 8419eb0a932..425252ea315 100644
--- a/spec/lib/api/entities/basic_project_details_spec.rb
+++ b/spec/lib/api/entities/basic_project_details_spec.rb
@@ -2,14 +2,16 @@
require 'spec_helper'
-RSpec.describe API::Entities::BasicProjectDetails do
- let_it_be(:project) { create(:project) }
-
- let(:current_user) { project.first_owner }
+RSpec.describe API::Entities::BasicProjectDetails, feature_category: :api do
+ let_it_be(:project_with_repository_restriction) { create(:project, :public, :repository_private) }
+ let(:member_user) { project_with_repository_restriction.first_owner }
subject(:output) { described_class.new(project, current_user: current_user).as_json }
describe '#default_branch' do
+ let(:current_user) { member_user }
+ let(:project) { project_with_repository_restriction }
+
it 'delegates to Project#default_branch_or_main' do
expect(project).to receive(:default_branch_or_main).twice.and_call_original
@@ -20,7 +22,42 @@ RSpec.describe API::Entities::BasicProjectDetails do
let(:current_user) { nil }
it 'is not included' do
- expect(output.keys).not_to include(:default_branch)
+ expect(output).not_to include(:default_branch)
+ end
+ end
+ end
+
+ describe '#readme_url #forks_count' do
+ using RSpec::Parameterized::TableSyntax
+ let_it_be(:non_member_user) { create(:user) } # Creates a fresh user that is why it is not the member of the project
+
+ context 'public project with repository is accessible by the user' do
+ let_it_be(:project_without_restriction) { create(:project, :public) }
+
+ where(:current_user, :project) do
+ ref(:member_user) | ref(:project_without_restriction)
+ ref(:non_member_user) | ref(:project_without_restriction)
+ nil | ref(:project_without_restriction)
+ ref(:member_user) | ref(:project_with_repository_restriction)
+ end
+
+ with_them do
+ it 'exposes readme_url and forks_count' do
+ expect(output).to include readme_url: project.readme_url, forks_count: project.forks_count
+ end
+ end
+ end
+
+ context 'public project with repository is not accessible by the user' do
+ where(:current_user, :project) do
+ ref(:non_member_user) | ref(:project_with_repository_restriction)
+ nil | ref(:project_with_repository_restriction)
+ end
+
+ with_them do
+ it 'does not expose readme_url and forks_count' do
+ expect(output).not_to include :readme_url, :forks_count
+ end
end
end
end
diff --git a/spec/lib/api/entities/bulk_imports/entity_spec.rb b/spec/lib/api/entities/bulk_imports/entity_spec.rb
index 4de85862ab9..ba8a2ddffcb 100644
--- a/spec/lib/api/entities/bulk_imports/entity_spec.rb
+++ b/spec/lib/api/entities/bulk_imports/entity_spec.rb
@@ -21,7 +21,8 @@ RSpec.describe API::Entities::BulkImports::Entity do
:project_id,
:created_at,
:updated_at,
- :failures
+ :failures,
+ :migrate_projects
)
end
end
diff --git a/spec/lib/api/entities/ml/mlflow/run_info_spec.rb b/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
index d5a37f53e21..db8f106c9fe 100644
--- a/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
+++ b/spec/lib/api/entities/ml/mlflow/run_info_spec.rb
@@ -33,6 +33,20 @@ RSpec.describe API::Entities::Ml::Mlflow::RunInfo do
end
end
+ describe 'run_name' do
+ context 'when nil' do
+ it { is_expected.not_to have_key(:run_name) }
+ end
+
+ context 'when not nil' do
+ before do
+ allow(candidate).to receive(:name).and_return('hello')
+ end
+
+ it { expect(subject[:run_name]).to eq('hello') }
+ end
+ end
+
describe 'experiment_id' do
it 'is the experiment iid as string' do
expect(subject[:experiment_id]).to eq(candidate.experiment.iid.to_s)