diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 18:09:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-07 18:09:52 +0300 |
commit | e43077ab4742ba5083a01a1e5341db1a1b7a1701 (patch) | |
tree | c33a00fb176caff735243c484bbd594a3b08bb6e /spec | |
parent | 211a8c3361ccf4eb92f36edbdcf15c98fcdcc8b7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
13 files changed, 157 insertions, 262 deletions
diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index c775b77ce1c..f8271bc8e8a 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -37,7 +37,7 @@ describe Projects::GroupLinksController do end end - context 'when user has access to group he want to link project to' do + context 'when user has access to group they want to link project to' do before do group.add_developer(user) end @@ -55,7 +55,7 @@ describe Projects::GroupLinksController do end end - context 'when user doers not have access to group he want to link to' do + context 'when user doers not have access to group they want to link to' do include_context 'link project to group' it 'renders 404' do diff --git a/spec/features/issues/user_creates_branch_and_merge_request_spec.rb b/spec/features/issues/user_creates_branch_and_merge_request_spec.rb index 45da4f30e4f..7eecfd1ccf4 100644 --- a/spec/features/issues/user_creates_branch_and_merge_request_spec.rb +++ b/spec/features/issues/user_creates_branch_and_merge_request_spec.rb @@ -287,7 +287,7 @@ describe 'User creates branch and merge request on issue page', :js do expect(source_message).to have_text('Source is not available') # JavaScript gets refs started with `mas` (entered above) and places the first match. - # User sees `mas` in black color (the part he entered) and the `ter` in gray color (a hint). + # User sees `mas` in black color (the part they entered) and the `ter` in gray color (a hint). # Since hinting is implemented via text selection and rspec/capybara doesn't have matchers for it, # we just checking the whole source name. expect(input_source.value).to eq(project.default_branch) diff --git a/spec/frontend/blob/components/blob_header_default_actions_spec.js b/spec/frontend/blob/components/blob_header_default_actions_spec.js new file mode 100644 index 00000000000..348d68514a3 --- /dev/null +++ b/spec/frontend/blob/components/blob_header_default_actions_spec.js @@ -0,0 +1,64 @@ +import { mount } from '@vue/test-utils'; +import BlobHeaderActions from '~/blob/components/blob_header_default_actions.vue'; +import { + BTN_COPY_CONTENTS_TITLE, + BTN_DOWNLOAD_TITLE, + BTN_RAW_TITLE, +} from '~/blob/components/constants'; +import { GlButtonGroup, GlButton } from '@gitlab/ui'; +import { Blob } from './mock_data'; + +describe('Blob Header Default Actions', () => { + let wrapper; + let btnGroup; + let buttons; + const hrefPrefix = 'http://localhost'; + + function createComponent(props = {}) { + wrapper = mount(BlobHeaderActions, { + propsData: { + blob: Object.assign({}, Blob, props), + }, + }); + } + + beforeEach(() => { + createComponent(); + btnGroup = wrapper.find(GlButtonGroup); + buttons = wrapper.findAll(GlButton); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('renders', () => { + it('gl-button-group component', () => { + expect(btnGroup.exists()).toBe(true); + }); + + it('exactly 3 buttons with predefined actions', () => { + expect(buttons.length).toBe(3); + [BTN_COPY_CONTENTS_TITLE, BTN_RAW_TITLE, BTN_DOWNLOAD_TITLE].forEach((title, i) => { + expect(buttons.at(i).vm.$el.title).toBe(title); + }); + }); + + it('correct href attribute on RAW button', () => { + expect(buttons.at(1).vm.$el.href).toBe(`${hrefPrefix}${Blob.rawPath}`); + }); + + it('correct href attribute on Download button', () => { + expect(buttons.at(2).vm.$el.href).toBe(`${hrefPrefix}${Blob.rawPath}?inline=false`); + }); + }); + + describe('functionally', () => { + it('emits an event when a Copy Contents button is clicked', () => { + jest.spyOn(wrapper.vm, '$emit'); + buttons.at(0).vm.$emit('click'); + + expect(wrapper.vm.$emit).toHaveBeenCalledWith('copy'); + }); + }); +}); diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb index a3e879a3f39..f92dca11136 100644 --- a/spec/helpers/nav_helper_spec.rb +++ b/spec/helpers/nav_helper_spec.rb @@ -83,7 +83,7 @@ describe NavHelper, :do_not_mock_admin_mode do expect(helper.header_links).not_to include(:issues, :merge_requests, :todos, :search) end - it 'shows the search box when the user cannot read cross project and he is visiting a project' do + it 'shows the search box when the user cannot read cross project and they are visiting a project' do helper.instance_variable_set(:@project, create(:project)) expect(helper.header_links).to include(:search) diff --git a/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb deleted file mode 100644 index 0edf87e1354..00000000000 --- a/spec/lib/gitlab/background_migration/activate_prometheus_services_for_shared_cluster_applications_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::BackgroundMigration::ActivatePrometheusServicesForSharedClusterApplications, :migration, schema: 2020_01_14_113341 do - include MigrationHelpers::PrometheusServiceHelpers - - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - let(:services) { table(:services) } - let(:namespace) { namespaces.create(name: 'user', path: 'user') } - let(:project) { projects.create(namespace_id: namespace.id) } - - let(:columns) do - %w(project_id active properties type template push_events - issues_events merge_requests_events tag_push_events - note_events category default wiki_page_events pipeline_events - confidential_issues_events commit_events job_events - confidential_note_events deployment_events) - end - - describe '#perform' do - it 'is idempotent' do - expect { subject.perform(project.id) }.to change { services.order(:id).map { |row| row.attributes } } - - expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } } - end - - context 'non prometheus services' do - it 'does not change them' do - other_type = 'SomeOtherService' - services.create(service_params_for(project.id, active: true, type: other_type)) - - expect { subject.perform(project.id) }.not_to change { services.where(type: other_type).order(:id).map { |row| row.attributes } } - end - end - - context 'prometheus services are configured manually ' do - it 'does not change them' do - properties = '{"api_url":"http://test.dev","manual_configuration":"1"}' - services.create(service_params_for(project.id, properties: properties, active: false)) - - expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } } - end - end - - context 'prometheus integration services do not exist' do - it 'creates missing services entries' do - subject.perform(project.id) - - rows = services.order(:id).map { |row| row.attributes.slice(*columns).symbolize_keys } - - expect([service_params_for(project.id, active: true)]).to eq rows - end - end - - context 'prometheus integration services exist' do - context 'in active state' do - it 'does not change them' do - services.create(service_params_for(project.id, active: true)) - - expect { subject.perform(project.id) }.not_to change { services.order(:id).map { |row| row.attributes } } - end - end - - context 'not in active state' do - it 'sets active attribute to true' do - service = services.create(service_params_for(project.id)) - - expect { subject.perform(project.id) }.to change { service.reload.active? }.from(false).to(true) - end - end - end - end -end diff --git a/spec/lib/gitlab/error_tracking_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb index 08718bc92a1..6764d48d14b 100644 --- a/spec/lib/gitlab/error_tracking_spec.rb +++ b/spec/lib/gitlab/error_tracking_spec.rb @@ -145,6 +145,17 @@ describe Gitlab::ErrorTracking do ) end + context 'with filterable parameters' do + let(:extra) { { test: 1, my_token: 'test' } } + + it 'filters parameters' do + expect(Gitlab::ErrorTracking::Logger).to receive(:error).with( + hash_including({ 'extra.test' => 1, 'extra.my_token' => '[FILTERED]' })) + + described_class.track_exception(exception, extra) + end + end + context 'the exception implements :sentry_extra_data' do let(:extra_info) { { event: 'explosion', size: :massive } } let(:exception) { double(message: 'bang!', sentry_extra_data: extra_info, backtrace: caller) } diff --git a/spec/lib/gitlab/user_access_spec.rb b/spec/lib/gitlab/user_access_spec.rb index 4e7c43a6856..2f4ab2e71db 100644 --- a/spec/lib/gitlab/user_access_spec.rb +++ b/spec/lib/gitlab/user_access_spec.rb @@ -160,7 +160,7 @@ describe Gitlab::UserAccess do expect(access.can_push_to_branch?('master')).to be_falsey end - it 'does not allow the user to push if he does not have push access to the canonical project' do + it 'does not allow the user to push if they do not have push access to the canonical project' do canonical_project.add_guest(user) expect(access.can_push_to_branch?('awesome-feature')).to be_falsey diff --git a/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb b/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb new file mode 100644 index 00000000000..5851b26dba4 --- /dev/null +++ b/spec/migrations/drop_activate_prometheus_services_for_shared_cluster_applications_background_migration_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20200116051619_drop_activate_prometheus_services_for_shared_cluster_applications_background_migration.rb') + +describe DropActivatePrometheusServicesForSharedClusterApplicationsBackgroundMigration, :sidekiq, :redis, :migration, schema: 2020_01_16_051619 do + subject(:migration) { described_class.new } + + describe '#up' do + context 'there are only affected jobs on the queue' do + it 'removes enqueued ActivatePrometheusServicesForSharedClusterApplications background jobs' do + Sidekiq::Testing.disable! do # https://github.com/mperham/sidekiq/wiki/testing#api Sidekiq's API does not have a testing mode + Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1]) + + expect { migration.up }.to change { Sidekiq::Queue.new(described_class::QUEUE).size }.from(1).to(0) + end + end + end + + context "there aren't any affected jobs on the queue" do + it 'skips other enqueued jobs' do + Sidekiq::Testing.disable! do + Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1]) + + expect { migration.up }.not_to change { Sidekiq::Queue.new(described_class::QUEUE).size } + end + end + end + + context "there are multiple types of jobs on the queue" do + it 'skips other enqueued jobs' do + Sidekiq::Testing.disable! do + queue = Sidekiq::Queue.new(described_class::QUEUE) + # this job will be deleted + Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1]) + # this jobs will be skipped + skipped_jobs_args = [['SomeOtherClass', 1], [described_class::DROPPED_JOB_CLASS, 'wrong id type'], [described_class::DROPPED_JOB_CLASS, 1, 'some wired argument']] + skipped_jobs_args.each do |args| + Sidekiq::Client.push('queue' => described_class::QUEUE, 'class' => ::BackgroundMigrationWorker, 'args' => args) + end + + migration.up + + expect(queue.size).to be 3 + expect(queue.map(&:args)).to match_array skipped_jobs_args + end + end + end + + context "other queues" do + it 'does not modify them' do + Sidekiq::Testing.disable! do + Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => ['SomeOtherClass', 1]) + Sidekiq::Client.push('queue' => 'other', 'class' => ::BackgroundMigrationWorker, 'args' => [described_class::DROPPED_JOB_CLASS, 1]) + + expect { migration.up }.not_to change { Sidekiq::Queue.new('other').size } + end + end + end + end +end diff --git a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb deleted file mode 100644 index 170251277e2..00000000000 --- a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb +++ /dev/null @@ -1,134 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require Rails.root.join('db', 'post_migrate', '20200114113341_patch_prometheus_services_for_shared_cluster_applications.rb') - -describe PatchPrometheusServicesForSharedClusterApplications, :migration do - include MigrationHelpers::PrometheusServiceHelpers - - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - let(:services) { table(:services) } - let(:clusters) { table(:clusters) } - let(:cluster_groups) { table(:cluster_groups) } - let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) } - let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') } - - let(:application_statuses) do - { - errored: -1, - installed: 3, - updated: 5 - } - end - - let(:cluster_types) do - { - instance_type: 1, - group_type: 2 - } - end - - describe '#up' do - let!(:project_with_missing_service) { projects.create!(name: 'gitlab', path: 'gitlab-ce', namespace_id: namespace.id) } - let(:project_with_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - let(:project_with_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - let(:project_with_manual_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - let(:project_with_manual_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - let(:project_with_active_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - let(:project_with_inactive_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } - - before do - services.create(service_params_for(project_with_inactive_service.id, active: false)) - services.create(service_params_for(project_with_active_service.id, active: true)) - services.create(service_params_for(project_with_active_not_prometheus_service.id, active: true, type: 'other')) - services.create(service_params_for(project_with_inactive_not_prometheus_service.id, active: false, type: 'other')) - services.create(service_params_for(project_with_manual_inactive_service.id, active: false, properties: { some: 'data' }.to_json)) - services.create(service_params_for(project_with_manual_active_service.id, active: true, properties: { some: 'data' }.to_json)) - end - - shared_examples 'patch prometheus services post migration' do - context 'prometheus application is installed on the cluster' do - it 'schedules a background migration' do - clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123') - - Sidekiq::Testing.fake! do - Timecop.freeze do - background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]] - - migrate! - - enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] } - expect(enqueued_migrations).to match_array(background_migrations) - end - end - end - end - - context 'prometheus application was recently updated on the cluster' do - it 'schedules a background migration' do - clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123') - - Sidekiq::Testing.fake! do - Timecop.freeze do - background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id], - ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]] - - migrate! - - enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] } - expect(enqueued_migrations).to match_array(background_migrations) - end - end - end - end - - context 'prometheus application failed to install on the cluster' do - it 'does not schedule a background migration' do - clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123') - - Sidekiq::Testing.fake! do - Timecop.freeze do - migrate! - - expect(BackgroundMigrationWorker.jobs.size).to eq 0 - end - end - end - end - - context 'prometheus application is NOT installed on the cluster' do - it 'does not schedule a background migration' do - Sidekiq::Testing.fake! do - Timecop.freeze do - migrate! - - expect(BackgroundMigrationWorker.jobs.size).to eq 0 - end - end - end - end - end - - context 'Cluster is group_type' do - let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:group_type]) } - - before do - cluster_groups.create(group_id: namespace.id, cluster_id: cluster.id) - end - - it_behaves_like 'patch prometheus services post migration' - end - - context 'Cluster is instance_type' do - let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:instance_type]) } - - it_behaves_like 'patch prometheus services post migration' - end - end -end diff --git a/spec/models/board_spec.rb b/spec/models/board_spec.rb index 0987c8e2b65..2d5309b4d23 100644 --- a/spec/models/board_spec.rb +++ b/spec/models/board_spec.rb @@ -16,26 +16,29 @@ describe Board do end describe '#order_by_name_asc' do - let!(:second_board) { create(:board, name: 'Secondary board', project: project) } - let!(:first_board) { create(:board, name: 'First board', project: project) } + let!(:board_B) { create(:board, project: project, name: 'B') } + let!(:board_C) { create(:board, project: project, name: 'C') } + let!(:board_a) { create(:board, project: project, name: 'a') } + let!(:board_A) { create(:board, project: project, name: 'A') } - it 'returns in alphabetical order' do - expect(project.boards.order_by_name_asc).to eq [first_board, second_board] + it 'returns in case-insensitive alphabetical order and then by ascending id' do + expect(project.boards.order_by_name_asc).to eq [board_a, board_A, board_B, board_C] end end describe '#first_board' do - let!(:other_board) { create(:board, name: 'Other board', project: other_project) } - let!(:second_board) { create(:board, name: 'Secondary board', project: project) } - let!(:first_board) { create(:board, name: 'First board', project: project) } + let!(:board_B) { create(:board, project: project, name: 'B') } + let!(:board_C) { create(:board, project: project, name: 'C') } + let!(:board_a) { create(:board, project: project, name: 'a') } + let!(:board_A) { create(:board, project: project, name: 'A') } - it 'return the first alphabetical board as a relation' do - expect(project.boards.first_board).to eq [first_board] + it 'return the first case-insensitive alphabetical board as a relation' do + expect(project.boards.first_board).to eq [board_a] end # BoardsActions#board expects this behavior it 'raises an error when find is done on a non-existent record' do - expect { project.boards.first_board.find(second_board.id) }.to raise_error(ActiveRecord::RecordNotFound) + expect { project.boards.first_board.find(board_A.id) }.to raise_error(ActiveRecord::RecordNotFound) end end end diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb index 06c09b100ac..b466bcb1a12 100644 --- a/spec/requests/api/project_hooks_spec.rb +++ b/spec/requests/api/project_hooks_spec.rb @@ -215,7 +215,7 @@ describe API::ProjectHooks, 'ProjectHooks' do expect(response).to have_gitlab_http_status(404) end - it "returns a 404 if a user attempts to delete project hooks he/she does not own" do + it "returns a 404 if a user attempts to delete project hooks they do not own" do test_user = create(:user) other_project = create(:project) other_project.add_maintainer(test_user) diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index e7d0e91bced..07a1be6c12b 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -988,7 +988,7 @@ describe NotificationService, :mailer do expect(email).to have_header('X-GitLab-NotificationReason', NotificationReason::ASSIGNED) end - it 'emails previous assignee even if he has the "on mention" notif level' do + it 'emails previous assignee even if they have the "on mention" notif level' do issue.assignees = [@u_mentioned] notification.reassigned_issue(issue, @u_disabled, [@u_watcher]) @@ -1005,7 +1005,7 @@ describe NotificationService, :mailer do should_not_email(@u_lazy_participant) end - it 'emails new assignee even if he has the "on mention" notif level' do + it 'emails new assignee even if they have the "on mention" notif level' do issue.assignees = [@u_mentioned] notification.reassigned_issue(issue, @u_disabled, [@u_mentioned]) diff --git a/spec/support/migrations_helpers/prometheus_service_helpers.rb b/spec/support/migrations_helpers/prometheus_service_helpers.rb deleted file mode 100644 index 88f2f71ee1e..00000000000 --- a/spec/support/migrations_helpers/prometheus_service_helpers.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module MigrationHelpers - module PrometheusServiceHelpers - def service_params_for(project_id, params = {}) - { - project_id: project_id, - active: false, - properties: '{}', - type: 'PrometheusService', - template: false, - push_events: true, - issues_events: true, - merge_requests_events: true, - tag_push_events: true, - note_events: true, - category: 'monitoring', - default: false, - wiki_page_events: true, - pipeline_events: true, - confidential_issues_events: true, - commit_events: true, - job_events: true, - confidential_note_events: true, - deployment_events: false - }.merge(params) - end - - def row_attributes(entity) - entity.attributes.with_indifferent_access.tap do |hash| - hash.merge!(hash.slice(:created_at, :updated_at).transform_values { |v| v.to_s(:db) }) - end - end - end -end |