summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-30 03:07:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-30 03:07:30 +0000
commitdbb27a91536f29550f7714356ab499d318e9d7e2 (patch)
treeab0aa16d03a04aec036d18cce0992f81d594026e /spec
parente222250937b497b4cf6e9b8e5ddde0097f0e0954 (diff)
downloadgitlab-ce-dbb27a91536f29550f7714356ab499d318e9d7e2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/boards/boards_spec.rb3
-rw-r--r--spec/frontend/filtered_search/filtered_search_manager_spec.js5
-rw-r--r--spec/frontend/filtered_search/visual_token_value_spec.js8
-rw-r--r--spec/frontend/sidebar/sidebar_move_issue_spec.js6
-rw-r--r--spec/graphql/types/issuable_searchable_field_enum_spec.rb13
-rw-r--r--spec/initializers/mailer_retries_spec.rb18
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb27
-rw-r--r--spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb6
-rw-r--r--spec/lib/marginalia_spec.rb16
-rw-r--r--spec/models/integration_spec.rb18
-rw-r--r--spec/models/integrations/redmine_spec.rb10
-rw-r--r--spec/requests/api/group_avatar_spec.rb20
-rw-r--r--spec/requests/api/releases_spec.rb16
-rw-r--r--spec/services/notification_service_spec.rb4
-rw-r--r--spec/support/sidekiq.rb21
-rw-r--r--spec/uploaders/object_storage_spec.rb6
16 files changed, 130 insertions, 67 deletions
diff --git a/spec/features/boards/boards_spec.rb b/spec/features/boards/boards_spec.rb
index 02bb7574fb0..4b52bb953ed 100644
--- a/spec/features/boards/boards_spec.rb
+++ b/spec/features/boards/boards_spec.rb
@@ -244,8 +244,7 @@ RSpec.describe 'Project issue boards', :js do
expect(page).to have_selector(selector, text: development.title, count: 1)
end
- # TODO https://gitlab.com/gitlab-org/gitlab/-/issues/323551
- xit 'issue moves between lists and does not show the "Development" label since the card is in the "Development" list label' do
+ it 'issue moves between lists and does not show the "Development" label since the card is in the "Development" list label' do
drag(list_from_index: 1, from_index: 1, list_to_index: 2)
wait_for_board_cards(2, 7)
diff --git a/spec/frontend/filtered_search/filtered_search_manager_spec.js b/spec/frontend/filtered_search/filtered_search_manager_spec.js
index c03c8f6c529..51e2dc3449b 100644
--- a/spec/frontend/filtered_search/filtered_search_manager_spec.js
+++ b/spec/frontend/filtered_search/filtered_search_manager_spec.js
@@ -8,10 +8,12 @@ import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered
import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
import RecentSearchesService from '~/filtered_search/services/recent_searches_service';
import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error';
+import createFlash from '~/flash';
import * as commonUtils from '~/lib/utils/common_utils';
import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes';
import { visitUrl } from '~/lib/utils/url_utility';
+jest.mock('~/flash');
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
visitUrl: jest.fn(),
@@ -127,11 +129,10 @@ describe('Filtered Search Manager', () => {
jest
.spyOn(RecentSearchesService.prototype, 'fetch')
.mockImplementation(() => Promise.reject(new RecentSearchesServiceError()));
- jest.spyOn(window, 'Flash').mockImplementation();
manager.setup();
- expect(window.Flash).not.toHaveBeenCalled();
+ expect(createFlash).not.toHaveBeenCalled();
});
});
diff --git a/spec/frontend/filtered_search/visual_token_value_spec.js b/spec/frontend/filtered_search/visual_token_value_spec.js
index 772fa7d07ed..7185f382fc1 100644
--- a/spec/frontend/filtered_search/visual_token_value_spec.js
+++ b/spec/frontend/filtered_search/visual_token_value_spec.js
@@ -1,11 +1,14 @@
import { escape } from 'lodash';
import FilteredSearchSpecHelper from 'helpers/filtered_search_spec_helper';
import { TEST_HOST } from 'helpers/test_constants';
-import DropdownUtils from '~/filtered_search//dropdown_utils';
+import DropdownUtils from '~/filtered_search/dropdown_utils';
import VisualTokenValue from '~/filtered_search/visual_token_value';
+import createFlash from '~/flash';
import AjaxCache from '~/lib/utils/ajax_cache';
import UsersCache from '~/lib/utils/users_cache';
+jest.mock('~/flash');
+
describe('Filtered Search Visual Tokens', () => {
const findElements = (tokenElement) => {
const tokenNameElement = tokenElement.querySelector('.name');
@@ -43,7 +46,6 @@ describe('Filtered Search Visual Tokens', () => {
});
it('ignores error if UsersCache throws', (done) => {
- jest.spyOn(window, 'Flash').mockImplementation(() => {});
const dummyError = new Error('Earth rotated backwards');
const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken);
const tokenValue = tokenValueElement.innerText;
@@ -55,7 +57,7 @@ describe('Filtered Search Visual Tokens', () => {
subject
.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue)
.then(() => {
- expect(window.Flash.mock.calls.length).toBe(0);
+ expect(createFlash.mock.calls.length).toBe(0);
})
.then(done)
.catch(done.fail);
diff --git a/spec/frontend/sidebar/sidebar_move_issue_spec.js b/spec/frontend/sidebar/sidebar_move_issue_spec.js
index 6a7758ace40..d9972ae75c3 100644
--- a/spec/frontend/sidebar/sidebar_move_issue_spec.js
+++ b/spec/frontend/sidebar/sidebar_move_issue_spec.js
@@ -1,5 +1,6 @@
import MockAdapter from 'axios-mock-adapter';
import $ from 'jquery';
+import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import SidebarMoveIssue from '~/sidebar/lib/sidebar_move_issue';
import SidebarService from '~/sidebar/services/sidebar_service';
@@ -7,6 +8,8 @@ import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarStore from '~/sidebar/stores/sidebar_store';
import Mock from './mock_data';
+jest.mock('~/flash');
+
describe('SidebarMoveIssue', () => {
let mock;
const test = {};
@@ -99,7 +102,6 @@ describe('SidebarMoveIssue', () => {
});
it('should remove loading state from confirm button on failure', (done) => {
- jest.spyOn(window, 'Flash').mockImplementation(() => {});
jest.spyOn(test.mediator, 'moveIssue').mockReturnValue(Promise.reject());
test.mediator.setMoveToProjectId(7);
@@ -108,7 +110,7 @@ describe('SidebarMoveIssue', () => {
expect(test.mediator.moveIssue).toHaveBeenCalled();
// Wait for the move issue request to fail
setImmediate(() => {
- expect(window.Flash).toHaveBeenCalled();
+ expect(createFlash).toHaveBeenCalled();
expect(test.$confirmButton.prop('disabled')).toBeFalsy();
expect(test.$confirmButton.hasClass('is-loading')).toBe(false);
done();
diff --git a/spec/graphql/types/issuable_searchable_field_enum_spec.rb b/spec/graphql/types/issuable_searchable_field_enum_spec.rb
new file mode 100644
index 00000000000..13e1b55ac7b
--- /dev/null
+++ b/spec/graphql/types/issuable_searchable_field_enum_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Types::IssuableSearchableFieldEnum do
+ specify { expect(described_class.graphql_name).to eq('IssuableSearchableField') }
+
+ it 'exposes all the issuable searchable fields' do
+ expect(described_class.values.keys).to contain_exactly(
+ *Issuable::SEARCHABLE_FIELDS.map(&:upcase)
+ )
+ end
+end
diff --git a/spec/initializers/mailer_retries_spec.rb b/spec/initializers/mailer_retries_spec.rb
index c1e56784ad9..a220188cc29 100644
--- a/spec/initializers/mailer_retries_spec.rb
+++ b/spec/initializers/mailer_retries_spec.rb
@@ -2,22 +2,8 @@
require 'spec_helper'
-RSpec.describe 'Mailer retries' do
- # We need to ensure that this runs through Sidekiq to take
- # advantage of the middleware. There is a Rails bug that means we
- # have to do some extra steps to make this happen:
- # https://github.com/rails/rails/issues/37270#issuecomment-553927324
- around do |example|
- descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
- descendants.each(&:disable_test_adapter)
- ActiveJob::Base.queue_adapter = :sidekiq
-
- example.run
-
- descendants.each { |a| a.queue_adapter = :test }
- end
-
- it 'sets retries for mailers to 3', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332645' do
+RSpec.describe 'Mailer retries', :sidekiq_mailers do
+ it 'sets retries for mailers to 3' do
DeviseMailer.user_admin_approval(create(:user)).deliver_later
expect(Sidekiq::Queues['mailers'].first).to include('retry' => 3)
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
index fa8b5e6ccf0..a6da40f47f1 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
@@ -167,6 +167,19 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestReviewImporter, :clean
end
end
+ context 'when the submitted_at is not provided' do
+ let(:review) { create_review(type: 'APPROVED', note: '', submitted_at: nil) }
+
+ it 'creates a note for the review without the author information' do
+ expect { subject.execute }.to change(Note, :count).by(1)
+
+ last_note = merge_request.notes.last
+
+ expect(last_note.created_at)
+ .to be_within(1.second).of(merge_request.updated_at)
+ end
+ end
+
context 'when the review has a note text' do
context 'when the review is "APPROVED"' do
let(:review) { create_review(type: 'APPROVED') }
@@ -215,13 +228,15 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestReviewImporter, :clean
end
end
- def create_review(type:, note: 'note', author: { id: 999, login: 'author' })
+ def create_review(type:, **extra)
Gitlab::GithubImport::Representation::PullRequestReview.from_json_hash(
- merge_request_id: merge_request.id,
- review_type: type,
- note: note,
- submitted_at: submitted_at.to_s,
- author: author
+ extra.reverse_merge(
+ author: { id: 999, login: 'author' },
+ merge_request_id: merge_request.id,
+ review_type: type,
+ note: 'note',
+ submitted_at: submitted_at.to_s
+ )
)
end
end
diff --git a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb
index f9763455468..cad9b13774e 100644
--- a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb
+++ b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb
@@ -68,5 +68,11 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
expect(review.author).to be_nil
end
+
+ it 'does not fail when submitted_at is blank' do
+ review = described_class.from_json_hash(hash.except('submitted_at'))
+
+ expect(review.submitted_at).to be_nil
+ end
end
end
diff --git a/spec/lib/marginalia_spec.rb b/spec/lib/marginalia_spec.rb
index 040f70236c6..dd57cd7980e 100644
--- a/spec/lib/marginalia_spec.rb
+++ b/spec/lib/marginalia_spec.rb
@@ -89,21 +89,7 @@ RSpec.describe 'Marginalia spec' do
end
end
- describe 'for ActionMailer delivery jobs' do
- # We need to ensure that this runs through Sidekiq to take
- # advantage of the middleware. There is a Rails bug that means we
- # have to do some extra steps to make this happen:
- # https://github.com/rails/rails/issues/37270#issuecomment-553927324
- around do |example|
- descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
- descendants.each(&:disable_test_adapter)
- ActiveJob::Base.queue_adapter = :sidekiq
-
- example.run
-
- descendants.each { |a| a.queue_adapter = :test }
- end
-
+ describe 'for ActionMailer delivery jobs', :sidekiq_mailers do
let(:delivery_job) { MarginaliaTestMailer.first_user.deliver_later }
let(:recorded) do
diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb
index dabcaac1e33..190c0b9b2e4 100644
--- a/spec/models/integration_spec.rb
+++ b/spec/models/integration_spec.rb
@@ -145,35 +145,29 @@ RSpec.describe Integration do
describe '#can_test?' do
subject { integration.can_test? }
- context 'when repository is not empty' do
- let(:project) { build(:project, :repository) }
-
- it { is_expected.to be true }
- end
-
- context 'when repository is empty' do
- let(:project) { build(:project) }
+ context 'when project-level integration' do
+ let(:project) { create(:project) }
it { is_expected.to be true }
end
- context 'when instance-level service' do
+ context 'when instance-level integration' do
Integration.available_integration_types.each do |type|
let(:integration) do
described_class.send(:integration_type_to_model, type).new(instance: true)
end
- it { is_expected.to be_falsey }
+ it { is_expected.to be false }
end
end
- context 'when group-level service' do
+ context 'when group-level integration' do
Integration.available_integration_types.each do |type|
let(:integration) do
described_class.send(:integration_type_to_model, type).new(group_id: group.id)
end
- it { is_expected.to be_falsey }
+ it { is_expected.to be false }
end
end
end
diff --git a/spec/models/integrations/redmine_spec.rb b/spec/models/integrations/redmine_spec.rb
index 083585d4fed..1fc4a4970c1 100644
--- a/spec/models/integrations/redmine_spec.rb
+++ b/spec/models/integrations/redmine_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Integrations::Redmine do
allow(Gitlab.config).to receive(:issues_tracker).and_return(settings)
end
- context 'when service is active' do
+ context 'when integration is active' do
before do
subject.active = true
end
@@ -27,12 +27,12 @@ RSpec.describe Integrations::Redmine do
it { is_expected.to validate_presence_of(:issues_url) }
it { is_expected.to validate_presence_of(:new_issue_url) }
- it_behaves_like 'issue tracker service URL attribute', :project_url
- it_behaves_like 'issue tracker service URL attribute', :issues_url
- it_behaves_like 'issue tracker service URL attribute', :new_issue_url
+ it_behaves_like 'issue tracker integration URL attribute', :project_url
+ it_behaves_like 'issue tracker integration URL attribute', :issues_url
+ it_behaves_like 'issue tracker integration URL attribute', :new_issue_url
end
- context 'when service is inactive' do
+ context 'when integration is inactive' do
before do
subject.active = false
end
diff --git a/spec/requests/api/group_avatar_spec.rb b/spec/requests/api/group_avatar_spec.rb
index e56b3792c47..50379d29b09 100644
--- a/spec/requests/api/group_avatar_spec.rb
+++ b/spec/requests/api/group_avatar_spec.rb
@@ -9,9 +9,9 @@ RSpec.describe API::GroupAvatar do
describe 'GET /groups/:id/avatar' do
context 'when the group is public' do
- it 'retrieves the avatar successfully' do
- group = create(:group, :public, :with_avatar)
+ let(:group) { create(:group, :public, :with_avatar) }
+ it 'retrieves the avatar successfully' do
get api(avatar_path(group))
expect(response).to have_gitlab_http_status(:ok)
@@ -19,6 +19,22 @@ RSpec.describe API::GroupAvatar do
.to eq(%(attachment; filename="dk.png"; filename*=UTF-8''dk.png))
end
+ context 'when the avatar is in the object storage' do
+ before do
+ stub_uploads_object_storage(AvatarUploader)
+
+ group.avatar.migrate!(ObjectStorage::Store::REMOTE)
+ end
+
+ it 'redirects to the file in the object storage' do
+ get api(avatar_path(group))
+
+ expect(response).to have_gitlab_http_status(:found)
+ expect(response.headers['Content-Disposition'])
+ .to eq(%(attachment; filename="dk.png"; filename*=UTF-8''dk.png))
+ end
+ end
+
context 'when the group does not have avatar' do
it 'returns :not_found' do
group = create(:group, :public)
diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb
index 81a4fcdbcac..8aec18c9c1b 100644
--- a/spec/requests/api/releases_spec.rb
+++ b/spec/requests/api/releases_spec.rb
@@ -463,9 +463,23 @@ RSpec.describe API::Releases do
end
context 'when specified tag is not found in the project' do
- it 'cannot find the release entry' do
+ it 'returns 404 for maintater' do
get api("/projects/#{project.id}/releases/non_exist_tag", maintainer)
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('404 Not Found')
+ end
+
+ it 'returns project not found for no user' do
+ get api("/projects/#{project.id}/releases/non_exist_tag", nil)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('404 Project Not Found')
+ end
+
+ it 'returns forbidden for guest' do
+ get api("/projects/#{project.id}/releases/non_existing_tag", guest)
+
expect(response).to have_gitlab_http_status(:forbidden)
end
end
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 6b1291042dd..cf36457309c 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -929,6 +929,10 @@ RSpec.describe NotificationService, :mailer do
end
context 'design management is disabled' do
+ before do
+ enable_design_management(false)
+ end
+
it 'does not notify anyone' do
notification.new_note(note)
diff --git a/spec/support/sidekiq.rb b/spec/support/sidekiq.rb
index 374997af1ec..dc475b92c0b 100644
--- a/spec/support/sidekiq.rb
+++ b/spec/support/sidekiq.rb
@@ -20,4 +20,25 @@ RSpec.configure do |config|
config.around(:example, :sidekiq_inline) do |example|
gitlab_sidekiq_inline { example.run }
end
+
+ # Some specs need to run mailers through Sidekiq explicitly, rather
+ # than the ActiveJob test adapter. There is a Rails bug that means we
+ # have to do some extra steps to make this happen:
+ # https://github.com/rails/rails/issues/37270
+ #
+ # In particular, we can't use an `around` hook because then the 'before' part
+ # of that will run before the `before_setup` hook in ActiveJob::TestHelper,
+ # which doesn't do what we want.
+ #
+ config.before(:example, :sidekiq_mailers) do
+ queue_adapter_changed_jobs.each { |k| k.queue_adapter = :sidekiq }
+ queue_adapter_changed_jobs.each(&:disable_test_adapter)
+ end
+
+ config.after(:example, :sidekiq_mailers) do
+ queue_adapter_changed_jobs.each do |klass|
+ klass.queue_adapter = :test
+ klass.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)
+ end
+ end
end
diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb
index a1d8695a8c9..13f70e3f85b 100644
--- a/spec/uploaders/object_storage_spec.rb
+++ b/spec/uploaders/object_storage_spec.rb
@@ -222,7 +222,11 @@ RSpec.describe ObjectStorage do
before do
stub_artifacts_object_storage
- stub_request(:get, %r{s3.amazonaws.com/#{uploader.path}}).to_return(status: 200, body: '')
+
+ # We need to check the Host header not including the port because AWS does not accept
+ stub_request(:get, %r{s3.amazonaws.com/#{uploader.path}})
+ .with { |request| !request.headers['Host'].to_s.include?(':443') }
+ .to_return(status: 200, body: '')
end
it "returns the file" do