diff options
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/analytics_summary_serializer_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/cluster_application_entity_spec.rb | 12 | ||||
-rw-r--r-- | spec/serializers/cluster_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/fork_namespace_entity_spec.rb | 32 | ||||
-rw-r--r-- | spec/serializers/issue_board_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/member_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/merge_request_diff_entity_spec.rb | 68 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 19 |
8 files changed, 102 insertions, 41 deletions
diff --git a/spec/serializers/analytics_summary_serializer_spec.rb b/spec/serializers/analytics_summary_serializer_spec.rb index cd8be07827d..9429c9d571a 100644 --- a/spec/serializers/analytics_summary_serializer_spec.rb +++ b/spec/serializers/analytics_summary_serializer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe AnalyticsSummarySerializer do let(:resource) do Gitlab::CycleAnalytics::Summary::Issue - .new(project: double, from: 1.day.ago, current_user: user) + .new(project: double, options: { from: 1.day.ago }, current_user: user) end before do @@ -36,7 +36,7 @@ RSpec.describe AnalyticsSummarySerializer do context 'when representing with unit' do let(:resource) do Gitlab::CycleAnalytics::Summary::DeploymentFrequency - .new(deployments: 10, from: 1.day.ago) + .new(deployments: 10, options: { from: 1.day.ago }) end subject { described_class.new.represent(resource, with_unit: true) } diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb index aa2bb25b17c..1e71e45948c 100644 --- a/spec/serializers/cluster_application_entity_spec.rb +++ b/spec/serializers/cluster_application_entity_spec.rb @@ -77,17 +77,5 @@ RSpec.describe ClusterApplicationEntity do expect(subject[:pages_domain]).to eq(id: pages_domain.id, domain: pages_domain.domain) end end - - context 'for fluentd application' do - let(:application) { build(:clusters_applications_fluentd, :installed) } - - it 'includes host, port, protocol and log fields' do - expect(subject[:port]).to eq(514) - expect(subject[:host]).to eq("example.com") - expect(subject[:protocol]).to eq("tcp") - expect(subject[:waf_log_enabled]).to be true - expect(subject[:cilium_log_enabled]).to be true - end - end end end diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index 10c6bc0e42a..ee1388024ea 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -91,9 +91,9 @@ RSpec.describe ClusterEntity do end end - context 'elastic stack is installed on cluster' do + context 'elastic stack is enabled on cluster' do it 'returns true' do - create(:clusters_applications_elastic_stack, :installed, cluster: cluster) + create(:clusters_integrations_elastic_stack, cluster: cluster) expect(subject[:enable_advanced_logs_querying]).to be true end diff --git a/spec/serializers/fork_namespace_entity_spec.rb b/spec/serializers/fork_namespace_entity_spec.rb index 5e9918a89ff..32223b0d41a 100644 --- a/spec/serializers/fork_namespace_entity_spec.rb +++ b/spec/serializers/fork_namespace_entity_spec.rb @@ -9,12 +9,15 @@ RSpec.describe ForkNamespaceEntity do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:namespace) { create(:group, :with_avatar, description: 'test') } + let_it_be(:forked_project) { build(:project) } let(:memberships) do user.members.index_by(&:source_id) end - let(:entity) { described_class.new(namespace, current_user: user, project: project, memberships: memberships) } + let(:forked_projects) { { namespace.id => forked_project } } + + let(:entity) { described_class.new(namespace, current_user: user, project: project, memberships: memberships, forked_projects: forked_projects) } subject(:json) { entity.as_json } @@ -46,10 +49,7 @@ RSpec.describe ForkNamespaceEntity do end it 'exposes forked_project_path when fork exists in namespace' do - namespace.add_maintainer(user) - fork_in_namespace = fork_project(project, user, namespace: namespace) - - expect(json[:forked_project_path]).to eql project_path(fork_in_namespace) + expect(json[:forked_project_path]).to eql project_path(forked_project) end it 'exposes relative path to the namespace' do @@ -60,15 +60,25 @@ RSpec.describe ForkNamespaceEntity do expect(json[:permission]).to eql 'Developer' end - it 'sets can_create_project to true when user can create projects in namespace' do - allow(user).to receive(:can?).with(:create_projects, namespace).and_return(true) - + it 'exposes can_create_project' do expect(json[:can_create_project]).to be true end - it 'sets can_create_project to false when user is not allowed create projects in namespace' do - allow(user).to receive(:can?).with(:create_projects, namespace).and_return(false) + context 'when fork_project_form feature flag is disabled' do + before do + stub_feature_flags(fork_project_form: false) + end + + it 'sets can_create_project to true when user can create projects in namespace' do + allow(user).to receive(:can?).with(:create_projects, namespace).and_return(true) - expect(json[:can_create_project]).to be false + expect(json[:can_create_project]).to be true + end + + it 'sets can_create_project to false when user is not allowed create projects in namespace' do + allow(user).to receive(:can?).with(:create_projects, namespace).and_return(false) + + expect(json[:can_create_project]).to be false + end end end diff --git a/spec/serializers/issue_board_entity_spec.rb b/spec/serializers/issue_board_entity_spec.rb index 138b8174d81..30423ceba6d 100644 --- a/spec/serializers/issue_board_entity_spec.rb +++ b/spec/serializers/issue_board_entity_spec.rb @@ -15,7 +15,7 @@ RSpec.describe IssueBoardEntity do it 'has basic attributes' do expect(subject).to include(:id, :iid, :title, :confidential, :due_date, :project_id, :relative_position, - :labels, :assignees, project: hash_including(:id, :path)) + :labels, :assignees, project: hash_including(:id, :path, :path_with_namespace)) end it 'has path and endpoints' do diff --git a/spec/serializers/member_serializer_spec.rb b/spec/serializers/member_serializer_spec.rb index 687d69f86ea..bc256432c46 100644 --- a/spec/serializers/member_serializer_spec.rb +++ b/spec/serializers/member_serializer_spec.rb @@ -42,7 +42,7 @@ RSpec.describe MemberSerializer do it_behaves_like 'members.json' it 'does not invoke group owner assignment' do - expect(Members::LastGroupOwnerAssigner).not_to receive(:new) + expect(LastGroupOwnerAssigner).not_to receive(:new) representation end diff --git a/spec/serializers/merge_request_diff_entity_spec.rb b/spec/serializers/merge_request_diff_entity_spec.rb index a3b356505b8..9bf95e68874 100644 --- a/spec/serializers/merge_request_diff_entity_spec.rb +++ b/spec/serializers/merge_request_diff_entity_spec.rb @@ -10,8 +10,16 @@ RSpec.describe MergeRequestDiffEntity do let(:merge_request_diffs) { merge_request.merge_request_diffs } let(:merge_request_diff) { merge_request_diffs.first } - let(:entity) do - described_class.new(merge_request_diff, request: request, merge_request: merge_request, merge_request_diffs: merge_request_diffs) + let(:entity) { initialize_entity(merge_request, merge_request_diff) } + + def initialize_entity(merge_request, merge_request_diff) + described_class.new( + merge_request_diff, + request: request, + merge_request: merge_request, + merge_request_diff: merge_request_diff, + merge_request_diffs: merge_request_diffs + ) end subject { entity.as_json } @@ -26,6 +34,62 @@ RSpec.describe MergeRequestDiffEntity do end end + describe '#version_index' do + shared_examples 'version_index is nil' do + it 'returns nil' do + expect(subject[:version_index]).to be_nil + end + end + + context 'when diff is not present' do + let(:entity) do + described_class.new( + merge_request_diff, + request: request, + merge_request: merge_request, + merge_request_diffs: merge_request_diffs + ) + end + + it_behaves_like 'version_index is nil' + end + + context 'when diff is not included in @merge_request_diffs' do + let(:merge_request_diff) { create(:merge_request_diff) } + let(:merge_request_diff_2) { create(:merge_request_diff) } + + before do + merge_request_diffs << merge_request_diff_2 + end + + it_behaves_like 'version_index is nil' + end + + context 'when @merge_request_diffs.size <= 1' do + before do + expect(merge_request_diffs.size).to eq(1) + end + + it_behaves_like 'version_index is nil' + end + + context 'when @merge_request_diffs.size > 1' do + let(:merge_request) { create(:merge_request_with_multiple_diffs) } + + it 'returns difference between size and diff index' do + expect(merge_request_diffs.size).to eq(2) + + # diff index: 0 + subject = initialize_entity(merge_request, merge_request_diffs.first) + expect(subject.as_json[:version_index]).to eq(2) + + # diff index: 1 + subject = initialize_entity(merge_request, merge_request_diffs.last) + expect(subject.as_json[:version_index]).to eq(1) + end + end + end + describe '#short_commit_sha' do it 'returns short sha' do expect(subject[:short_commit_sha]).to eq('b83d6e39') diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index 1111290cade..bcad9eb6e23 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -212,18 +212,17 @@ RSpec.describe PipelineSerializer do context 'with build environments' do let(:ref) { 'feature' } - it 'verifies number of queries', :request_store do - stub_licensed_features(protected_environments: true) + let_it_be(:production) { create(:environment, :production, project: project) } + let_it_be(:staging) { create(:environment, :staging, project: project) } - env = create(:environment, project: project) - create(:ci_build, :scheduled, project: project, environment: env.name) - create(:ci_build, :scheduled, project: project, environment: env.name) - create(:ci_build, :scheduled, project: project, environment: env.name) + it 'executes one query to fetch all related environments', :request_store do + pipeline = create(:ci_pipeline, project: project) + create(:ci_build, :manual, pipeline: pipeline, environment: production.name) + create(:ci_build, :manual, pipeline: pipeline, environment: staging.name) + create(:ci_build, :scheduled, pipeline: pipeline, environment: production.name) + create(:ci_build, :scheduled, pipeline: pipeline, environment: staging.name) - recorded = ActiveRecord::QueryRecorder.new { subject } - expected_queries = Gitlab.ee? ? 56 : 52 - expect(recorded.count).to be_within(1).of(expected_queries) - expect(recorded.cached_count).to eq(0) + expect { subject }.not_to exceed_query_limit(1).for_query /SELECT "environments".*/ end end |