diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-10 18:10:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-10 18:10:24 +0300 |
commit | bd5eb9f0201cf39ecfb0e754787a2297d5fdf051 (patch) | |
tree | b3770a3806de9bf16a106474e4e8b0b57f4076a3 /spec | |
parent | 0ecdc32a425d18a762fb7723c2063e864065b571 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/projects/groups_finder_spec.rb | 33 | ||||
-rw-r--r-- | spec/graphql/mutations/merge_requests/set_draft_spec.rb | 55 | ||||
-rw-r--r-- | spec/graphql/types/merge_request_type_spec.rb | 2 | ||||
-rw-r--r-- | spec/graphql/types/mutation_type_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/hostname_metric_spec.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_metrics_spec.rb | 1 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 10 | ||||
-rw-r--r-- | spec/services/ci/create_web_ide_terminal_service_spec.rb | 10 | ||||
-rw-r--r-- | spec/support/helpers/cycle_analytics_helpers.rb | 32 |
9 files changed, 150 insertions, 18 deletions
diff --git a/spec/finders/projects/groups_finder_spec.rb b/spec/finders/projects/groups_finder_spec.rb index 89d4edaec7c..7f01b73c7ca 100644 --- a/spec/finders/projects/groups_finder_spec.rb +++ b/spec/finders/projects/groups_finder_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Projects::GroupsFinder do let_it_be(:root_group) { create(:group, :public) } let_it_be(:project_group) { create(:group, :public, parent: root_group) } let_it_be(:shared_group_with_dev_access) { create(:group, :private, parent: root_group) } - let_it_be(:shared_group_with_reporter_access) { create(:group, :private) } + let_it_be(:shared_group_with_reporter_access) { create(:group, :public) } let_it_be(:public_project) { create(:project, :public, group: project_group) } let_it_be(:private_project) { create(:project, :private, group: project_group) } @@ -53,6 +53,24 @@ RSpec.describe Projects::GroupsFinder do is_expected.to match_array([project_group, root_group, shared_group_with_dev_access]) end end + + context 'when shared_visible_only is on' do + let(:params) { super().merge(shared_visible_only: true) } + + it 'returns ancestor and public shared groups' do + is_expected.to match_array([project_group, root_group, shared_group_with_reporter_access]) + end + + context 'when user has access to the private shared group' do + before do + shared_group_with_dev_access.add_guest(current_user) + end + + it 'returns ancestor and shared groups user has access to' do + is_expected.to match_array([project_group, root_group, shared_group_with_reporter_access, shared_group_with_dev_access]) + end + end + end end context 'when skip group option is on' do @@ -74,6 +92,19 @@ RSpec.describe Projects::GroupsFinder do it 'returns ancestor groups for this project' do is_expected.to match_array([project_group, root_group]) end + + context 'when visible shared groups are requested' do + let(:params) do + { + with_shared: true, + shared_visible_only: true + } + end + + it 'returns ancestor groups and public shared groups for this project' do + is_expected.to match_array([project_group, root_group, shared_group_with_reporter_access]) + end + end end end end diff --git a/spec/graphql/mutations/merge_requests/set_draft_spec.rb b/spec/graphql/mutations/merge_requests/set_draft_spec.rb new file mode 100644 index 00000000000..697b2e5b007 --- /dev/null +++ b/spec/graphql/mutations/merge_requests/set_draft_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::MergeRequests::SetDraft do + let_it_be(:merge_request) { create(:merge_request) } + let_it_be(:user) { create(:user) } + + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) } + + describe '#resolve' do + let(:draft) { true } + let(:mutated_merge_request) { subject[:merge_request] } + + subject { mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, draft: draft) } + + it_behaves_like 'permission level for merge request mutation is correctly verified' + + context 'when the user can update the merge request' do + before do + merge_request.project.add_developer(user) + end + + it 'returns the merge request as a draft' do + expect(mutated_merge_request).to eq(merge_request) + expect(mutated_merge_request).to be_draft + expect(subject[:errors]).to be_empty + end + + it 'returns errors if/when merge request could not be updated' do + # Make the merge request invalid + merge_request.allow_broken = true + merge_request.update!(source_project: nil) + + expect(subject[:errors]).not_to be_empty + end + + context 'when passing draft as false' do + let(:draft) { false } + + it 'removes `Draft` from the title' do + merge_request.update!(title: "Draft: working on it") + + expect(mutated_merge_request).not_to be_draft + end + + it 'does not do anything if the title did not start with draft' do + expect(mutated_merge_request).not_to be_draft + end + end + end + end +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 3314ea62324..fa33b32c6c8 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do notes discussions user_permissions id iid title title_html description description_html state created_at updated_at source_project target_project project project_id source_project_id target_project_id source_branch - target_branch work_in_progress merge_when_pipeline_succeeds diff_head_sha + target_branch work_in_progress draft merge_when_pipeline_succeeds diff_head_sha merge_commit_sha user_notes_count user_discussions_count should_remove_source_branch diff_refs diff_stats diff_stats_summary force_remove_source_branch merge_status in_progress_merge_commit_sha diff --git a/spec/graphql/types/mutation_type_spec.rb b/spec/graphql/types/mutation_type_spec.rb index 41993327577..e4144e4fa97 100644 --- a/spec/graphql/types/mutation_type_spec.rb +++ b/spec/graphql/types/mutation_type_spec.rb @@ -3,8 +3,16 @@ require 'spec_helper' RSpec.describe Types::MutationType do - it 'is expected to have the MergeRequestSetWip' do - expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetWip) + it 'is expected to have the deprecated MergeRequestSetWip' do + field = get_field('MergeRequestSetWip') + + expect(field).to be_present + expect(field.deprecation_reason).to be_present + expect(field.resolver).to eq(Mutations::MergeRequests::SetWip) + end + + it 'is expected to have the MergeRequestSetDraft' do + expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetDraft) end describe 'deprecated and aliased mutations' do @@ -27,9 +35,9 @@ RSpec.describe Types::MutationType do it { expect(alias_field.resolver.fields).to eq(canonical_field.resolver.fields) } it { expect(alias_field.resolver.arguments).to eq(canonical_field.resolver.arguments) } end + end - def get_field(name) - described_class.fields[GraphqlHelpers.fieldnamerize(name)] - end + def get_field(name) + described_class.fields[GraphqlHelpers.fieldnamerize(name)] end end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/hostname_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/hostname_metric_spec.rb new file mode 100644 index 00000000000..83e07200025 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/hostname_metric_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::HostnameMetric do + it_behaves_like 'a correct instrumented metric value', { time_frame: 'none', data_source: 'ruby' }, Gitlab.config.gitlab.host +end diff --git a/spec/lib/gitlab/usage_data_metrics_spec.rb b/spec/lib/gitlab/usage_data_metrics_spec.rb index e841f680a32..684f0bf17a1 100644 --- a/spec/lib/gitlab/usage_data_metrics_spec.rb +++ b/spec/lib/gitlab/usage_data_metrics_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Gitlab::UsageDataMetrics do context 'whith instrumentation_class' do it 'includes top level keys' do expect(subject).to include(:uuid) + expect(subject).to include(:hostname) end it 'includes counts keys' do diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index a781ba7747c..7f804186bc7 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1683,7 +1683,7 @@ RSpec.describe API::Projects do let_it_be(:root_group) { create(:group, :public, name: 'root group') } let_it_be(:project_group) { create(:group, :public, parent: root_group, name: 'project group') } let_it_be(:shared_group_with_dev_access) { create(:group, :private, parent: root_group, name: 'shared group') } - let_it_be(:shared_group_with_reporter_access) { create(:group, :private) } + let_it_be(:shared_group_with_reporter_access) { create(:group, :public) } let_it_be(:private_project) { create(:project, :private, group: project_group) } let_it_be(:public_project) { create(:project, :public, group: project_group) } @@ -1765,6 +1765,14 @@ RSpec.describe API::Projects do end end + context 'when shared_visible_only is on' do + let(:params) { super().merge(shared_visible_only: true) } + + it_behaves_like 'successful groups response' do + let(:expected_groups) { [root_group, project_group, shared_group_with_reporter_access] } + end + end + context 'when search by shared group name' do let(:params) { super().merge(search: 'shared') } diff --git a/spec/services/ci/create_web_ide_terminal_service_spec.rb b/spec/services/ci/create_web_ide_terminal_service_spec.rb index a0974247918..0804773442d 100644 --- a/spec/services/ci/create_web_ide_terminal_service_spec.rb +++ b/spec/services/ci/create_web_ide_terminal_service_spec.rb @@ -28,16 +28,6 @@ RSpec.describe Ci::CreateWebIdeTerminalService do end subject end - - context 'when the ci_pipeline_ensure_iid_on_save feature flag is off' do - it 'does not call ensure_project_iid explicitly' do - stub_feature_flags(ci_pipeline_ensure_iid_on_save: false) - expect_next_instance_of(Ci::Pipeline) do |instance| - expect(instance).to receive(:ensure_project_iid!).once - end - subject - end - end end before do diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb index 9e62eef14de..5915ffe202d 100644 --- a/spec/support/helpers/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -3,6 +3,38 @@ module CycleAnalyticsHelpers include GitHelpers + def toggle_value_stream_dropdown + page.find('[data-testid="dropdown-value-streams"]').click + end + + def add_custom_stage_to_form + page.find_button(s_('CreateValueStreamForm|Add another stage')).click + + index = page.all('[data-testid="value-stream-stage-fields"]').length + last_stage = page.all('[data-testid="value-stream-stage-fields"]').last + + within last_stage do + find('[name*="custom-stage-name-"]').fill_in with: "Cool custom stage - name #{index}" + select_dropdown_option_by_value "custom-stage-start-event-", :merge_request_created + select_dropdown_option_by_value "custom-stage-end-event-", :merge_request_merged + end + end + + def save_value_stream(custom_value_stream_name) + fill_in 'create-value-stream-name', with: custom_value_stream_name + + page.find_button(s_('CreateValueStreamForm|Create Value Stream')).click + wait_for_requests + end + + def create_custom_value_stream(custom_value_stream_name) + toggle_value_stream_dropdown + page.find_button(_('Create new Value Stream')).click + + add_custom_stage_to_form + save_value_stream(custom_value_stream_name) + end + def wait_for_stages_to_load(selector = '.js-path-navigation') expect(page).to have_selector selector wait_for_requests |