Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-18 06:10:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-18 06:10:30 +0300
commit14facaa466ed56cd0dfad8c0f821ea32f94f94a0 (patch)
tree16f08c5a5d8e1241871a5c4f7398a0e2f0aab445 /spec
parent90e7f31698f6d67da00ed3a68a7392127746ced2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/access_tokens/index_spec.js71
-rw-r--r--spec/lib/api/helpers_spec.rb21
-rw-r--r--spec/models/concerns/routable_spec.rb6
-rw-r--r--spec/models/user_spec.rb14
4 files changed, 59 insertions, 53 deletions
diff --git a/spec/frontend/access_tokens/index_spec.js b/spec/frontend/access_tokens/index_spec.js
index dba6e73f278..1157e44f41a 100644
--- a/spec/frontend/access_tokens/index_spec.js
+++ b/spec/frontend/access_tokens/index_spec.js
@@ -1,7 +1,4 @@
-/* eslint-disable vue/require-prop-types */
-/* eslint-disable vue/one-component-per-file */
import { createWrapper } from '@vue/test-utils';
-import Vue from 'vue';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import {
@@ -10,10 +7,11 @@ import {
initNewAccessTokenApp,
initTokensApp,
} from '~/access_tokens';
-import * as AccessTokenTableApp from '~/access_tokens/components/access_token_table_app.vue';
+import AccessTokenTableApp from '~/access_tokens/components/access_token_table_app.vue';
import ExpiresAtField from '~/access_tokens/components/expires_at_field.vue';
-import * as NewAccessTokenApp from '~/access_tokens/components/new_access_token_app.vue';
-import * as TokensApp from '~/access_tokens/components/tokens_app.vue';
+import NewAccessTokenApp from '~/access_tokens/components/new_access_token_app.vue';
+import TokensApp from '~/access_tokens/components/tokens_app.vue';
+import { FORM_SELECTOR } from '~/access_tokens/components/constants';
import { FEED_TOKEN, INCOMING_EMAIL_TOKEN, STATIC_OBJECT_TOKEN } from '~/access_tokens/constants';
import { __, sprintf } from '~/locale';
@@ -30,25 +28,6 @@ describe('access tokens', () => {
const accessTokenTypePlural = 'personal access tokens';
const initialActiveAccessTokens = [{ revoked_path: '1' }];
- const FakeAccessTokenTableApp = Vue.component('FakeComponent', {
- inject: [
- 'accessTokenType',
- 'accessTokenTypePlural',
- 'initialActiveAccessTokens',
- 'noActiveTokensMessage',
- 'showRole',
- ],
- props: [
- 'accessTokenType',
- 'accessTokenTypePlural',
- 'initialActiveAccessTokens',
- 'noActiveTokensMessage',
- 'showRole',
- ],
- render: () => null,
- });
- AccessTokenTableApp.default = FakeAccessTokenTableApp;
-
it('mounts the component and provides required values', () => {
setHTMLFixture(
`<div id="js-access-token-table-app"
@@ -60,19 +39,18 @@ describe('access tokens', () => {
);
const vueInstance = initAccessTokenTableApp();
-
wrapper = createWrapper(vueInstance);
- const component = wrapper.findComponent(FakeAccessTokenTableApp);
+ const component = wrapper.findComponent({ name: 'AccessTokenTableRoot' });
expect(component.exists()).toBe(true);
-
- expect(component.props()).toMatchObject({
+ expect(wrapper.findComponent(AccessTokenTableApp).vm).toMatchObject({
// Required value
accessTokenType,
accessTokenTypePlural,
initialActiveAccessTokens,
// Default values
+ information: undefined,
noActiveTokensMessage: sprintf(__('This user has no active %{accessTokenTypePlural}.'), {
accessTokenTypePlural,
}),
@@ -81,12 +59,14 @@ describe('access tokens', () => {
});
it('mounts the component and provides all values', () => {
+ const information = 'Additional information';
const noActiveTokensMessage = 'This group has no active access tokens.';
setHTMLFixture(
`<div id="js-access-token-table-app"
data-access-token-type="${accessTokenType}"
data-access-token-type-plural="${accessTokenTypePlural}"
data-initial-active-access-tokens=${JSON.stringify(initialActiveAccessTokens)}
+ data-information="${information}"
data-no-active-tokens-message="${noActiveTokensMessage}"
data-show-role
>
@@ -94,15 +74,15 @@ describe('access tokens', () => {
);
const vueInstance = initAccessTokenTableApp();
-
wrapper = createWrapper(vueInstance);
- const component = wrapper.findComponent(FakeAccessTokenTableApp);
+ const component = wrapper.findComponent({ name: 'AccessTokenTableRoot' });
expect(component.exists()).toBe(true);
- expect(component.props()).toMatchObject({
+ expect(component.findComponent(AccessTokenTableApp).vm).toMatchObject({
accessTokenType,
accessTokenTypePlural,
initialActiveAccessTokens,
+ information,
noActiveTokensMessage,
showRole: true,
});
@@ -157,23 +137,16 @@ describe('access tokens', () => {
it('mounts the component and sets `accessTokenType` prop', () => {
const accessTokenType = 'personal access token';
setHTMLFixture(
- `<div id="js-new-access-token-app" data-access-token-type="${accessTokenType}"></div>`,
+ `<div id="js-new-access-token-app" data-access-token-type="${accessTokenType}"></div>
+ <form id="${FORM_SELECTOR.slice(1)}"></form>`,
);
- const FakeNewAccessTokenApp = Vue.component('FakeComponent', {
- inject: ['accessTokenType'],
- props: ['accessTokenType'],
- render: () => null,
- });
- NewAccessTokenApp.default = FakeNewAccessTokenApp;
-
const vueInstance = initNewAccessTokenApp();
-
wrapper = createWrapper(vueInstance);
- const component = wrapper.findComponent(FakeNewAccessTokenApp);
+ const component = wrapper.findComponent({ name: 'NewAccessTokenRoot' });
expect(component.exists()).toBe(true);
- expect(component.props('accessTokenType')).toEqual(accessTokenType);
+ expect(component.findComponent(NewAccessTokenApp).vm).toMatchObject({ accessTokenType });
});
it('returns `null`', () => {
@@ -192,20 +165,12 @@ describe('access tokens', () => {
`<div id="js-tokens-app" data-tokens-data=${JSON.stringify(tokensData)}></div>`,
);
- const FakeTokensApp = Vue.component('FakeComponent', {
- inject: ['tokenTypes'],
- props: ['tokenTypes'],
- render: () => null,
- });
- TokensApp.default = FakeTokensApp;
-
const vueInstance = initTokensApp();
-
wrapper = createWrapper(vueInstance);
- const component = wrapper.findComponent(FakeTokensApp);
+ const component = wrapper.findComponent(TokensApp);
expect(component.exists()).toBe(true);
- expect(component.props('tokenTypes')).toEqual(tokensData);
+ expect(component.vm).toMatchObject({ tokenTypes: tokensData });
});
it('returns `null`', () => {
diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb
index 3ea42c29ce2..11bbe825402 100644
--- a/spec/lib/api/helpers_spec.rb
+++ b/spec/lib/api/helpers_spec.rb
@@ -110,6 +110,13 @@ RSpec.describe API::Helpers do
end
end
+ context 'when ID is a negative number' do
+ let(:existing_id) { project.id }
+ let(:non_existing_id) { -1 }
+
+ it_behaves_like 'project finder'
+ end
+
context 'when project is pending delete' do
let(:project_pending_delete) { create(:project, pending_delete: true) }
@@ -325,6 +332,13 @@ RSpec.describe API::Helpers do
it_behaves_like 'group finder'
end
+
+ context 'when ID is a negative number' do
+ let(:existing_id) { group.id }
+ let(:non_existing_id) { -1 }
+
+ it_behaves_like 'group finder'
+ end
end
end
@@ -421,6 +435,13 @@ RSpec.describe API::Helpers do
it_behaves_like 'namespace finder'
end
+
+ context 'when ID is a negative number' do
+ let(:existing_id) { namespace.id }
+ let(:non_existing_id) { -1 }
+
+ it_behaves_like 'namespace finder'
+ end
end
shared_examples 'user namespace finder' do
diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb
index cf66ba83e87..dc1002f3560 100644
--- a/spec/models/concerns/routable_spec.rb
+++ b/spec/models/concerns/routable_spec.rb
@@ -23,6 +23,12 @@ RSpec.shared_examples 'routable resource' do
end.not_to exceed_all_query_limit(control_count)
end
+ context 'when path is a negative number' do
+ it 'returns nil' do
+ expect(described_class.find_by_full_path(-1)).to be_nil
+ end
+ end
+
context 'with redirect routes' do
let_it_be(:redirect_route) { create(:redirect_route, source: record) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b08c85339d1..e6d4e9cc2f6 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1166,6 +1166,20 @@ RSpec.describe User do
'ORDER BY "users"."last_activity_on" ASC NULLS FIRST, "users"."id" DESC')
end
end
+
+ describe '.order_recent_sign_in' do
+ it 'sorts users by current_sign_in_at in descending order' do
+ expect(described_class.order_recent_sign_in.to_sql).to include(
+ 'ORDER BY "users"."current_sign_in_at" DESC NULLS LAST')
+ end
+ end
+
+ describe '.order_oldest_sign_in' do
+ it 'sorts users by current_sign_in_at in ascending order' do
+ expect(described_class.order_oldest_sign_in.to_sql).to include(
+ 'ORDER BY "users"."current_sign_in_at" ASC NULLS LAST')
+ end
+ end
end
context 'strip attributes' do