summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-07 18:06:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-07 18:06:21 +0000
commitd8ccc7a00b7a1ea954263170a2044257424a2cfe (patch)
tree0a29cb558aae61795da47c82ce7e87983c5dc4af /spec
parent90a06a20be61bb6d48d77746091492831153e075 (diff)
downloadgitlab-ce-d8ccc7a00b7a1ea954263170a2044257424a2cfe.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb16
-rw-r--r--spec/controllers/projects/commits_controller_spec.rb4
-rw-r--r--spec/controllers/projects/error_tracking_controller_spec.rb2
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb4
-rw-r--r--spec/controllers/projects/releases_controller_spec.rb4
-rw-r--r--spec/controllers/projects/tags_controller_spec.rb2
-rw-r--r--spec/controllers/projects_controller_spec.rb2
-rw-r--r--spec/controllers/uploads_controller_spec.rb24
-rw-r--r--spec/features/projects/pipelines/pipelines_spec.rb5
-rw-r--r--spec/features/projects/tags/user_views_tags_spec.rb2
-rw-r--r--spec/frontend/repository/components/preview/__snapshots__/index_spec.js.snap36
-rw-r--r--spec/frontend/repository/components/preview/index_spec.js49
-rw-r--r--spec/frontend/repository/components/table/index_spec.js66
-rw-r--r--spec/frontend/repository/components/tree_content_spec.js71
-rw-r--r--spec/lib/constraints/project_url_constrainer_spec.rb31
-rw-r--r--spec/lib/gitlab/bitbucket_import/importer_spec.rb1
-rw-r--r--spec/models/concerns/issuable_spec.rb28
-rw-r--r--spec/requests/projects/blob_controller_spec.rb44
-rw-r--r--spec/requests/user_avatar_spec.rb36
-rw-r--r--spec/routing/project_routing_spec.rb4
-rw-r--r--spec/support/controllers/sessionless_auth_controller_shared_examples.rb22
-rw-r--r--spec/support/shared_examples/controllers/todos_shared_examples.rb2
22 files changed, 333 insertions, 122 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index bb7f5ec2b28..481883c50fa 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -90,14 +90,6 @@ describe ApplicationController do
let(:format) { :html }
it_behaves_like 'setting gon variables'
-
- context 'for peek requests' do
- before do
- request.path = '/-/peek'
- end
-
- it_behaves_like 'not setting gon variables'
- end
end
context 'with json format' do
@@ -105,6 +97,12 @@ describe ApplicationController do
it_behaves_like 'not setting gon variables'
end
+
+ context 'with atom format' do
+ let(:format) { :atom }
+
+ it_behaves_like 'not setting gon variables'
+ end
end
describe 'session expiration' do
@@ -186,7 +184,7 @@ describe ApplicationController do
expect(response).to have_gitlab_http_status(404)
end
- it 'redirects to login page if not authenticated' do
+ it 'redirects to login page via authenticate_user! if not authenticated' do
get :index
expect(response).to redirect_to new_user_session_path
diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb
index 1977e92e42b..9c4d6fdcb2a 100644
--- a/spec/controllers/projects/commits_controller_spec.rb
+++ b/spec/controllers/projects/commits_controller_spec.rb
@@ -142,7 +142,7 @@ describe Projects::CommitsController do
context 'token authentication' do
context 'public project' do
- it_behaves_like 'authenticates sessionless user', :show, :atom, { public: true, ignore_incrementing: true } do
+ it_behaves_like 'authenticates sessionless user', :show, :atom, public: true do
before do
public_project = create(:project, :repository, :public)
@@ -152,7 +152,7 @@ describe Projects::CommitsController do
end
context 'private project' do
- it_behaves_like 'authenticates sessionless user', :show, :atom, { public: false, ignore_incrementing: true } do
+ it_behaves_like 'authenticates sessionless user', :show, :atom, public: false do
before do
private_project = create(:project, :repository, :private)
private_project.add_maintainer(user)
diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb
index 31868f5f717..4c224e960a6 100644
--- a/spec/controllers/projects/error_tracking_controller_spec.rb
+++ b/spec/controllers/projects/error_tracking_controller_spec.rb
@@ -146,7 +146,7 @@ describe Projects::ErrorTrackingController do
it 'redirects to sign-in page' do
post :list_projects, params: list_projects_params
- expect(response).to have_gitlab_http_status(:redirect)
+ expect(response).to have_gitlab_http_status(:unauthorized)
end
end
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 8770a5ee303..4c2b58551bf 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -1441,7 +1441,7 @@ describe Projects::IssuesController do
context 'private project with token authentication' do
let(:private_project) { create(:project, :private) }
- it_behaves_like 'authenticates sessionless user', :index, :atom, ignore_incrementing: true do
+ it_behaves_like 'authenticates sessionless user', :index, :atom do
before do
default_params.merge!(project_id: private_project, namespace_id: private_project.namespace)
@@ -1449,7 +1449,7 @@ describe Projects::IssuesController do
end
end
- it_behaves_like 'authenticates sessionless user', :calendar, :ics, ignore_incrementing: true do
+ it_behaves_like 'authenticates sessionless user', :calendar, :ics do
before do
default_params.merge!(project_id: private_project, namespace_id: private_project.namespace)
diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb
index 562119d967f..28ca20d7dab 100644
--- a/spec/controllers/projects/releases_controller_spec.rb
+++ b/spec/controllers/projects/releases_controller_spec.rb
@@ -111,8 +111,8 @@ describe Projects::ReleasesController do
context 'when the project is private and the user is not logged in' do
let(:project) { private_project }
- it 'returns a redirect' do
- expect(response).to have_gitlab_http_status(:redirect)
+ it 'returns a 401' do
+ expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
diff --git a/spec/controllers/projects/tags_controller_spec.rb b/spec/controllers/projects/tags_controller_spec.rb
index f077b4c99fc..b99b5d611fc 100644
--- a/spec/controllers/projects/tags_controller_spec.rb
+++ b/spec/controllers/projects/tags_controller_spec.rb
@@ -41,7 +41,7 @@ describe Projects::TagsController do
context 'private project with token authentication' do
let(:private_project) { create(:project, :repository, :private) }
- it_behaves_like 'authenticates sessionless user', :index, :atom, ignore_incrementing: true do
+ it_behaves_like 'authenticates sessionless user', :index, :atom do
before do
default_params.merge!(project_id: private_project, namespace_id: private_project.namespace)
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 22538565698..321f5ecdbc9 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -1149,7 +1149,7 @@ describe ProjectsController do
context 'private project with token authentication' do
let(:private_project) { create(:project, :private) }
- it_behaves_like 'authenticates sessionless user', :show, :atom, ignore_incrementing: true do
+ it_behaves_like 'authenticates sessionless user', :show, :atom do
before do
default_params.merge!(id: private_project, namespace_id: private_project.namespace)
diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb
index 1bcf3bb106b..f35babc1b56 100644
--- a/spec/controllers/uploads_controller_spec.rb
+++ b/spec/controllers/uploads_controller_spec.rb
@@ -228,10 +228,10 @@ describe UploadsController do
user.block
end
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "user", mounted_as: "avatar", id: user.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
@@ -320,10 +320,10 @@ describe UploadsController do
end
context "when not signed in" do
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
@@ -343,10 +343,10 @@ describe UploadsController do
project.add_maintainer(user)
end
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "project", mounted_as: "avatar", id: project.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
@@ -439,10 +439,10 @@ describe UploadsController do
user.block
end
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "group", mounted_as: "avatar", id: group.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
@@ -526,10 +526,10 @@ describe UploadsController do
end
context "when not signed in" do
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
@@ -549,10 +549,10 @@ describe UploadsController do
project.add_maintainer(user)
end
- it "redirects to the sign in page" do
+ it "responds with status 401" do
get :show, params: { model: "note", mounted_as: "attachment", id: note.id, filename: "dk.png" }
- expect(response).to redirect_to(new_user_session_path)
+ expect(response).to have_gitlab_http_status(401)
end
end
diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb
index f6eeb8d7065..a9a127da56f 100644
--- a/spec/features/projects/pipelines/pipelines_spec.rb
+++ b/spec/features/projects/pipelines/pipelines_spec.rb
@@ -819,10 +819,7 @@ describe 'Pipelines', :js do
context 'when project is private' do
let(:project) { create(:project, :private, :repository) }
- it 'redirects the user to sign_in and displays the flash alert' do
- expect(page).to have_content 'You need to sign in'
- expect(page.current_path).to eq("/users/sign_in")
- end
+ it { expect(page).to have_content 'You need to sign in' }
end
end
diff --git a/spec/features/projects/tags/user_views_tags_spec.rb b/spec/features/projects/tags/user_views_tags_spec.rb
index bc570f502bf..f344b682715 100644
--- a/spec/features/projects/tags/user_views_tags_spec.rb
+++ b/spec/features/projects/tags/user_views_tags_spec.rb
@@ -15,7 +15,7 @@ describe 'User views tags', :feature do
it do
visit project_tags_path(project, format: :atom)
- expect(page.current_path).to eq("/users/sign_in")
+ expect(page).to have_gitlab_http_status(401)
end
end
diff --git a/spec/frontend/repository/components/preview/__snapshots__/index_spec.js.snap b/spec/frontend/repository/components/preview/__snapshots__/index_spec.js.snap
new file mode 100644
index 00000000000..3d5ec3fd411
--- /dev/null
+++ b/spec/frontend/repository/components/preview/__snapshots__/index_spec.js.snap
@@ -0,0 +1,36 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Repository file preview component renders file HTML 1`] = `
+<article
+ class="file-holder js-hide-on-navigation limited-width-container readme-holder"
+>
+ <div
+ class="file-title"
+ >
+ <i
+ aria-hidden="true"
+ class="fa fa-file-text-o fa-fw"
+ />
+
+ <gllink-stub
+ href="http://test.com"
+ >
+ <strong>
+ README.md
+ </strong>
+ </gllink-stub>
+ </div>
+
+ <div
+ class="blob-viewer"
+ >
+ <div>
+ <div
+ class="blob"
+ >
+ test
+ </div>
+ </div>
+ </div>
+</article>
+`;
diff --git a/spec/frontend/repository/components/preview/index_spec.js b/spec/frontend/repository/components/preview/index_spec.js
new file mode 100644
index 00000000000..0112e6310f4
--- /dev/null
+++ b/spec/frontend/repository/components/preview/index_spec.js
@@ -0,0 +1,49 @@
+import { shallowMount } from '@vue/test-utils';
+import { GlLoadingIcon } from '@gitlab/ui';
+import Preview from '~/repository/components/preview/index.vue';
+
+let vm;
+let $apollo;
+
+function factory(blob) {
+ $apollo = {
+ query: jest.fn().mockReturnValue(Promise.resolve({})),
+ };
+
+ vm = shallowMount(Preview, {
+ propsData: {
+ blob,
+ },
+ mocks: {
+ $apollo,
+ },
+ });
+}
+
+describe('Repository file preview component', () => {
+ afterEach(() => {
+ vm.destroy();
+ });
+
+ it('renders file HTML', () => {
+ factory({
+ webUrl: 'http://test.com',
+ name: 'README.md',
+ });
+
+ vm.setData({ readme: { html: '<div class="blob">test</div>' } });
+
+ expect(vm.element).toMatchSnapshot();
+ });
+
+ it('renders loading icon', () => {
+ factory({
+ webUrl: 'http://test.com',
+ name: 'README.md',
+ });
+
+ vm.setData({ loading: 1 });
+
+ expect(vm.find(GlLoadingIcon).exists()).toBe(true);
+ });
+});
diff --git a/spec/frontend/repository/components/table/index_spec.js b/spec/frontend/repository/components/table/index_spec.js
index 0c5a7370fca..1e2f3501c8c 100644
--- a/spec/frontend/repository/components/table/index_spec.js
+++ b/spec/frontend/repository/components/table/index_spec.js
@@ -1,18 +1,34 @@
import { shallowMount } from '@vue/test-utils';
import { GlSkeletonLoading } from '@gitlab/ui';
import Table from '~/repository/components/table/index.vue';
+import TableRow from '~/repository/components/table/row.vue';
let vm;
let $apollo;
-function factory(path, data = () => ({})) {
- $apollo = {
- query: jest.fn().mockReturnValue(Promise.resolve({ data: data() })),
- };
-
+const MOCK_BLOBS = [
+ {
+ id: '123abc',
+ flatPath: 'blob',
+ name: 'blob.md',
+ type: 'blob',
+ webUrl: 'http://test.com',
+ },
+ {
+ id: '124abc',
+ flatPath: 'blob2',
+ name: 'blob2.md',
+ type: 'blob',
+ webUrl: 'http://test.com',
+ },
+];
+
+function factory({ path, isLoading = false, entries = {} }) {
vm = shallowMount(Table, {
propsData: {
path,
+ isLoading,
+ entries,
},
mocks: {
$apollo,
@@ -31,7 +47,7 @@ describe('Repository table component', () => {
${'app/assets'} | ${'master'}
${'/'} | ${'test'}
`('renders table caption for $ref in $path', ({ path, ref }) => {
- factory(path);
+ factory({ path });
vm.setData({ ref });
@@ -41,40 +57,20 @@ describe('Repository table component', () => {
});
it('shows loading icon', () => {
- factory('/');
-
- vm.setData({ isLoadingFiles: true });
+ factory({ path: '/', isLoading: true });
expect(vm.find(GlSkeletonLoading).exists()).toBe(true);
});
- describe('normalizeData', () => {
- it('normalizes edge nodes', () => {
- const output = vm.vm.normalizeData('blobs', [{ node: '1' }, { node: '2' }]);
-
- expect(output).toEqual(['1', '2']);
+ it('renders table rows', () => {
+ factory({
+ path: '/',
+ entries: {
+ blobs: MOCK_BLOBS,
+ },
});
- });
-
- describe('hasNextPage', () => {
- it('returns undefined when hasNextPage is false', () => {
- const output = vm.vm.hasNextPage({
- trees: { pageInfo: { hasNextPage: false } },
- submodules: { pageInfo: { hasNextPage: false } },
- blobs: { pageInfo: { hasNextPage: false } },
- });
- expect(output).toBe(undefined);
- });
-
- it('returns pageInfo object when hasNextPage is true', () => {
- const output = vm.vm.hasNextPage({
- trees: { pageInfo: { hasNextPage: false } },
- submodules: { pageInfo: { hasNextPage: false } },
- blobs: { pageInfo: { hasNextPage: true, nextCursor: 'test' } },
- });
-
- expect(output).toEqual({ hasNextPage: true, nextCursor: 'test' });
- });
+ expect(vm.find(TableRow).exists()).toBe(true);
+ expect(vm.findAll(TableRow).length).toBe(2);
});
});
diff --git a/spec/frontend/repository/components/tree_content_spec.js b/spec/frontend/repository/components/tree_content_spec.js
new file mode 100644
index 00000000000..954c4791c04
--- /dev/null
+++ b/spec/frontend/repository/components/tree_content_spec.js
@@ -0,0 +1,71 @@
+import { shallowMount } from '@vue/test-utils';
+import TreeContent from '~/repository/components/tree_content.vue';
+import FilePreview from '~/repository/components/preview/index.vue';
+
+let vm;
+let $apollo;
+
+function factory(path, data = () => ({})) {
+ $apollo = {
+ query: jest.fn().mockReturnValue(Promise.resolve({ data: data() })),
+ };
+
+ vm = shallowMount(TreeContent, {
+ propsData: {
+ path,
+ },
+ mocks: {
+ $apollo,
+ },
+ });
+}
+
+describe('Repository table component', () => {
+ afterEach(() => {
+ vm.destroy();
+ });
+
+ it('renders file preview', () => {
+ factory('/');
+
+ vm.setData({ entries: { blobs: [{ name: 'README.md ' }] } });
+
+ expect(vm.find(FilePreview).exists()).toBe(true);
+ });
+
+ describe('normalizeData', () => {
+ it('normalizes edge nodes', () => {
+ factory('/');
+
+ const output = vm.vm.normalizeData('blobs', [{ node: '1' }, { node: '2' }]);
+
+ expect(output).toEqual(['1', '2']);
+ });
+ });
+
+ describe('hasNextPage', () => {
+ it('returns undefined when hasNextPage is false', () => {
+ factory('/');
+
+ const output = vm.vm.hasNextPage({
+ trees: { pageInfo: { hasNextPage: false } },
+ submodules: { pageInfo: { hasNextPage: false } },
+ blobs: { pageInfo: { hasNextPage: false } },
+ });
+
+ expect(output).toBe(undefined);
+ });
+
+ it('returns pageInfo object when hasNextPage is true', () => {
+ factory('/');
+
+ const output = vm.vm.hasNextPage({
+ trees: { pageInfo: { hasNextPage: false } },
+ submodules: { pageInfo: { hasNextPage: false } },
+ blobs: { pageInfo: { hasNextPage: true, nextCursor: 'test' } },
+ });
+
+ expect(output).toEqual({ hasNextPage: true, nextCursor: 'test' });
+ });
+ });
+});
diff --git a/spec/lib/constraints/project_url_constrainer_spec.rb b/spec/lib/constraints/project_url_constrainer_spec.rb
index ac3221ecab7..27d70d562c1 100644
--- a/spec/lib/constraints/project_url_constrainer_spec.rb
+++ b/spec/lib/constraints/project_url_constrainer_spec.rb
@@ -14,42 +14,15 @@ describe Constraints::ProjectUrlConstrainer do
end
context 'invalid request' do
- context "non-existing project" do
- let(:request) { build_request('foo', 'bar') }
-
- it { expect(subject.matches?(request)).to be_falsey }
-
- context 'existence_check is false' do
- it { expect(subject.matches?(request, existence_check: false)).to be_truthy }
- end
- end
-
context "project id ending with .git" do
let(:request) { build_request(namespace.full_path, project.path + '.git') }
it { expect(subject.matches?(request)).to be_falsey }
end
end
-
- context 'when the request matches a redirect route' do
- let(:old_project_path) { 'old_project_path' }
- let!(:redirect_route) { project.redirect_routes.create!(path: "#{namespace.full_path}/#{old_project_path}") }
-
- context 'and is a GET request' do
- let(:request) { build_request(namespace.full_path, old_project_path) }
- it { expect(subject.matches?(request)).to be_truthy }
- end
-
- context 'and is NOT a GET request' do
- let(:request) { build_request(namespace.full_path, old_project_path, 'POST') }
- it { expect(subject.matches?(request)).to be_falsey }
- end
- end
end
- def build_request(namespace, project, method = 'GET')
- double(:request,
- 'get?': (method == 'GET'),
- params: { namespace_id: namespace, id: project })
+ def build_request(namespace, project)
+ double(:request, params: { namespace_id: namespace, id: project })
end
end
diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb
index 7f7a285c453..b0d07c6e0b0 100644
--- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb
+++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb
@@ -158,6 +158,7 @@ describe Gitlab::BitbucketImport::Importer do
expect { subject.execute }.to change { MergeRequest.count }.by(1)
merge_request = MergeRequest.first
+ expect(merge_request.state).to eq('merged')
expect(merge_request.notes.count).to eq(2)
expect(merge_request.notes.map(&:discussion_id).uniq.count).to eq(1)
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index e8116f0a301..f7bef9e71e2 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -111,6 +111,34 @@ describe Issuable do
end
end
+ describe '.initialize' do
+ it 'maps the state to the right state_id' do
+ described_class::STATE_ID_MAP.each do |key, value|
+ issuable = MergeRequest.new(state: key)
+
+ expect(issuable.state).to eq(key)
+ expect(issuable.state_id).to eq(value)
+ end
+ end
+
+ it 'maps a string version of the state to the right state_id' do
+ described_class::STATE_ID_MAP.each do |key, value|
+ issuable = MergeRequest.new('state' => key)
+
+ expect(issuable.state).to eq(key)
+ expect(issuable.state_id).to eq(value)
+ end
+ end
+
+ it 'gives preference to state_id if present' do
+ issuable = MergeRequest.new('state' => 'opened',
+ 'state_id' => described_class::STATE_ID_MAP['merged'])
+
+ expect(issuable.state).to eq('merged')
+ expect(issuable.state_id).to eq(described_class::STATE_ID_MAP['merged'])
+ end
+ end
+
describe '#milestone_available?' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
diff --git a/spec/requests/projects/blob_controller_spec.rb b/spec/requests/projects/blob_controller_spec.rb
new file mode 100644
index 00000000000..b3321375ccc
--- /dev/null
+++ b/spec/requests/projects/blob_controller_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::BlobController do
+ let(:project) { create(:project, :private, :repository) }
+ let(:namespace) { project.namespace }
+
+ context 'anonymous user views blob in inaccessible project' do
+ context 'with default HTML format' do
+ before do
+ get namespace_project_blob_path(namespace_id: namespace, project_id: project, id: 'master/README.md')
+ end
+
+ context 'when project is private' do
+ it { expect(response).to have_gitlab_http_status(:redirect) }
+ end
+
+ context 'when project does not exist' do
+ let(:namespace) { 'non_existent_namespace' }
+ let(:project) { 'non_existent_project' }
+
+ it { expect(response).to have_gitlab_http_status(:redirect) }
+ end
+ end
+
+ context 'with JSON format' do
+ before do
+ get namespace_project_blob_path(namespace_id: namespace, project_id: project, id: 'master/README.md', format: :json)
+ end
+
+ context 'when project is private' do
+ it { expect(response).to have_gitlab_http_status(:unauthorized) }
+ end
+
+ context 'when project does not exist' do
+ let(:namespace) { 'non_existent_namespace' }
+ let(:project) { 'non_existent_project' }
+
+ it { expect(response).to have_gitlab_http_status(:unauthorized) }
+ end
+ end
+ end
+end
diff --git a/spec/requests/user_avatar_spec.rb b/spec/requests/user_avatar_spec.rb
new file mode 100644
index 00000000000..9451674161c
--- /dev/null
+++ b/spec/requests/user_avatar_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Loading a user avatar' do
+ let(:user) { create(:user, :with_avatar) }
+
+ context 'when logged in' do
+ # The exact query count will vary depending on the 2FA settings of the
+ # instance, group, and user. Removing those extra 2FA queries in this case
+ # may not be a good idea, so we just set up the ideal case.
+ before do
+ stub_application_setting(require_two_factor_authentication: true)
+
+ login_as(create(:user, :two_factor))
+ end
+
+ # One each for: current user, avatar user, and upload record
+ it 'only performs three SQL queries' do
+ get user.avatar_url # Skip queries on first application load
+
+ expect(response).to have_gitlab_http_status(200)
+ expect { get user.avatar_url }.not_to exceed_query_limit(3)
+ end
+ end
+
+ context 'when logged out' do
+ # One each for avatar user and upload record
+ it 'only performs two SQL queries' do
+ get user.avatar_url # Skip queries on first application load
+
+ expect(response).to have_gitlab_http_status(200)
+ expect { get user.avatar_url }.not_to exceed_query_limit(2)
+ end
+ end
+end
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index 561c2b572ec..61110790a43 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -776,10 +776,6 @@ describe 'project routing' do
it 'routes when :template_type is `issue`' do
expect(get(show_with_template_type('issue'))).to route_to('projects/templates#show', namespace_id: 'gitlab', project_id: 'gitlabhq', template_type: 'issue', key: 'template_name', format: 'json')
end
-
- it 'routes to application#route_not_found when :template_type is unknown' do
- expect(get(show_with_template_type('invalid'))).to route_to('application#route_not_found', unmatched_route: 'gitlab/gitlabhq/templates/invalid/template_name')
- end
end
end
diff --git a/spec/support/controllers/sessionless_auth_controller_shared_examples.rb b/spec/support/controllers/sessionless_auth_controller_shared_examples.rb
index bc95fcd6b88..b5149a0fcb1 100644
--- a/spec/support/controllers/sessionless_auth_controller_shared_examples.rb
+++ b/spec/support/controllers/sessionless_auth_controller_shared_examples.rb
@@ -34,15 +34,8 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
context 'when the personal access token has no api scope', unless: params[:public] do
it 'does not log the user in' do
- # Several instances of where these specs are shared route the request
- # through ApplicationController#route_not_found which does not involve
- # the usual auth code from Devise, so does not increment the
- # :user_unauthenticated_counter
- #
- unless params[:ignore_incrementing]
- expect(authentication_metrics)
- .to increment(:user_unauthenticated_counter)
- end
+ expect(authentication_metrics)
+ .to increment(:user_unauthenticated_counter)
personal_access_token.update(scopes: [:read_user])
@@ -91,15 +84,8 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
end
it "doesn't log the user in otherwise", unless: params[:public] do
- # Several instances of where these specs are shared route the request
- # through ApplicationController#route_not_found which does not involve
- # the usual auth code from Devise, so does not increment the
- # :user_unauthenticated_counter
- #
- unless params[:ignore_incrementing]
- expect(authentication_metrics)
- .to increment(:user_unauthenticated_counter)
- end
+ expect(authentication_metrics)
+ .to increment(:user_unauthenticated_counter)
get path, params: default_params.merge(private_token: 'token')
diff --git a/spec/support/shared_examples/controllers/todos_shared_examples.rb b/spec/support/shared_examples/controllers/todos_shared_examples.rb
index 914bf506320..f3f9abb7da2 100644
--- a/spec/support/shared_examples/controllers/todos_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/todos_shared_examples.rb
@@ -39,7 +39,7 @@ shared_examples 'todos actions' do
post_create
end.to change { user.todos.count }.by(0)
- expect(response).to have_gitlab_http_status(302)
+ expect(response).to have_gitlab_http_status(parent.is_a?(Group) ? 401 : 302)
end
end
end