diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/sessions_controller_spec.rb | 41 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/milestone_with_stats.json | 30 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/release.json | 2 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/release/release_for_guest.json | 2 | ||||
-rw-r--r-- | spec/frontend/diffs/components/diff_table_cell_spec.js | 4 | ||||
-rw-r--r-- | spec/lib/feature_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/middleware/multipart_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/snippet_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/releases_spec.rb | 17 | ||||
-rw-r--r-- | spec/spec_helper.rb | 6 | ||||
-rw-r--r-- | spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb | 42 |
11 files changed, 156 insertions, 46 deletions
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 2f597fd5cb3..a677e17ab0c 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -495,4 +495,45 @@ describe SessionsController do expect(session[:failed_login_attempts]).to eq(1) end end + + describe '#set_current_context' do + before do + set_devise_mapping(context: @request) + end + + context 'when signed in' do + let_it_be(:user) { create(:user) } + + before do + sign_in(user) + end + + it 'sets the username and caller_id in the context' do + expect(controller).to receive(:destroy).and_wrap_original do |m, *args| + expect(Labkit::Context.current.to_h) + .to include('meta.user' => user.username, + 'meta.caller_id' => 'SessionsController#destroy') + + m.call(*args) + end + + delete :destroy + end + end + + context 'when not signed in' do + it 'sets the caller_id in the context' do + expect(controller).to receive(:new).and_wrap_original do |m, *args| + expect(Labkit::Context.current.to_h) + .to include('meta.caller_id' => 'SessionsController#new') + expect(Labkit::Context.current.to_h) + .not_to include('meta.user') + + m.call(*args) + end + + get :new + end + end + end end diff --git a/spec/fixtures/api/schemas/public_api/v4/milestone_with_stats.json b/spec/fixtures/api/schemas/public_api/v4/milestone_with_stats.json new file mode 100644 index 00000000000..e2475545ee9 --- /dev/null +++ b/spec/fixtures/api/schemas/public_api/v4/milestone_with_stats.json @@ -0,0 +1,30 @@ +{ + "type": "object", + "properties" : { + "id": { "type": "integer" }, + "iid": { "type": "integer" }, + "project_id": { "type": ["integer", "null"] }, + "group_id": { "type": ["integer", "null"] }, + "title": { "type": "string" }, + "description": { "type": ["string", "null"] }, + "state": { "type": "string" }, + "created_at": { "type": "date" }, + "updated_at": { "type": "date" }, + "start_date": { "type": "date" }, + "due_date": { "type": "date" }, + "web_url": { "type": "string" }, + "issue_stats": { + "required": ["total", "closed"], + "properties": { + "total": { "type": "integer" }, + "closed": { "type": "integer" } + }, + "additionalProperties": false + } + }, + "required": [ + "id", "iid", "title", "description", "state", + "state", "created_at", "updated_at", "start_date", "due_date", "issue_stats" + ], + "additionalProperties": false +} diff --git a/spec/fixtures/api/schemas/public_api/v4/release.json b/spec/fixtures/api/schemas/public_api/v4/release.json index 46703c69dc0..a239be09919 100644 --- a/spec/fixtures/api/schemas/public_api/v4/release.json +++ b/spec/fixtures/api/schemas/public_api/v4/release.json @@ -17,7 +17,7 @@ }, "milestones": { "type": "array", - "items": { "$ref": "milestone.json" } + "items": { "$ref": "milestone_with_stats.json" } }, "commit_path": { "type": "string" }, "tag_path": { "type": "string" }, diff --git a/spec/fixtures/api/schemas/public_api/v4/release/release_for_guest.json b/spec/fixtures/api/schemas/public_api/v4/release/release_for_guest.json index bce74892059..1a1e92ac778 100644 --- a/spec/fixtures/api/schemas/public_api/v4/release/release_for_guest.json +++ b/spec/fixtures/api/schemas/public_api/v4/release/release_for_guest.json @@ -10,7 +10,7 @@ "upcoming_release": { "type": "boolean" }, "milestones": { "type": "array", - "items": { "$ref": "../milestone.json" } + "items": { "$ref": "../milestone_with_stats.json" } }, "commit_path": { "type": "string" }, "tag_path": { "type": "string" }, diff --git a/spec/frontend/diffs/components/diff_table_cell_spec.js b/spec/frontend/diffs/components/diff_table_cell_spec.js index ad70b5695cc..1af0746f3bd 100644 --- a/spec/frontend/diffs/components/diff_table_cell_spec.js +++ b/spec/frontend/diffs/components/diff_table_cell_spec.js @@ -155,10 +155,6 @@ describe('DiffTableCell', () => { }); }); - it('renders the correct line number', () => { - expect(findLineNumber().text()).toEqual(TEST_LINE_NUMBER.toString()); - }); - it('on click, dispatches setHighlightedRow', () => { expect(store.dispatch).not.toHaveBeenCalled(); diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 2525dd17b89..cbe617359ef 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -146,7 +146,15 @@ describe Feature do expect(described_class.enabled?(:enabled_feature_flag)).to be_truthy end - it { expect(described_class.l1_cache_backend).to eq(Gitlab::ThreadMemoryCache.cache_backend) } + context 'with USE_THREAD_MEMORY_CACHE defined' do + before do + stub_env('USE_THREAD_MEMORY_CACHE', '1') + end + + it { expect(described_class.l1_cache_backend).to eq(Gitlab::ThreadMemoryCache.cache_backend) } + end + + it { expect(described_class.l1_cache_backend).to eq(Gitlab::ProcessMemoryCache.cache_backend) } it { expect(described_class.l2_cache_backend).to eq(Rails.cache) } it 'caches the status in L1 and L2 caches', diff --git a/spec/lib/gitlab/middleware/multipart_spec.rb b/spec/lib/gitlab/middleware/multipart_spec.rb index 33797817578..1d3ad3afb56 100644 --- a/spec/lib/gitlab/middleware/multipart_spec.rb +++ b/spec/lib/gitlab/middleware/multipart_spec.rb @@ -5,9 +5,7 @@ require 'spec_helper' require 'tempfile' describe Gitlab::Middleware::Multipart do - let(:app) { double(:app) } - let(:middleware) { described_class.new(app) } - let(:original_filename) { 'filename' } + include_context 'multipart middleware context' shared_examples_for 'multipart upload files' do it 'opens top-level files' do @@ -82,22 +80,12 @@ describe Gitlab::Middleware::Multipart do end it 'allows files in uploads/tmp directory' do - Dir.mktmpdir do |dir| - uploads_dir = File.join(dir, 'public/uploads/tmp') - FileUtils.mkdir_p(uploads_dir) - - allow(Rails).to receive(:root).and_return(dir) - allow(Dir).to receive(:tmpdir).and_return(File.join(Dir.tmpdir, 'tmpsubdir')) - - Tempfile.open('top-level', uploads_dir) do |tempfile| - env = post_env({ 'file' => tempfile.path }, { 'file.name' => original_filename, 'file.path' => tempfile.path }, Gitlab::Workhorse.secret, 'gitlab-workhorse') - - expect(app).to receive(:call) do |env| - expect(get_params(env)['file']).to be_a(::UploadedFile) - end - - middleware.call(env) + with_tmp_dir('public/uploads/tmp') do |dir, env| + expect(app).to receive(:call) do |env| + expect(get_params(env)['file']).to be_a(::UploadedFile) end + + middleware.call(env) end end @@ -127,22 +115,4 @@ describe Gitlab::Middleware::Multipart do middleware.call(env) end end - - # Rails 5 doesn't combine the GET/POST parameters in - # ActionDispatch::HTTP::Parameters if action_dispatch.request.parameters is set: - # https://github.com/rails/rails/blob/aea6423f013ca48f7704c70deadf2cd6ac7d70a1/actionpack/lib/action_dispatch/http/parameters.rb#L41 - def get_params(env) - req = ActionDispatch::Request.new(env) - req.GET.merge(req.POST) - end - - def post_env(rewritten_fields, params, secret, issuer) - token = JWT.encode({ 'iss' => issuer, 'rewritten_fields' => rewritten_fields }, secret, 'HS256') - Rack::MockRequest.env_for( - '/', - method: 'post', - params: params, - described_class::RACK_ENV_KEY => token - ) - end end diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 95807f5f0c1..c9656b4d6ca 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -149,7 +149,7 @@ describe Snippet do end describe '.search' do - let(:snippet) { create(:snippet, title: 'test snippet') } + let(:snippet) { create(:snippet, title: 'test snippet', description: 'description') } it 'returns snippets with a matching title' do expect(described_class.search(snippet.title)).to eq([snippet]) @@ -174,6 +174,10 @@ describe Snippet do it 'returns snippets with a matching file name regardless of the casing' do expect(described_class.search(snippet.file_name.upcase)).to eq([snippet]) end + + it 'returns snippets with a matching description' do + expect(described_class.search(snippet.description)).to eq([snippet]) + end end describe '.search_code' do diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb index f9e7253a88b..5de8d5aa3ff 100644 --- a/spec/requests/api/releases_spec.rb +++ b/spec/requests/api/releases_spec.rb @@ -359,12 +359,29 @@ describe API::Releases do let(:milestone) { create(:milestone, project: project) } + it 'matches schema' do + get api("/projects/#{project.id}/releases/v0.1", non_project_member) + + expect(response).to match_response_schema('public_api/v4/release') + end + it 'exposes milestones' do get api("/projects/#{project.id}/releases/v0.1", non_project_member) expect(json_response['milestones'].first['title']).to eq(milestone.title) end + it 'returns issue stats for milestone' do + create_list(:issue, 2, milestone: milestone, project: project) + create_list(:issue, 3, :closed, milestone: milestone, project: project) + + get api("/projects/#{project.id}/releases/v0.1", non_project_member) + + issue_stats = json_response['milestones'].first["issue_stats"] + expect(issue_stats["total"]).to eq(5) + expect(issue_stats["closed"]).to eq(3) + end + context 'when project restricts visibility of issues and merge requests' do let!(:project) { create(:project, :repository, :public, :issues_private, :merge_requests_private) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b862fc4bbd9..d379fd494fa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -193,8 +193,10 @@ RSpec.configure do |config| # expect(Gitlab::Git::KeepAround).to receive(:execute).and_call_original allow(Gitlab::Git::KeepAround).to receive(:execute) - # Clear thread cache and Sidekiq queues - Gitlab::ThreadMemoryCache.cache_backend.clear + [Gitlab::ThreadMemoryCache, Gitlab::ProcessMemoryCache].each do |cache| + cache.cache_backend.clear + end + Sidekiq::Worker.clear_all # Temporary patch to force admin mode to be active by default in tests when diff --git a/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb b/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb new file mode 100644 index 00000000000..f1554ea8e9f --- /dev/null +++ b/spec/support/shared_contexts/lib/gitlab/middleware/multipart_shared_contexts.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +RSpec.shared_context 'multipart middleware context' do + let(:app) { double(:app) } + let(:middleware) { described_class.new(app) } + let(:original_filename) { 'filename' } + + # Rails 5 doesn't combine the GET/POST parameters in + # ActionDispatch::HTTP::Parameters if action_dispatch.request.parameters is set: + # https://github.com/rails/rails/blob/aea6423f013ca48f7704c70deadf2cd6ac7d70a1/actionpack/lib/action_dispatch/http/parameters.rb#L41 + def get_params(env) + req = ActionDispatch::Request.new(env) + req.GET.merge(req.POST) + end + + def post_env(rewritten_fields, params, secret, issuer) + token = JWT.encode({ 'iss' => issuer, 'rewritten_fields' => rewritten_fields }, secret, 'HS256') + Rack::MockRequest.env_for( + '/', + method: 'post', + params: params, + described_class::RACK_ENV_KEY => token + ) + end + + def with_tmp_dir(uploads_sub_dir, storage_path = '') + Dir.mktmpdir do |dir| + upload_dir = File.join(dir, storage_path, uploads_sub_dir) + FileUtils.mkdir_p(upload_dir) + + allow(Rails).to receive(:root).and_return(dir) + allow(Dir).to receive(:tmpdir).and_return(File.join(Dir.tmpdir, 'tmpsubdir')) + allow(GitlabUploader).to receive(:root).and_return(File.join(dir, storage_path)) + + Tempfile.open('top-level', upload_dir) do |tempfile| + env = post_env({ 'file' => tempfile.path }, { 'file.name' => original_filename, 'file.path' => tempfile.path }, Gitlab::Workhorse.secret, 'gitlab-workhorse') + + yield dir, env + end + end + end +end |