Skip to content
Snippets Groups Projects
Commit 8957ace3 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 232e0a31
No related branches found
No related tags found
No related merge requests found
Showing
with 153 additions and 179 deletions
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe JobsFinder, '#execute' do
describe Ci::JobsFinder, '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create(:user, :admin) }
let_it_be(:project) { create(:project, :private, public_builds: false) }
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe PipelineSchedulesFinder do
describe Ci::PipelineSchedulesFinder do
let(:project) { create(:project) }
 
let!(:active_schedule) { create(:ci_pipeline_schedule, project: project) }
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe PipelinesFinder do
describe Ci::PipelinesFinder do
let(:project) { create(:project, :public, :repository) }
let(:current_user) { nil }
let(:params) { {} }
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe RunnerJobsFinder do
describe Ci::RunnerJobsFinder do
let(:project) { create(:project) }
let(:runner) { create(:ci_runner, :instance) }
 
Loading
Loading
import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import component from '~/blob/notebook/notebook_viewer.vue';
import NotebookLab from '~/notebook/index.vue';
import waitForPromises from 'helpers/wait_for_promises';
describe('iPython notebook renderer', () => {
let wrapper;
let mock;
const endpoint = 'test';
const mockNotebook = {
cells: [
{
cell_type: 'markdown',
source: ['# test'],
},
{
cell_type: 'code',
execution_count: 1,
source: ['def test(str)', ' return str'],
outputs: [],
},
],
};
const mountComponent = () => {
wrapper = shallowMount(component, { propsData: { endpoint } });
};
const findLoading = () => wrapper.find(GlLoadingIcon);
const findNotebookLab = () => wrapper.find(NotebookLab);
const findLoadErrorMessage = () => wrapper.find({ ref: 'loadErrorMessage' });
const findParseErrorMessage = () => wrapper.find({ ref: 'parsingErrorMessage' });
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
mock.restore();
});
it('shows loading icon', () => {
mock.onGet(endpoint).reply(() => new Promise(() => {}));
mountComponent({ loadFile: jest.fn() });
expect(findLoading().exists()).toBe(true);
});
describe('successful response', () => {
beforeEach(() => {
mock.onGet(endpoint).reply(200, mockNotebook);
mountComponent();
return waitForPromises();
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('renders the notebook', () => {
expect(findNotebookLab().exists()).toBe(true);
});
});
describe('error in JSON response', () => {
beforeEach(() => {
mock.onGet(endpoint).reply(() =>
// eslint-disable-next-line prefer-promise-reject-errors
Promise.reject({ status: 200 }),
);
mountComponent();
return waitForPromises();
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('shows error message', () => {
expect(findParseErrorMessage().text()).toEqual('An error occurred while parsing the file.');
});
});
describe('error getting file', () => {
beforeEach(() => {
mock.onGet(endpoint).reply(500, '');
mountComponent();
return waitForPromises();
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('shows error message', () => {
expect(findLoadErrorMessage().text()).toEqual(
'An error occurred while loading the file. Please try again later.',
);
});
});
});
<div class="file-content" data-endpoint="/test" id="js-notebook-viewer"></div>
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import renderNotebook from '~/blob/notebook';
describe('iPython notebook renderer', () => {
preloadFixtures('static/notebook_viewer.html');
beforeEach(() => {
loadFixtures('static/notebook_viewer.html');
});
it('shows loading icon', () => {
renderNotebook();
expect(document.querySelector('.loading')).not.toBeNull();
});
describe('successful response', () => {
let mock;
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(200, {
cells: [
{
cell_type: 'markdown',
source: ['# test'],
},
{
cell_type: 'code',
execution_count: 1,
source: ['def test(str)', ' return str'],
outputs: [],
},
],
});
renderNotebook();
setTimeout(() => {
done();
});
});
afterEach(() => {
mock.restore();
});
it('does not show loading icon', () => {
expect(document.querySelector('.loading')).toBeNull();
});
it('renders the notebook', () => {
expect(document.querySelector('.md')).not.toBeNull();
});
it('renders the markdown cell', () => {
expect(document.querySelector('h1')).not.toBeNull();
expect(document.querySelector('h1').textContent.trim()).toBe('test');
});
it('highlights code', () => {
expect(document.querySelector('.token')).not.toBeNull();
expect(document.querySelector('.language-python')).not.toBeNull();
});
});
describe('error in JSON response', () => {
let mock;
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(() =>
// eslint-disable-next-line prefer-promise-reject-errors
Promise.reject({ status: 200, data: '{ "cells": [{"cell_type": "markdown"} }' }),
);
renderNotebook();
setTimeout(() => {
done();
});
});
afterEach(() => {
mock.restore();
});
it('does not show loading icon', () => {
expect(document.querySelector('.loading')).toBeNull();
});
it('shows error message', () => {
expect(document.querySelector('.md').textContent.trim()).toBe(
'An error occurred while parsing the file.',
);
});
});
describe('error getting file', () => {
let mock;
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(500, '');
renderNotebook();
setTimeout(() => {
done();
});
});
afterEach(() => {
mock.restore();
});
it('does not show loading icon', () => {
expect(document.querySelector('.loading')).toBeNull();
});
it('shows error message', () => {
expect(document.querySelector('.md').textContent.trim()).toBe(
'An error occurred while loading the file. Please try again later.',
);
});
});
});
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe Gitlab::GithubImport::Caching, :clean_gitlab_redis_cache do
describe Gitlab::Cache::Import::Caching, :clean_gitlab_redis_cache do
describe '.read' do
it 'reads a value from the cache' do
described_class.write('foo', 'bar')
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@ describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache do
 
describe '#cache_database_id' do
it 'caches the ID of a database row' do
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with('github-import/issuable-finder/4/MergeRequest/1', 10)
 
Loading
Loading
Loading
Loading
@@ -21,7 +21,7 @@ describe Gitlab::GithubImport::LabelFinder, :clean_gitlab_redis_cache do
it 'returns nil for an empty cache key' do
key = finder.cache_key_for(bug.name)
 
Gitlab::GithubImport::Caching.write(key, '')
Gitlab::Cache::Import::Caching.write(key, '')
 
expect(finder.id_for(bug.name)).to be_nil
end
Loading
Loading
@@ -40,7 +40,7 @@ describe Gitlab::GithubImport::LabelFinder, :clean_gitlab_redis_cache do
 
describe '#build_cache' do
it 'builds the cache of all project labels' do
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write_multiple)
.with(
{
Loading
Loading
Loading
Loading
@@ -22,7 +22,7 @@ describe Gitlab::GithubImport::MilestoneFinder, :clean_gitlab_redis_cache do
it 'returns nil for an empty cache key' do
key = finder.cache_key_for(milestone.iid)
 
Gitlab::GithubImport::Caching.write(key, '')
Gitlab::Cache::Import::Caching.write(key, '')
 
expect(finder.id_for(issuable)).to be_nil
end
Loading
Loading
@@ -41,7 +41,7 @@ describe Gitlab::GithubImport::MilestoneFinder, :clean_gitlab_redis_cache do
 
describe '#build_cache' do
it 'builds the cache of all project milestones' do
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write_multiple)
.with("github-import/milestone-finder/#{project.id}/1" => milestone.id)
.and_call_original
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache do
end
 
it 'sets the initial page number to the cached value when one is present' do
Gitlab::GithubImport::Caching.write(counter.cache_key, 2)
Gitlab::Cache::Import::Caching.write(counter.cache_key, 2)
 
expect(described_class.new(project, :issues).current).to eq(2)
end
Loading
Loading
Loading
Loading
@@ -57,7 +57,7 @@ describe Gitlab::GithubImport::ParallelScheduling do
 
expect(importer).to receive(:parallel_import)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:expire)
.with(importer.already_imported_cache_key, a_kind_of(Numeric))
 
Loading
Loading
@@ -287,7 +287,7 @@ describe Gitlab::GithubImport::ParallelScheduling do
.with(object)
.and_return(object.id)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:set_add)
.with(importer.already_imported_cache_key, object.id)
.and_call_original
Loading
Loading
Loading
Loading
@@ -162,7 +162,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
 
context 'when an Email address is cached' do
it 'reads the Email address from the cache' do
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:read)
.and_return(email)
 
Loading
Loading
@@ -182,7 +182,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
it 'caches the Email address when an Email address is available' do
expect(client).to receive(:user).with('kittens').and_return(user)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with(an_instance_of(String), email)
 
Loading
Loading
@@ -195,7 +195,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
.with('kittens')
.and_return(nil)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.not_to receive(:write)
 
expect(finder.email_for_github_username('kittens')).to be_nil
Loading
Loading
@@ -207,7 +207,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
let(:id) { 4 }
 
it 'reads a user ID from the cache' do
Gitlab::GithubImport::Caching
Gitlab::Cache::Import::Caching
.write(described_class::ID_CACHE_KEY % id, 4)
 
expect(finder.cached_id_for_github_id(id)).to eq([true, 4])
Loading
Loading
@@ -222,7 +222,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
let(:email) { 'kittens@example.com' }
 
it 'reads a user ID from the cache' do
Gitlab::GithubImport::Caching
Gitlab::Cache::Import::Caching
.write(described_class::ID_FOR_EMAIL_CACHE_KEY % email, 4)
 
expect(finder.cached_id_for_github_email(email)).to eq([true, 4])
Loading
Loading
@@ -241,7 +241,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
.with(id)
.and_return(42)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with(described_class::ID_CACHE_KEY % id, 42)
 
Loading
Loading
@@ -253,7 +253,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
.with(id)
.and_return(nil)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with(described_class::ID_CACHE_KEY % id, nil)
 
Loading
Loading
@@ -269,7 +269,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
.with(email)
.and_return(42)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with(described_class::ID_FOR_EMAIL_CACHE_KEY % email, 42)
 
Loading
Loading
@@ -281,7 +281,7 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
.with(email)
.and_return(nil)
 
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.with(described_class::ID_FOR_EMAIL_CACHE_KEY % email, nil)
 
Loading
Loading
@@ -317,13 +317,13 @@ describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do
 
describe '#read_id_from_cache' do
it 'reads an ID from the cache' do
Gitlab::GithubImport::Caching.write('foo', 10)
Gitlab::Cache::Import::Caching.write('foo', 10)
 
expect(finder.read_id_from_cache('foo')).to eq([true, 10])
end
 
it 'reads a cache key with an empty value' do
Gitlab::GithubImport::Caching.write('foo', nil)
Gitlab::Cache::Import::Caching.write('foo', nil)
 
expect(finder.read_id_from_cache('foo')).to eq([true, nil])
end
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ describe Gitlab::GithubImport do
end
 
it 'caches the ghost user ID' do
expect(Gitlab::GithubImport::Caching)
expect(Gitlab::Cache::Import::Caching)
.to receive(:write)
.once
.and_call_original
Loading
Loading
Loading
Loading
@@ -387,29 +387,6 @@ describe Gitlab::UsageData do
expect(described_class.count(relation, fallback: 15, batch: false)).to eq(15)
end
end
describe '#approximate_counts' do
it 'gets approximate counts for selected models', :aggregate_failures do
create(:label)
expect(Gitlab::Database::Count).to receive(:approximate_counts)
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
counts = described_class.approximate_counts.values
expect(counts.count).to eq(described_class::APPROXIMATE_COUNT_MODELS.count)
expect(counts.any? { |count| count < 0 }).to be_falsey
end
it 'returns default values if counts can not be retrieved', :aggregate_failures do
described_class::APPROXIMATE_COUNT_MODELS.map do |model|
model.name.underscore.pluralize.to_sym
end
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return({})
expect(described_class.approximate_counts.values.uniq).to eq([-1])
end
end
end
end
end
Loading
Loading
@@ -832,6 +832,13 @@ describe API::Users, :do_not_mock_admin_mode do
expect(user.reload.private_profile).to eq(false)
end
 
it "does have default values for theme and color-scheme ID" do
put api("/users/#{user.id}", admin), params: {}
expect(user.reload.theme_id).to eq(Gitlab::Themes.default.id)
expect(user.reload.color_scheme_id).to eq(Gitlab::ColorSchemes.default.id)
end
it "updates private profile" do
put api("/users/#{user.id}", admin), params: { private_profile: true }
 
Loading
Loading
@@ -857,6 +864,19 @@ describe API::Users, :do_not_mock_admin_mode do
expect(user.reload.private_profile).to eq(true)
end
 
it "does not modify theme or color-scheme ID when field is not provided" do
theme = Gitlab::Themes.each.find { |t| t.id != Gitlab::Themes.default.id }
scheme = Gitlab::ColorSchemes.each.find { |t| t.id != Gitlab::ColorSchemes.default.id }
user.update(theme_id: theme.id, color_scheme_id: scheme.id)
put api("/users/#{user.id}", admin), params: {}
expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.theme_id).to eq(theme.id)
expect(user.reload.color_scheme_id).to eq(scheme.id)
end
it "does not update admin status" do
put api("/users/#{admin_user.id}", admin), params: { can_create_group: false }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment