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:
authorValery Sizov <valery@gitlab.com>2017-05-05 16:59:31 +0300
committerValery Sizov <valery@gitlab.com>2017-05-05 16:59:31 +0300
commit5004579b15b0585c0a26231d7422fb1d8086bd66 (patch)
treeb9d0096b88813af0d2cb38c173485f56aa62ebc7 /spec
parent79b8323d11cc06911b996f327c6e06fd29cafea4 (diff)
parent10c1bf2d77fd0ab21309d0b136cbc0ac11f56c77 (diff)
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into mia_backort[ci skip]
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/artifacts_controller_spec.rb188
-rw-r--r--spec/controllers/projects/deploy_keys_controller_spec.rb66
-rw-r--r--spec/controllers/projects/pages_controller_spec.rb57
-rw-r--r--spec/controllers/projects/pages_domains_controller_spec.rb58
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb36
-rw-r--r--spec/controllers/uploads_controller_spec.rb87
-rw-r--r--spec/features/cycle_analytics_spec.rb19
-rw-r--r--spec/features/merge_requests/user_posts_notes_spec.rb1
-rw-r--r--spec/features/merge_requests/user_uses_slash_commands_spec.rb1
-rw-r--r--spec/features/projects/artifacts/file_spec.rb59
-rw-r--r--spec/features/projects/branches/new_branch_ref_dropdown_spec.rb48
-rw-r--r--spec/features/projects/deploy_keys_spec.rb12
-rw-r--r--spec/javascripts/boards/issue_card_spec.js21
-rw-r--r--spec/javascripts/cycle_analytics/limit_warning_component_spec.js3
-rw-r--r--spec/javascripts/deploy_keys/components/action_btn_spec.js70
-rw-r--r--spec/javascripts/deploy_keys/components/app_spec.js142
-rw-r--r--spec/javascripts/deploy_keys/components/key_spec.js92
-rw-r--r--spec/javascripts/deploy_keys/components/keys_panel_spec.js70
-rw-r--r--spec/javascripts/environments/environment_actions_spec.js12
-rw-r--r--spec/javascripts/environments/environment_rollback_spec.js24
-rw-r--r--spec/javascripts/environments/environment_stop_spec.js10
-rw-r--r--spec/javascripts/fixtures/deploy_keys.rb36
-rw-r--r--spec/javascripts/fixtures/mini_dropdown_graph.html.haml6
-rw-r--r--spec/javascripts/lib/utils/common_utils_spec.js11
-rw-r--r--spec/javascripts/notes_spec.js229
-rw-r--r--spec/javascripts/pipelines/stage_spec.js121
-rw-r--r--spec/javascripts/vue_shared/translate_spec.js90
-rw-r--r--spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb11
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb2
-rw-r--r--spec/lib/gitlab/health_checks/fs_shards_check_spec.rb12
-rw-r--r--spec/lib/gitlab/health_checks/simple_check_shared.rb6
-rw-r--r--spec/lib/gitlab/i18n_spec.rb27
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml1
-rw-r--r--spec/lib/gitlab/prometheus_spec.rb30
-rw-r--r--spec/lib/gitlab/shell_spec.rb41
-rw-r--r--spec/lib/gitlab/slash_commands/command_definition_spec.rb52
-rw-r--r--spec/lib/gitlab/slash_commands/dsl_spec.rb66
-rw-r--r--spec/models/ci/artifact_blob_spec.rb44
-rw-r--r--spec/models/event_spec.rb42
-rw-r--r--spec/models/network/graph_spec.rb21
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb2
-rw-r--r--spec/models/project_spec.rb8
-rw-r--r--spec/models/project_wiki_spec.rb21
-rw-r--r--spec/models/user_spec.rb8
-rw-r--r--spec/policies/personal_snippet_policy_spec.rb141
-rw-r--r--spec/requests/projects/artifacts_controller_spec.rb117
-rw-r--r--spec/serializers/deploy_key_entity_spec.rb38
-rw-r--r--spec/services/preview_markdown_service_spec.rb67
-rw-r--r--spec/services/slash_commands/interpret_service_spec.rb207
-rw-r--r--spec/services/upload_service_spec.rb (renamed from spec/services/projects/upload_service_spec.rb)4
-rw-r--r--spec/support/features/issuable_slash_commands_shared_examples.rb16
-rw-r--r--spec/support/prometheus_helpers.rb4
-rw-r--r--spec/support/time_tracking_shared_examples.rb13
-rw-r--r--spec/tasks/gitlab/shell_rake_spec.rb4
-rw-r--r--spec/uploaders/personal_file_uploader_spec.rb31
-rw-r--r--spec/views/projects/tags/index.html.haml_spec.rb20
56 files changed, 2334 insertions, 291 deletions
diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb
new file mode 100644
index 00000000000..eff9fab8da2
--- /dev/null
+++ b/spec/controllers/projects/artifacts_controller_spec.rb
@@ -0,0 +1,188 @@
+require 'spec_helper'
+
+describe Projects::ArtifactsController do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, :repository) }
+
+ let(:pipeline) do
+ create(:ci_pipeline,
+ project: project,
+ sha: project.commit.sha,
+ ref: project.default_branch,
+ status: 'success')
+ end
+
+ let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
+
+ before do
+ project.team << [user, :developer]
+
+ sign_in(user)
+ end
+
+ describe 'GET download' do
+ it 'sends the artifacts file' do
+ expect(controller).to receive(:send_file).with(build.artifacts_file.path, disposition: 'attachment').and_call_original
+
+ get :download, namespace_id: project.namespace, project_id: project, build_id: build
+ end
+ end
+
+ describe 'GET browse' do
+ context 'when the directory exists' do
+ it 'renders the browse view' do
+ get :browse, namespace_id: project.namespace, project_id: project, build_id: build, path: 'other_artifacts_0.1.2'
+
+ expect(response).to render_template('projects/artifacts/browse')
+ end
+ end
+
+ context 'when the directory does not exist' do
+ it 'responds Not Found' do
+ get :browse, namespace_id: project.namespace, project_id: project, build_id: build, path: 'unknown'
+
+ expect(response).to be_not_found
+ end
+ end
+ end
+
+ describe 'GET file' do
+ context 'when the file exists' do
+ it 'renders the file view' do
+ get :file, namespace_id: project.namespace, project_id: project, build_id: build, path: 'ci_artifacts.txt'
+
+ expect(response).to render_template('projects/artifacts/file')
+ end
+ end
+
+ context 'when the file does not exist' do
+ it 'responds Not Found' do
+ get :file, namespace_id: project.namespace, project_id: project, build_id: build, path: 'unknown'
+
+ expect(response).to be_not_found
+ end
+ end
+ end
+
+ describe 'GET raw' do
+ context 'when the file exists' do
+ it 'serves the file using workhorse' do
+ get :raw, namespace_id: project.namespace, project_id: project, build_id: build, path: 'ci_artifacts.txt'
+
+ send_data = response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]
+
+ expect(send_data).to start_with('artifacts-entry:')
+
+ base64_params = send_data.sub(/\Aartifacts\-entry:/, '')
+ params = JSON.parse(Base64.urlsafe_decode64(base64_params))
+
+ expect(params.keys).to eq(%w(Archive Entry))
+ expect(params['Archive']).to end_with('build_artifacts.zip')
+ expect(params['Entry']).to eq(Base64.encode64('ci_artifacts.txt'))
+ end
+ end
+
+ context 'when the file does not exist' do
+ it 'responds Not Found' do
+ get :raw, namespace_id: project.namespace, project_id: project, build_id: build, path: 'unknown'
+
+ expect(response).to be_not_found
+ end
+ end
+ end
+
+ describe 'GET latest_succeeded' do
+ def params_from_ref(ref = pipeline.ref, job = build.name, path = 'browse')
+ {
+ namespace_id: project.namespace,
+ project_id: project,
+ ref_name_and_path: File.join(ref, path),
+ job: job
+ }
+ end
+
+ context 'cannot find the build' do
+ shared_examples 'not found' do
+ it { expect(response).to have_http_status(:not_found) }
+ end
+
+ context 'has no such ref' do
+ before do
+ get :latest_succeeded, params_from_ref('TAIL', build.name)
+ end
+
+ it_behaves_like 'not found'
+ end
+
+ context 'has no such build' do
+ before do
+ get :latest_succeeded, params_from_ref(pipeline.ref, 'NOBUILD')
+ end
+
+ it_behaves_like 'not found'
+ end
+
+ context 'has no path' do
+ before do
+ get :latest_succeeded, params_from_ref(pipeline.sha, build.name, '')
+ end
+
+ it_behaves_like 'not found'
+ end
+ end
+
+ context 'found the build and redirect' do
+ shared_examples 'redirect to the build' do
+ it 'redirects' do
+ path = browse_namespace_project_build_artifacts_path(
+ project.namespace,
+ project,
+ build)
+
+ expect(response).to redirect_to(path)
+ end
+ end
+
+ context 'with regular branch' do
+ before do
+ pipeline.update(ref: 'master',
+ sha: project.commit('master').sha)
+
+ get :latest_succeeded, params_from_ref('master')
+ end
+
+ it_behaves_like 'redirect to the build'
+ end
+
+ context 'with branch name containing slash' do
+ before do
+ pipeline.update(ref: 'improve/awesome',
+ sha: project.commit('improve/awesome').sha)
+
+ get :latest_succeeded, params_from_ref('improve/awesome')
+ end
+
+ it_behaves_like 'redirect to the build'
+ end
+
+ context 'with branch name and path containing slashes' do
+ before do
+ pipeline.update(ref: 'improve/awesome',
+ sha: project.commit('improve/awesome').sha)
+
+ get :latest_succeeded, params_from_ref('improve/awesome', build.name, 'file/README.md')
+ end
+
+ it 'redirects' do
+ path = file_namespace_project_build_artifacts_path(
+ project.namespace,
+ project,
+ build,
+ 'README.md')
+
+ expect(response).to redirect_to(path)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb
new file mode 100644
index 00000000000..efe1a78415b
--- /dev/null
+++ b/spec/controllers/projects/deploy_keys_controller_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+
+describe Projects::DeployKeysController do
+ let(:project) { create(:project, :repository) }
+ let(:user) { create(:user) }
+
+ before do
+ project.team << [user, :master]
+
+ sign_in(user)
+ end
+
+ describe 'GET index' do
+ let(:params) do
+ { namespace_id: project.namespace, project_id: project }
+ end
+
+ context 'when html requested' do
+ it 'redirects to blob' do
+ get :index, params
+
+ expect(response).to redirect_to(namespace_project_settings_repository_path(params))
+ end
+ end
+
+ context 'when json requested' do
+ let(:project2) { create(:empty_project, :internal)}
+ let(:project_private) { create(:empty_project, :private)}
+
+ let(:deploy_key_internal) do
+ create(:deploy_key, key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCdMHEHyhRjbhEZVddFn6lTWdgEy5Q6Bz4nwGB76xWZI5YT/1WJOMEW+sL5zYd31kk7sd3FJ5L9ft8zWMWrr/iWXQikC2cqZK24H1xy+ZUmrRuJD4qGAaIVoyyzBL+avL+lF8J5lg6YSw8gwJY/lX64/vnJHUlWw2n5BF8IFOWhiw== dummy@gitlab.com')
+ end
+ let(:deploy_key_actual) do
+ create(:deploy_key, key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDNd/UJWhPrpb+b/G5oL109y57yKuCxE+WUGJGYaj7WQKsYRJmLYh1mgjrl+KVyfsWpq4ylOxIfFSnN9xBBFN8mlb0Fma5DC7YsSsibJr3MZ19ZNBprwNcdogET7aW9I0In7Wu5f2KqI6e5W/spJHCy4JVxzVMUvk6Myab0LnJ2iQ== dummy@gitlab.com')
+ end
+ let!(:deploy_key_public) { create(:deploy_key, public: true) }
+
+ let!(:deploy_keys_project_internal) do
+ create(:deploy_keys_project, project: project2, deploy_key: deploy_key_internal)
+ end
+
+ let!(:deploy_keys_actual_project) do
+ create(:deploy_keys_project, project: project, deploy_key: deploy_key_actual)
+ end
+
+ let!(:deploy_keys_project_private) do
+ create(:deploy_keys_project, project: project_private, deploy_key: create(:another_deploy_key))
+ end
+
+ before do
+ project2.team << [user, :developer]
+ end
+
+ it 'returns json in a correct format' do
+ get :index, params.merge(format: :json)
+
+ json = JSON.parse(response.body)
+
+ expect(json.keys).to match_array(%w(enabled_keys available_project_keys public_keys))
+ expect(json['enabled_keys'].count).to eq(1)
+ expect(json['available_project_keys'].count).to eq(1)
+ expect(json['public_keys'].count).to eq(1)
+ end
+ end
+ end
+end
diff --git a/spec/controllers/projects/pages_controller_spec.rb b/spec/controllers/projects/pages_controller_spec.rb
new file mode 100644
index 00000000000..df35d8e86b9
--- /dev/null
+++ b/spec/controllers/projects/pages_controller_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe Projects::PagesController do
+ let(:user) { create(:user) }
+ let(:project) { create(:empty_project, :public, :access_requestable) }
+
+ let(:request_params) do
+ {
+ namespace_id: project.namespace,
+ project_id: project
+ }
+ end
+
+ before do
+ allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
+ sign_in(user)
+ project.add_master(user)
+ end
+
+ describe 'GET show' do
+ it 'returns 200 status' do
+ get :show, request_params
+
+ expect(response).to have_http_status(200)
+ end
+ end
+
+ describe 'DELETE destroy' do
+ it 'returns 302 status' do
+ delete :destroy, request_params
+
+ expect(response).to have_http_status(302)
+ end
+ end
+
+ context 'pages disabled' do
+ before do
+ allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
+ end
+
+ describe 'GET show' do
+ it 'returns 404 status' do
+ get :show, request_params
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ describe 'DELETE destroy' do
+ it 'returns 404 status' do
+ delete :destroy, request_params
+
+ expect(response).to have_http_status(404)
+ end
+ end
+ end
+end
diff --git a/spec/controllers/projects/pages_domains_controller_spec.rb b/spec/controllers/projects/pages_domains_controller_spec.rb
index 2362df895a8..33853c4b9d0 100644
--- a/spec/controllers/projects/pages_domains_controller_spec.rb
+++ b/spec/controllers/projects/pages_domains_controller_spec.rb
@@ -1,8 +1,9 @@
require 'spec_helper'
describe Projects::PagesDomainsController do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:project) { create(:empty_project) }
+ let!(:pages_domain) { create(:pages_domain, project: project) }
let(:request_params) do
{
@@ -11,14 +12,17 @@ describe Projects::PagesDomainsController do
}
end
+ let(:pages_domain_params) do
+ build(:pages_domain, :with_certificate, :with_key, domain: 'my.otherdomain.com').slice(:key, :certificate, :domain)
+ end
+
before do
+ allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
sign_in(user)
- project.team << [user, :master]
+ project.add_master(user)
end
describe 'GET show' do
- let!(:pages_domain) { create(:pages_domain, project: project) }
-
it "displays the 'show' page" do
get(:show, request_params.merge(id: pages_domain.domain))
@@ -37,10 +41,6 @@ describe Projects::PagesDomainsController do
end
describe 'POST create' do
- let(:pages_domain_params) do
- build(:pages_domain, :with_certificate, :with_key).slice(:key, :certificate, :domain)
- end
-
it "creates a new pages domain" do
expect do
post(:create, request_params.merge(pages_domain: pages_domain_params))
@@ -51,8 +51,6 @@ describe Projects::PagesDomainsController do
end
describe 'DELETE destroy' do
- let!(:pages_domain) { create(:pages_domain, project: project) }
-
it "deletes the pages domain" do
expect do
delete(:destroy, request_params.merge(id: pages_domain.domain))
@@ -61,4 +59,42 @@ describe Projects::PagesDomainsController do
expect(response).to redirect_to(namespace_project_pages_path(project.namespace, project))
end
end
+
+ context 'pages disabled' do
+ before do
+ allow(Gitlab.config.pages).to receive(:enabled).and_return(false)
+ end
+
+ describe 'GET show' do
+ it 'returns 404 status' do
+ get(:show, request_params.merge(id: pages_domain.domain))
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ describe 'GET new' do
+ it 'returns 404 status' do
+ get :new, request_params
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ describe 'POST create' do
+ it "returns 404 status" do
+ post(:create, request_params.merge(pages_domain: pages_domain_params))
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ describe 'DELETE destroy' do
+ it "deletes the pages domain" do
+ delete(:destroy, request_params.merge(id: pages_domain.domain))
+
+ expect(response).to have_http_status(404)
+ end
+ end
+ end
end
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index b9bacc5a64a..1b47d163c0b 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -5,6 +5,8 @@ describe Projects::PipelinesController do
let(:project) { create(:empty_project, :public) }
before do
+ project.add_developer(user)
+
sign_in(user)
end
@@ -87,4 +89,38 @@ describe Projects::PipelinesController do
expect(json_response['favicon']).to eq "/assets/ci_favicons/#{status.favicon}.ico"
end
end
+
+ describe 'POST retry.json' do
+ let!(:pipeline) { create(:ci_pipeline, :failed, project: project) }
+ let!(:build) { create(:ci_build, :failed, pipeline: pipeline) }
+
+ before do
+ post :retry, namespace_id: project.namespace,
+ project_id: project,
+ id: pipeline.id,
+ format: :json
+ end
+
+ it 'retries a pipeline without returning any content' do
+ expect(response).to have_http_status(:no_content)
+ expect(build.reload).to be_retried
+ end
+ end
+
+ describe 'POST cancel.json' do
+ let!(:pipeline) { create(:ci_pipeline, project: project) }
+ let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
+
+ before do
+ post :cancel, namespace_id: project.namespace,
+ project_id: project,
+ id: pipeline.id,
+ format: :json
+ end
+
+ it 'cancels a pipeline without returning any content' do
+ expect(response).to have_http_status(:no_content)
+ expect(pipeline.reload).to be_canceled
+ end
+ end
end
diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb
index f67d26da0ac..7dedfe160a6 100644
--- a/spec/controllers/uploads_controller_spec.rb
+++ b/spec/controllers/uploads_controller_spec.rb
@@ -8,6 +8,93 @@ end
describe UploadsController do
let!(:user) { create(:user, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) }
+ describe 'POST create' do
+ let(:model) { 'personal_snippet' }
+ let(:snippet) { create(:personal_snippet, :public) }
+ let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') }
+ let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') }
+
+ context 'when a user does not have permissions to upload a file' do
+ it "returns 401 when the user is not logged in" do
+ post :create, model: model, id: snippet.id, format: :json
+
+ expect(response).to have_http_status(401)
+ end
+
+ it "returns 404 when user can't comment on a snippet" do
+ private_snippet = create(:personal_snippet, :private)
+
+ sign_in(user)
+ post :create, model: model, id: private_snippet.id, format: :json
+
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ context 'when a user is logged in' do
+ before do
+ sign_in(user)
+ end
+
+ it "returns an error without file" do
+ post :create, model: model, id: snippet.id, format: :json
+
+ expect(response).to have_http_status(422)
+ end
+
+ it "returns an error with invalid model" do
+ expect { post :create, model: 'invalid', id: snippet.id, format: :json }
+ .to raise_error(ActionController::UrlGenerationError)
+ end
+
+ it "returns 404 status when object not found" do
+ post :create, model: model, id: 9999, format: :json
+
+ expect(response).to have_http_status(404)
+ end
+
+ context 'with valid image' do
+ before do
+ post :create, model: 'personal_snippet', id: snippet.id, file: jpg, format: :json
+ end
+
+ it 'returns a content with original filename, new link, and correct type.' do
+ expect(response.body).to match '\"alt\":\"rails_sample\"'
+ expect(response.body).to match "\"url\":\"/uploads"
+ end
+
+ it 'creates a corresponding Upload record' do
+ upload = Upload.last
+
+ aggregate_failures do
+ expect(upload).to exist
+ expect(upload.model).to eq snippet
+ end
+ end
+ end
+
+ context 'with valid non-image file' do
+ before do
+ post :create, model: 'personal_snippet', id: snippet.id, file: txt, format: :json
+ end
+
+ it 'returns a content with original filename, new link, and correct type.' do
+ expect(response.body).to match '\"alt\":\"doc_sample.txt\"'
+ expect(response.body).to match "\"url\":\"/uploads"
+ end
+
+ it 'creates a corresponding Upload record' do
+ upload = Upload.last
+
+ aggregate_failures do
+ expect(upload).to exist
+ expect(upload.model).to eq snippet
+ end
+ end
+ end
+ end
+ end
+
describe "GET show" do
context 'Content-Disposition security measures' do
let(:project) { create(:empty_project, :public) }
diff --git a/spec/features/cycle_analytics_spec.rb b/spec/features/cycle_analytics_spec.rb
index b93275c330b..7c9d522273b 100644
--- a/spec/features/cycle_analytics_spec.rb
+++ b/spec/features/cycle_analytics_spec.rb
@@ -62,6 +62,25 @@ feature 'Cycle Analytics', feature: true, js: true do
expect_issue_to_be_present
end
end
+
+ context "when my preferred language is Spanish" do
+ before do
+ user.update_attribute(:preferred_language, 'es')
+
+ project.team << [user, :master]
+ login_as(user)
+ visit namespace_project_cycle_analytics_path(project.namespace, project)
+ wait_for_ajax
+ end
+
+ it 'shows the content in Spanish' do
+ expect(page).to have_content('Estado del Pipeline')
+ end
+
+ it 'resets the language to English' do
+ expect(I18n.locale).to eq(:en)
+ end
+ end
end
context "as a guest" do
diff --git a/spec/features/merge_requests/user_posts_notes_spec.rb b/spec/features/merge_requests/user_posts_notes_spec.rb
index c7cc4d6bc72..7fc0e2ce6ec 100644
--- a/spec/features/merge_requests/user_posts_notes_spec.rb
+++ b/spec/features/merge_requests/user_posts_notes_spec.rb
@@ -98,6 +98,7 @@ describe 'Merge requests > User posts notes', :js do
find('.btn-save').click
end
+ wait_for_ajax
find('.note').hover
find('.js-note-edit').click
diff --git a/spec/features/merge_requests/user_uses_slash_commands_spec.rb b/spec/features/merge_requests/user_uses_slash_commands_spec.rb
index 1c0f21e5616..f0ad57eb92f 100644
--- a/spec/features/merge_requests/user_uses_slash_commands_spec.rb
+++ b/spec/features/merge_requests/user_uses_slash_commands_spec.rb
@@ -160,6 +160,7 @@ feature 'Merge Requests > User uses slash commands', feature: true, js: true do
it 'changes target branch from a note' do
write_note("message start \n/target_branch merge-test\n message end.")
+ wait_for_ajax
expect(page).not_to have_content('/target_branch')
expect(page).to have_content('message start')
expect(page).to have_content('message end.')
diff --git a/spec/features/projects/artifacts/file_spec.rb b/spec/features/projects/artifacts/file_spec.rb
new file mode 100644
index 00000000000..74308a7e8dd
--- /dev/null
+++ b/spec/features/projects/artifacts/file_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+feature 'Artifact file', :js, feature: true do
+ let(:project) { create(:project, :public) }
+ let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master') }
+ let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
+
+ def visit_file(path)
+ visit file_namespace_project_build_artifacts_path(project.namespace, project, build, path)
+ end
+
+ context 'Text file' do
+ before do
+ visit_file('other_artifacts_0.1.2/doc_sample.txt')
+
+ wait_for_ajax
+ end
+
+ it 'displays an error' do
+ aggregate_failures do
+ # shows an error message
+ expect(page).to have_content('The source could not be displayed because it is stored as a job artifact. You can download it instead.')
+
+ # does not show a viewer switcher
+ expect(page).not_to have_selector('.js-blob-viewer-switcher')
+
+ # does not show a copy button
+ expect(page).not_to have_selector('.js-copy-blob-source-btn')
+
+ # shows a download button
+ expect(page).to have_link('Download')
+ end
+ end
+ end
+
+ context 'JPG file' do
+ before do
+ visit_file('rails_sample.jpg')
+
+ wait_for_ajax
+ end
+
+ it 'displays the blob' do
+ aggregate_failures do
+ # shows rendered image
+ expect(page).to have_selector('.image_file img')
+
+ # does not show a viewer switcher
+ expect(page).not_to have_selector('.js-blob-viewer-switcher')
+
+ # does not show a copy button
+ expect(page).not_to have_selector('.js-copy-blob-source-btn')
+
+ # shows a download button
+ expect(page).to have_link('Download')
+ end
+ end
+ end
+end
diff --git a/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb b/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb
new file mode 100644
index 00000000000..cfc782c98ad
--- /dev/null
+++ b/spec/features/projects/branches/new_branch_ref_dropdown_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper'
+
+describe 'New Branch Ref Dropdown', :js, :feature do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, :public) }
+ let(:toggle) { find('.create-from .dropdown-toggle') }
+
+ before do
+ project.add_master(user)
+
+ login_as(user)
+ visit new_namespace_project_branch_path(project.namespace, project)
+ end
+
+ it 'filters a list of branches and tags' do
+ toggle.click
+
+ filter_by('v1.0.0')
+
+ expect(items_count).to be(1)
+
+ filter_by('video')
+
+ expect(items_count).to be(1)
+
+ find('.create-from .dropdown-content li').click
+
+ expect(toggle).to have_content 'video'
+ end
+
+ it 'accepts a manually entered commit SHA' do
+ toggle.click
+
+ filter_by('somecommitsha')
+
+ find('.create-from input[type=search]').send_keys(:enter)
+
+ expect(toggle).to have_content 'somecommitsha'
+ end
+
+ def items_count
+ all('.create-from .dropdown-content li').length
+ end
+
+ def filter_by(filter_text)
+ fill_in 'Filter by Git revision', with: filter_text
+ end
+end
diff --git a/spec/features/projects/deploy_keys_spec.rb b/spec/features/projects/deploy_keys_spec.rb
index 0b997f130ea..06abfbbc86b 100644
--- a/spec/features/projects/deploy_keys_spec.rb
+++ b/spec/features/projects/deploy_keys_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'Project deploy keys', feature: true do
+describe 'Project deploy keys', :js, :feature do
let(:user) { create(:user) }
let(:project) { create(:project_empty_repo) }
@@ -17,9 +17,13 @@ describe 'Project deploy keys', feature: true do
it 'removes association between project and deploy key' do
visit namespace_project_settings_repository_path(project.namespace, project)
- page.within '.deploy-keys' do
- expect { click_on 'Remove' }
- .to change { project.deploy_keys.count }.by(-1)
+ page.within(find('.deploy-keys')) do
+ expect(page).to have_selector('.deploy-keys li', count: 1)
+
+ click_on 'Remove'
+
+ expect(page).not_to have_selector('.fa-spinner', count: 0)
+ expect(page).to have_selector('.deploy-keys li', count: 0)
end
end
end
diff --git a/spec/javascripts/boards/issue_card_spec.js b/spec/javascripts/boards/issue_card_spec.js
index b1907ac3070..f872ca1040b 100644
--- a/spec/javascripts/boards/issue_card_spec.js
+++ b/spec/javascripts/boards/issue_card_spec.js
@@ -145,6 +145,27 @@ describe('Issue card component', () => {
).not.toBeNull();
});
});
+
+ describe('assignee default avatar', () => {
+ beforeEach((done) => {
+ component.issue.assignee = new ListUser({
+ id: 1,
+ name: 'testing 123',
+ username: 'test',
+ }, 'default_avatar');
+
+ Vue.nextTick(done);
+ });
+
+ it('displays defaults avatar if users avatar is null', () => {
+ expect(
+ component.$el.querySelector('.card-assignee img'),
+ ).not.toBeNull();
+ expect(
+ component.$el.querySelector('.card-assignee img').getAttribute('src'),
+ ).toBe('default_avatar');
+ });
+ });
});
describe('multiple assignees', () => {
diff --git a/spec/javascripts/cycle_analytics/limit_warning_component_spec.js b/spec/javascripts/cycle_analytics/limit_warning_component_spec.js
index 50000c5a5f5..2fb9eb0ca85 100644
--- a/spec/javascripts/cycle_analytics/limit_warning_component_spec.js
+++ b/spec/javascripts/cycle_analytics/limit_warning_component_spec.js
@@ -1,6 +1,9 @@
import Vue from 'vue';
+import Translate from '~/vue_shared/translate';
import limitWarningComp from '~/cycle_analytics/components/limit_warning_component';
+Vue.use(Translate);
+
describe('Limit warning component', () => {
let component;
let LimitWarningComponent;
diff --git a/spec/javascripts/deploy_keys/components/action_btn_spec.js b/spec/javascripts/deploy_keys/components/action_btn_spec.js
new file mode 100644
index 00000000000..5b93fbc5575
--- /dev/null
+++ b/spec/javascripts/deploy_keys/components/action_btn_spec.js
@@ -0,0 +1,70 @@
+import Vue from 'vue';
+import eventHub from '~/deploy_keys/eventhub';
+import actionBtn from '~/deploy_keys/components/action_btn.vue';
+
+describe('Deploy keys action btn', () => {
+ const data = getJSONFixture('deploy_keys/keys.json');
+ const deployKey = data.enabled_keys[0];
+ let vm;
+
+ beforeEach((done) => {
+ const ActionBtnComponent = Vue.extend(actionBtn);
+
+ vm = new ActionBtnComponent({
+ propsData: {
+ deployKey,
+ type: 'enable',
+ },
+ }).$mount();
+
+ setTimeout(done);
+ });
+
+ it('renders the type as uppercase', () => {
+ expect(
+ vm.$el.textContent.trim(),
+ ).toBe('Enable');
+ });
+
+ it('sends eventHub event with btn type', (done) => {
+ spyOn(eventHub, '$emit');
+
+ vm.$el.click();
+
+ setTimeout(() => {
+ expect(
+ eventHub.$emit,
+ ).toHaveBeenCalledWith('enable.key', deployKey);
+
+ done();
+ });
+ });
+
+ it('shows loading spinner after click', (done) => {
+ vm.$el.click();
+
+ setTimeout(() => {
+ expect(
+ vm.$el.querySelector('.fa'),
+ ).toBeDefined();
+
+ done();
+ });
+ });
+
+ it('disables button after click', (done) => {
+ vm.$el.click();
+
+ setTimeout(() => {
+ expect(
+ vm.$el.classList.contains('disabled'),
+ ).toBeTruthy();
+
+ expect(
+ vm.$el.getAttribute('disabled'),
+ ).toBe('disabled');
+
+ done();
+ });
+ });
+});
diff --git a/spec/javascripts/deploy_keys/components/app_spec.js b/spec/javascripts/deploy_keys/components/app_spec.js
new file mode 100644
index 00000000000..700897f50b0
--- /dev/null
+++ b/spec/javascripts/deploy_keys/components/app_spec.js
@@ -0,0 +1,142 @@
+import Vue from 'vue';
+import eventHub from '~/deploy_keys/eventhub';
+import deployKeysApp from '~/deploy_keys/components/app.vue';
+
+describe('Deploy keys app component', () => {
+ const data = getJSONFixture('deploy_keys/keys.json');
+ let vm;
+
+ const deployKeysResponse = (request, next) => {
+ next(request.respondWith(JSON.stringify(data), {
+ status: 200,
+ }));
+ };
+
+ beforeEach((done) => {
+ const Component = Vue.extend(deployKeysApp);
+
+ Vue.http.interceptors.push(deployKeysResponse);
+
+ vm = new Component({
+ propsData: {
+ endpoint: '/test',
+ },
+ }).$mount();
+
+ setTimeout(done);
+ });
+
+ afterEach(() => {
+ Vue.http.interceptors = _.without(Vue.http.interceptors, deployKeysResponse);
+ });
+
+ it('renders loading icon', (done) => {
+ vm.store.keys = {};
+ vm.isLoading = false;
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelectorAll('.deploy-keys-panel').length,
+ ).toBe(0);
+
+ expect(
+ vm.$el.querySelector('.fa-spinner'),
+ ).toBeDefined();
+
+ done();
+ });
+ });
+
+ it('renders keys panels', () => {
+ expect(
+ vm.$el.querySelectorAll('.deploy-keys-panel').length,
+ ).toBe(3);
+ });
+
+ it('does not render key panels when keys object is empty', (done) => {
+ vm.store.keys = {};
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelectorAll('.deploy-keys-panel').length,
+ ).toBe(0);
+
+ done();
+ });
+ });
+
+ it('does not render public panel when empty', (done) => {
+ vm.store.keys.public_keys = [];
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelectorAll('.deploy-keys-panel').length,
+ ).toBe(2);
+
+ done();
+ });
+ });
+
+ it('re-fetches deploy keys when enabling a key', (done) => {
+ const key = data.public_keys[0];
+
+ spyOn(vm.service, 'getKeys');
+ spyOn(vm.service, 'enableKey').and.callFake(() => new Promise((resolve) => {
+ resolve();
+
+ setTimeout(() => {
+ expect(vm.service.getKeys).toHaveBeenCalled();
+
+ done();
+ });
+ }));
+
+ eventHub.$emit('enable.key', key);
+
+ expect(vm.service.enableKey).toHaveBeenCalledWith(key.id);
+ });
+
+ it('re-fetches deploy keys when disabling a key', (done) => {
+ const key = data.public_keys[0];
+
+ spyOn(window, 'confirm').and.returnValue(true);
+ spyOn(vm.service, 'getKeys');
+ spyOn(vm.service, 'disableKey').and.callFake(() => new Promise((resolve) => {
+ resolve();
+
+ setTimeout(() => {
+ expect(vm.service.getKeys).toHaveBeenCalled();
+
+ done();
+ });
+ }));
+
+ eventHub.$emit('disable.key', key);
+
+ expect(vm.service.disableKey).toHaveBeenCalledWith(key.id);
+ });
+
+ it('calls disableKey when removing a key', (done) => {
+ const key = data.public_keys[0];
+
+ spyOn(window, 'confirm').and.returnValue(true);
+ spyOn(vm.service, 'getKeys');
+ spyOn(vm.service, 'disableKey').and.callFake(() => new Promise((resolve) => {
+ resolve();
+
+ setTimeout(() => {
+ expect(vm.service.getKeys).toHaveBeenCalled();
+
+ done();
+ });
+ }));
+
+ eventHub.$emit('remove.key', key);
+
+ expect(vm.service.disableKey).toHaveBeenCalledWith(key.id);
+ });
+
+ it('hasKeys returns true when there are keys', () => {
+ expect(vm.hasKeys).toEqual(3);
+ });
+});
diff --git a/spec/javascripts/deploy_keys/components/key_spec.js b/spec/javascripts/deploy_keys/components/key_spec.js
new file mode 100644
index 00000000000..793ab8c451d
--- /dev/null
+++ b/spec/javascripts/deploy_keys/components/key_spec.js
@@ -0,0 +1,92 @@
+import Vue from 'vue';
+import DeployKeysStore from '~/deploy_keys/store';
+import key from '~/deploy_keys/components/key.vue';
+
+describe('Deploy keys key', () => {
+ let vm;
+ const KeyComponent = Vue.extend(key);
+ const data = getJSONFixture('deploy_keys/keys.json');
+ const createComponent = (deployKey) => {
+ const store = new DeployKeysStore();
+ store.keys = data;
+
+ vm = new KeyComponent({
+ propsData: {
+ deployKey,
+ store,
+ },
+ }).$mount();
+ };
+
+ describe('enabled key', () => {
+ const deployKey = data.enabled_keys[0];
+
+ beforeEach((done) => {
+ createComponent(deployKey);
+
+ setTimeout(done);
+ });
+
+ it('renders the keys title', () => {
+ expect(
+ vm.$el.querySelector('.title').textContent.trim(),
+ ).toContain('My title');
+ });
+
+ it('renders human friendly formatted created date', () => {
+ expect(
+ vm.$el.querySelector('.key-created-at').textContent.trim(),
+ ).toBe(`created ${gl.utils.getTimeago().format(deployKey.created_at)}`);
+ });
+
+ it('shows remove button', () => {
+ expect(
+ vm.$el.querySelector('.btn').textContent.trim(),
+ ).toBe('Remove');
+ });
+
+ it('shows write access text when key has write access', (done) => {
+ vm.deployKey.can_push = true;
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelector('.write-access-allowed'),
+ ).not.toBeNull();
+
+ expect(
+ vm.$el.querySelector('.write-access-allowed').textContent.trim(),
+ ).toBe('Write access allowed');
+
+ done();
+ });
+ });
+ });
+
+ describe('public keys', () => {
+ const deployKey = data.public_keys[0];
+
+ beforeEach((done) => {
+ createComponent(deployKey);
+
+ setTimeout(done);
+ });
+
+ it('shows enable button', () => {
+ expect(
+ vm.$el.querySelector('.btn').textContent.trim(),
+ ).toBe('Enable');
+ });
+
+ it('shows disable button when key is enabled', (done) => {
+ vm.store.keys.enabled_keys.push(deployKey);
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelector('.btn').textContent.trim(),
+ ).toBe('Disable');
+
+ done();
+ });
+ });
+ });
+});
diff --git a/spec/javascripts/deploy_keys/components/keys_panel_spec.js b/spec/javascripts/deploy_keys/components/keys_panel_spec.js
new file mode 100644
index 00000000000..a69b39c35c4
--- /dev/null
+++ b/spec/javascripts/deploy_keys/components/keys_panel_spec.js
@@ -0,0 +1,70 @@
+import Vue from 'vue';
+import DeployKeysStore from '~/deploy_keys/store';
+import deployKeysPanel from '~/deploy_keys/components/keys_panel.vue';
+
+describe('Deploy keys panel', () => {
+ const data = getJSONFixture('deploy_keys/keys.json');
+ let vm;
+
+ beforeEach((done) => {
+ const DeployKeysPanelComponent = Vue.extend(deployKeysPanel);
+ const store = new DeployKeysStore();
+ store.keys = data;
+
+ vm = new DeployKeysPanelComponent({
+ propsData: {
+ title: 'test',
+ keys: data.enabled_keys,
+ showHelpBox: true,
+ store,
+ },
+ }).$mount();
+
+ setTimeout(done);
+ });
+
+ it('renders the title with keys count', () => {
+ expect(
+ vm.$el.querySelector('h5').textContent.trim(),
+ ).toContain('test');
+
+ expect(
+ vm.$el.querySelector('h5').textContent.trim(),
+ ).toContain(`(${vm.keys.length})`);
+ });
+
+ it('renders list of keys', () => {
+ expect(
+ vm.$el.querySelectorAll('li').length,
+ ).toBe(vm.keys.length);
+ });
+
+ it('renders help box if keys are empty', (done) => {
+ vm.keys = [];
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelector('.settings-message'),
+ ).toBeDefined();
+
+ expect(
+ vm.$el.querySelector('.settings-message').textContent.trim(),
+ ).toBe('No deploy keys found. Create one with the form above.');
+
+ done();
+ });
+ });
+
+ it('does not render help box if keys are empty & showHelpBox is false', (done) => {
+ vm.keys = [];
+ vm.showHelpBox = false;
+
+ Vue.nextTick(() => {
+ expect(
+ vm.$el.querySelector('.settings-message'),
+ ).toBeNull();
+
+ done();
+ });
+ });
+});
diff --git a/spec/javascripts/environments/environment_actions_spec.js b/spec/javascripts/environments/environment_actions_spec.js
index 676bf61cfd9..596d812c724 100644
--- a/spec/javascripts/environments/environment_actions_spec.js
+++ b/spec/javascripts/environments/environment_actions_spec.js
@@ -4,7 +4,6 @@ import actionsComp from '~/environments/components/environment_actions.vue';
describe('Actions Component', () => {
let ActionsComponent;
let actionsMock;
- let spy;
let component;
beforeEach(() => {
@@ -26,13 +25,9 @@ describe('Actions Component', () => {
},
];
- spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());
component = new ActionsComponent({
propsData: {
actions: actionsMock,
- service: {
- postAction: spy,
- },
},
}).$mount();
});
@@ -48,13 +43,6 @@ describe('Actions Component', () => {
).toEqual(actionsMock.length);
});
- it('should call the service when an action is clicked', () => {
- component.$el.querySelector('.dropdown').click();
- component.$el.querySelector('.js-manual-action-link').click();
-
- expect(spy).toHaveBeenCalledWith(actionsMock[0].play_path);
- });
-
it('should render a disabled action when it\'s not playable', () => {
expect(
component.$el.querySelector('.dropdown-menu li:last-child button').getAttribute('disabled'),
diff --git a/spec/javascripts/environments/environment_rollback_spec.js b/spec/javascripts/environments/environment_rollback_spec.js
index 25397714a76..eb8e49d81fe 100644
--- a/spec/javascripts/environments/environment_rollback_spec.js
+++ b/spec/javascripts/environments/environment_rollback_spec.js
@@ -4,11 +4,9 @@ import rollbackComp from '~/environments/components/environment_rollback.vue';
describe('Rollback Component', () => {
const retryURL = 'https://gitlab.com/retry';
let RollbackComponent;
- let spy;
beforeEach(() => {
RollbackComponent = Vue.extend(rollbackComp);
- spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());
});
it('Should render Re-deploy label when isLastDeployment is true', () => {
@@ -17,9 +15,6 @@ describe('Rollback Component', () => {
propsData: {
retryUrl: retryURL,
isLastDeployment: true,
- service: {
- postAction: spy,
- },
},
}).$mount();
@@ -32,28 +27,9 @@ describe('Rollback Component', () => {
propsData: {
retryUrl: retryURL,
isLastDeployment: false,
- service: {
- postAction: spy,
- },
},
}).$mount();
expect(component.$el.querySelector('span').textContent).toContain('Rollback');
});
-
- it('should call the service when the button is clicked', () => {
- const component = new RollbackComponent({
- propsData: {
- retryUrl: retryURL,
- isLastDeployment: false,
- service: {
- postAction: spy,
- },
- },
- }).$mount();
-
- component.$el.click();
-
- expect(spy).toHaveBeenCalledWith(retryURL);
- });
});
diff --git a/spec/javascripts/environments/environment_stop_spec.js b/spec/javascripts/environments/environment_stop_spec.js
index 942e4aaabd4..8131f1e5b11 100644
--- a/spec/javascripts/environments/environment_stop_spec.js
+++ b/spec/javascripts/environments/environment_stop_spec.js
@@ -4,20 +4,15 @@ import stopComp from '~/environments/components/environment_stop.vue';
describe('Stop Component', () => {
let StopComponent;
let component;
- let spy;
const stopURL = '/stop';
beforeEach(() => {
StopComponent = Vue.extend(stopComp);
- spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());
spyOn(window, 'confirm').and.returnValue(true);
component = new StopComponent({
propsData: {
stopUrl: stopURL,
- service: {
- postAction: spy,
- },
},
}).$mount();
});
@@ -26,9 +21,4 @@ describe('Stop Component', () => {
expect(component.$el.tagName).toEqual('BUTTON');
expect(component.$el.getAttribute('title')).toEqual('Stop');
});
-
- it('should call the service when an action is clicked', () => {
- component.$el.click();
- expect(spy).toHaveBeenCalled();
- });
});
diff --git a/spec/javascripts/fixtures/deploy_keys.rb b/spec/javascripts/fixtures/deploy_keys.rb
new file mode 100644
index 00000000000..16e598a4b29
--- /dev/null
+++ b/spec/javascripts/fixtures/deploy_keys.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Projects::DeployKeysController, '(JavaScript fixtures)', type: :controller do
+ include JavaScriptFixturesHelpers
+
+ let(:admin) { create(:admin) }
+ let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
+ let(:project) { create(:project_empty_repo, namespace: namespace, path: 'todos-project') }
+ let(:project2) { create(:empty_project, :internal)}
+
+ before(:all) do
+ clean_frontend_fixtures('deploy_keys/')
+ end
+
+ before(:each) do
+ sign_in(admin)
+ end
+
+ render_views
+
+ it 'deploy_keys/keys.json' do |example|
+ create(:deploy_key, public: true)
+ project_key = create(:deploy_key, key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCdMHEHyhRjbhEZVddFn6lTWdgEy5Q6Bz4nwGB76xWZI5YT/1WJOMEW+sL5zYd31kk7sd3FJ5L9ft8zWMWrr/iWXQikC2cqZK24H1xy+ZUmrRuJD4qGAaIVoyyzBL+avL+lF8J5lg6YSw8gwJY/lX64/vnJHUlWw2n5BF8IFOWhiw== dummy@gitlab.com')
+ internal_key = create(:deploy_key, key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDNd/UJWhPrpb+b/G5oL109y57yKuCxE+WUGJGYaj7WQKsYRJmLYh1mgjrl+KVyfsWpq4ylOxIfFSnN9xBBFN8mlb0Fma5DC7YsSsibJr3MZ19ZNBprwNcdogET7aW9I0In7Wu5f2KqI6e5W/spJHCy4JVxzVMUvk6Myab0LnJ2iQ== dummy@gitlab.com')
+ create(:deploy_keys_project, project: project, deploy_key: project_key)
+ create(:deploy_keys_project, project: project2, deploy_key: internal_key)
+
+ get :index,
+ namespace_id: project.namespace.to_param,
+ project_id: project,
+ format: :json
+
+ expect(response).to be_success
+ store_frontend_fixture(response, example.description)
+ end
+end
diff --git a/spec/javascripts/fixtures/mini_dropdown_graph.html.haml b/spec/javascripts/fixtures/mini_dropdown_graph.html.haml
index 29370b974af..b532b48a95b 100644
--- a/spec/javascripts/fixtures/mini_dropdown_graph.html.haml
+++ b/spec/javascripts/fixtures/mini_dropdown_graph.html.haml
@@ -3,7 +3,7 @@
Dropdown
%ul.dropdown-menu.mini-pipeline-graph-dropdown-menu.js-builds-dropdown-container
- .js-builds-dropdown-list.scrollable-menu
+ %li.js-builds-dropdown-list.scrollable-menu
- .js-builds-dropdown-loading.builds-dropdown-loading.hidden
- %span.fa.fa-spinner.fa-spin
+ %li.js-builds-dropdown-loading.hidden
+ %span.fa.fa-spinner
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js
index a00efa10119..5eb147ed888 100644
--- a/spec/javascripts/lib/utils/common_utils_spec.js
+++ b/spec/javascripts/lib/utils/common_utils_spec.js
@@ -362,5 +362,16 @@ require('~/lib/utils/common_utils');
gl.utils.setCiStatusFavicon(BUILD_URL);
});
});
+
+ describe('gl.utils.ajaxPost', () => {
+ it('should perform `$.ajax` call and do `POST` request', () => {
+ const requestURL = '/some/random/api';
+ const data = { keyname: 'value' };
+ const ajaxSpy = spyOn($, 'ajax').and.callFake(() => {});
+
+ gl.utils.ajaxPost(requestURL, data);
+ expect(ajaxSpy.calls.allArgs()[0][0].type).toEqual('POST');
+ });
+ });
});
})();
diff --git a/spec/javascripts/notes_spec.js b/spec/javascripts/notes_spec.js
index cdc5c4510ff..7bffa90ab14 100644
--- a/spec/javascripts/notes_spec.js
+++ b/spec/javascripts/notes_spec.js
@@ -26,7 +26,7 @@ import '~/notes';
describe('task lists', function() {
beforeEach(function() {
- $('form').on('submit', function(e) {
+ $('.js-comment-button').on('click', function(e) {
e.preventDefault();
});
this.notes = new Notes();
@@ -60,9 +60,12 @@ import '~/notes';
reset: function() {}
});
- $('form').on('submit', function(e) {
+ $('.js-comment-button').on('click', (e) => {
+ const $form = $(this);
e.preventDefault();
- $('.js-main-target-form').trigger('ajax:success');
+ this.notes.addNote($form);
+ this.notes.reenableTargetFormSubmitButton(e);
+ this.notes.resetMainTargetForm(e);
});
});
@@ -238,8 +241,8 @@ import '~/notes';
$resultantNote = Notes.animateAppendNote(noteHTML, $notesList);
});
- it('should have `fade-in` class', () => {
- expect($resultantNote.hasClass('fade-in')).toEqual(true);
+ it('should have `fade-in-full` class', () => {
+ expect($resultantNote.hasClass('fade-in-full')).toEqual(true);
});
it('should append note to the notes list', () => {
@@ -269,5 +272,221 @@ import '~/notes';
expect($note.replaceWith).toHaveBeenCalledWith($updatedNote);
});
});
+
+ describe('getFormData', () => {
+ it('should return form metadata object from form reference', () => {
+ this.notes = new Notes();
+
+ const $form = $('form');
+ const sampleComment = 'foobar';
+ $form.find('textarea.js-note-text').val(sampleComment);
+ const { formData, formContent, formAction } = this.notes.getFormData($form);
+
+ expect(formData.indexOf(sampleComment) > -1).toBe(true);
+ expect(formContent).toEqual(sampleComment);
+ expect(formAction).toEqual($form.attr('action'));
+ });
+ });
+
+ describe('hasSlashCommands', () => {
+ beforeEach(() => {
+ this.notes = new Notes();
+ });
+
+ it('should return true when comment has slash commands', () => {
+ const sampleComment = '/wip /milestone %1.0 /merge /unassign Merging this';
+ const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
+
+ expect(hasSlashCommands).toBeTruthy();
+ });
+
+ it('should return false when comment does NOT have any slash commands', () => {
+ const sampleComment = 'Looking good, Awesome!';
+ const hasSlashCommands = this.notes.hasSlashCommands(sampleComment);
+
+ expect(hasSlashCommands).toBeFalsy();
+ });
+ });
+
+ describe('stripSlashCommands', () => {
+ const REGEX_SLASH_COMMANDS = /\/\w+/g;
+
+ it('should strip slash commands from the comment', () => {
+ this.notes = new Notes();
+ const sampleComment = '/wip /milestone %1.0 /merge /unassign Merging this';
+ const stripedComment = this.notes.stripSlashCommands(sampleComment);
+
+ expect(REGEX_SLASH_COMMANDS.test(stripedComment)).toBeFalsy();
+ });
+ });
+
+ describe('createPlaceholderNote', () => {
+ const sampleComment = 'foobar';
+ const uniqueId = 'b1234-a4567';
+ const currentUsername = 'root';
+ const currentUserFullname = 'Administrator';
+
+ beforeEach(() => {
+ this.notes = new Notes();
+ });
+
+ it('should return constructed placeholder element for regular note based on form contents', () => {
+ const $tempNote = this.notes.createPlaceholderNote({
+ formContent: sampleComment,
+ uniqueId,
+ isDiscussionNote: false,
+ currentUsername,
+ currentUserFullname
+ });
+ const $tempNoteHeader = $tempNote.find('.note-header');
+
+ expect($tempNote.prop('nodeName')).toEqual('LI');
+ expect($tempNote.attr('id')).toEqual(uniqueId);
+ $tempNote.find('.timeline-icon > a, .note-header-info > a').each(function() {
+ expect($(this).attr('href')).toEqual(`/${currentUsername}`);
+ });
+ expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeFalsy();
+ expect($tempNoteHeader.find('.hidden-xs').text().trim()).toEqual(currentUserFullname);
+ expect($tempNoteHeader.find('.note-headline-light').text().trim()).toEqual(`@${currentUsername}`);
+ expect($tempNote.find('.note-body .note-text').text().trim()).toEqual(sampleComment);
+ });
+
+ it('should return constructed placeholder element for discussion note based on form contents', () => {
+ const $tempNote = this.notes.createPlaceholderNote({
+ formContent: sampleComment,
+ uniqueId,
+ isDiscussionNote: true,
+ currentUsername,
+ currentUserFullname
+ });
+
+ expect($tempNote.prop('nodeName')).toEqual('LI');
+ expect($tempNote.find('.timeline-content').hasClass('discussion')).toBeTruthy();
+ });
+ });
+
+ describe('postComment & updateComment', () => {
+ const sampleComment = 'foo';
+ const updatedComment = 'bar';
+ const note = {
+ id: 1234,
+ html: `<li class="note note-row-1234 timeline-entry" id="note_1234">
+ <div class="note-text">${sampleComment}</div>
+ </li>`,
+ note: sampleComment,
+ valid: true
+ };
+ let $form;
+ let $notesContainer;
+
+ beforeEach(() => {
+ this.notes = new Notes();
+ window.gon.current_username = 'root';
+ window.gon.current_user_fullname = 'Administrator';
+ $form = $('form');
+ $notesContainer = $('ul.main-notes-list');
+ $form.find('textarea.js-note-text').val(sampleComment);
+ $('.js-comment-button').click();
+ });
+
+ it('should show placeholder note while new comment is being posted', () => {
+ expect($notesContainer.find('.note.being-posted').length > 0).toEqual(true);
+ });
+
+ it('should remove placeholder note when new comment is done posting', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ expect($notesContainer.find('.note.being-posted').length).toEqual(0);
+ });
+ });
+
+ it('should show actual note element when new comment is done posting', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ expect($notesContainer.find(`#${note.id}`).length > 0).toEqual(true);
+ });
+ });
+
+ it('should reset Form when new comment is done posting', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ expect($form.find('textarea.js-note-text')).toEqual('');
+ });
+ });
+
+ it('should trigger ajax:success event on Form when new comment is done posting', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ spyOn($form, 'trigger');
+ expect($form.trigger).toHaveBeenCalledWith('ajax:success', [note]);
+ });
+ });
+
+ it('should show flash error message when new comment failed to be posted', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.error();
+ expect($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true);
+ });
+ });
+
+ it('should refill form textarea with original comment content when new comment failed to be posted', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.error();
+ expect($form.find('textarea.js-note-text')).toEqual(sampleComment);
+ });
+ });
+
+ it('should show updated comment as _actively being posted_ while comment being updated', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ const $noteEl = $notesContainer.find(`#note_${note.id}`);
+ $noteEl.find('.js-note-edit').click();
+ $noteEl.find('textarea.js-note-text').val(updatedComment);
+ $noteEl.find('.js-comment-save-button').click();
+ expect($noteEl.hasClass('.being-posted')).toEqual(true);
+ expect($noteEl.find('.note-text').text()).toEqual(updatedComment);
+ });
+ });
+
+ it('should show updated comment when comment update is done posting', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ const $noteEl = $notesContainer.find(`#note_${note.id}`);
+ $noteEl.find('.js-note-edit').click();
+ $noteEl.find('textarea.js-note-text').val(updatedComment);
+ $noteEl.find('.js-comment-save-button').click();
+
+ spyOn($, 'ajax').and.callFake((updateOptions) => {
+ const updatedNote = Object.assign({}, note);
+ updatedNote.note = updatedComment;
+ updatedNote.html = `<li class="note note-row-1234 timeline-entry" id="note_1234">
+ <div class="note-text">${updatedComment}</div>
+ </li>`;
+ updateOptions.success(updatedNote);
+ const $updatedNoteEl = $notesContainer.find(`#note_${updatedNote.id}`);
+ expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
+ expect($updatedNoteEl.find('note-text').text().trim()).toEqual(updatedComment); // Verify if comment text updated
+ });
+ });
+ });
+
+ it('should show flash error message when comment failed to be updated', () => {
+ spyOn($, 'ajax').and.callFake((options) => {
+ options.success(note);
+ const $noteEl = $notesContainer.find(`#note_${note.id}`);
+ $noteEl.find('.js-note-edit').click();
+ $noteEl.find('textarea.js-note-text').val(updatedComment);
+ $noteEl.find('.js-comment-save-button').click();
+
+ spyOn($, 'ajax').and.callFake((updateOptions) => {
+ updateOptions.error();
+ const $updatedNoteEl = $notesContainer.find(`#note_${note.id}`);
+ expect($updatedNoteEl.hasClass('.being-posted')).toEqual(false); // Remove being-posted visuals
+ expect($updatedNoteEl.find('note-text').text().trim()).toEqual(sampleComment); // See if comment reverted back to original
+ expect($notesContainer.parent().find('.flash-container .flash-text').is(':visible')).toEqual(true); // Flash error message shown
+ });
+ });
+ });
+ });
});
}).call(window);
diff --git a/spec/javascripts/pipelines/stage_spec.js b/spec/javascripts/pipelines/stage_spec.js
index 2f1154bd999..a4f32a1faed 100644
--- a/spec/javascripts/pipelines/stage_spec.js
+++ b/spec/javascripts/pipelines/stage_spec.js
@@ -1,81 +1,86 @@
import Vue from 'vue';
-import { SUCCESS_SVG } from '~/ci_status_icons';
-import Stage from '~/pipelines/components/stage';
+import stage from '~/pipelines/components/stage.vue';
+
+describe('Pipelines stage component', () => {
+ let StageComponent;
+ let component;
+
+ beforeEach(() => {
+ StageComponent = Vue.extend(stage);
+
+ component = new StageComponent({
+ propsData: {
+ stage: {
+ status: {
+ group: 'success',
+ icon: 'icon_status_success',
+ title: 'success',
+ },
+ dropdown_path: 'foo',
+ },
+ updateDropdown: false,
+ },
+ }).$mount();
+ });
-function minify(string) {
- return string.replace(/\s/g, '');
-}
+ it('should render a dropdown with the status icon', () => {
+ expect(component.$el.getAttribute('class')).toEqual('dropdown');
+ expect(component.$el.querySelector('svg')).toBeDefined();
+ expect(component.$el.querySelector('button').getAttribute('data-toggle')).toEqual('dropdown');
+ });
-describe('Pipelines Stage', () => {
- describe('data', () => {
- let stageReturnValue;
+ describe('with successfull request', () => {
+ const interceptor = (request, next) => {
+ next(request.respondWith(JSON.stringify({ html: 'foo' }), {
+ status: 200,
+ }));
+ };
beforeEach(() => {
- stageReturnValue = Stage.data();
+ Vue.http.interceptors.push(interceptor);
});
- it('should return object with .builds and .spinner', () => {
- expect(stageReturnValue).toEqual({
- builds: '',
- spinner: '<span class="fa fa-spinner fa-spin"></span>',
- });
+ afterEach(() => {
+ Vue.http.interceptors = _.without(
+ Vue.http.interceptors, interceptor,
+ );
});
- });
- describe('computed', () => {
- describe('svgHTML', function () {
- let stage;
- let svgHTML;
+ it('should render the received data', (done) => {
+ component.$el.querySelector('button').click();
- beforeEach(() => {
- stage = { stage: { status: { icon: 'icon_status_success' } } };
-
- svgHTML = Stage.computed.svgHTML.call(stage);
- });
-
- it("should return the correct icon for the stage's status", () => {
- expect(svgHTML).toBe(SUCCESS_SVG);
- });
+ setTimeout(() => {
+ expect(
+ component.$el.querySelector('.js-builds-dropdown-container ul').textContent.trim(),
+ ).toEqual('foo');
+ done();
+ }, 0);
});
});
- describe('when mounted', () => {
- let StageComponent;
- let renderedComponent;
- let stage;
+ describe('when request fails', () => {
+ const interceptor = (request, next) => {
+ next(request.respondWith(JSON.stringify({}), {
+ status: 500,
+ }));
+ };
beforeEach(() => {
- stage = { status: { icon: 'icon_status_success' } };
-
- StageComponent = Vue.extend(Stage);
-
- renderedComponent = new StageComponent({
- propsData: {
- stage,
- },
- }).$mount();
+ Vue.http.interceptors.push(interceptor);
});
- it('should render the correct status svg', () => {
- const minifiedComponent = minify(renderedComponent.$el.outerHTML);
- const expectedSVG = minify(SUCCESS_SVG);
-
- expect(minifiedComponent).toContain(expectedSVG);
+ afterEach(() => {
+ Vue.http.interceptors = _.without(
+ Vue.http.interceptors, interceptor,
+ );
});
- });
-
- describe('when request fails', () => {
- it('closes dropdown', () => {
- spyOn($, 'ajax').and.callFake(options => options.error());
- const StageComponent = Vue.extend(Stage);
- const component = new StageComponent({
- propsData: { stage: { status: { icon: 'foo' } } },
- }).$mount();
+ it('should close the dropdown', () => {
+ component.$el.click();
- expect(
- component.$el.classList.contains('open'),
- ).toEqual(false);
+ setTimeout(() => {
+ expect(component.$el.classList.contains('open')).toEqual(false);
+ }, 0);
});
});
});
diff --git a/spec/javascripts/vue_shared/translate_spec.js b/spec/javascripts/vue_shared/translate_spec.js
new file mode 100644
index 00000000000..cbb3cbdff46
--- /dev/null
+++ b/spec/javascripts/vue_shared/translate_spec.js
@@ -0,0 +1,90 @@
+import Vue from 'vue';
+import Translate from '~/vue_shared/translate';
+
+Vue.use(Translate);
+
+describe('Vue translate filter', () => {
+ let el;
+
+ beforeEach(() => {
+ el = document.createElement('div');
+
+ document.body.appendChild(el);
+ });
+
+ it('translate single text', (done) => {
+ const comp = new Vue({
+ el,
+ template: `
+ <span>
+ {{ __('testing') }}
+ </span>
+ `,
+ }).$mount();
+
+ Vue.nextTick(() => {
+ expect(
+ comp.$el.textContent.trim(),
+ ).toBe('testing');
+
+ done();
+ });
+ });
+
+ it('translate plural text with single count', (done) => {
+ const comp = new Vue({
+ el,
+ template: `
+ <span>
+ {{ n__('%d day', '%d days', 1) }}
+ </span>
+ `,
+ }).$mount();
+
+ Vue.nextTick(() => {
+ expect(
+ comp.$el.textContent.trim(),
+ ).toBe('1 day');
+
+ done();
+ });
+ });
+
+ it('translate plural text with multiple count', (done) => {
+ const comp = new Vue({
+ el,
+ template: `
+ <span>
+ {{ n__('%d day', '%d days', 2) }}
+ </span>
+ `,
+ }).$mount();
+
+ Vue.nextTick(() => {
+ expect(
+ comp.$el.textContent.trim(),
+ ).toBe('2 days');
+
+ done();
+ });
+ });
+
+ it('translate plural without replacing any text', (done) => {
+ const comp = new Vue({
+ el,
+ template: `
+ <span>
+ {{ n__('day', 'days', 2) }}
+ </span>
+ `,
+ }).$mount();
+
+ Vue.nextTick(() => {
+ expect(
+ comp.$el.textContent.trim(),
+ ).toBe('days');
+
+ done();
+ });
+ });
+});
diff --git a/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb b/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
index abc93e1b44a..3b905611467 100644
--- a/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
+++ b/spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb
@@ -135,6 +135,17 @@ describe Gitlab::Ci::Build::Artifacts::Metadata::Entry do
subject { |example| path(example).nodes }
it { is_expected.to eq 4 }
end
+
+ describe '#blob' do
+ let(:file_entry) { |example| path(example) }
+ subject { file_entry.blob }
+
+ it 'returns a blob representing the entry data' do
+ expect(subject).to be_a(Blob)
+ expect(subject.path).to eq(file_entry.path)
+ expect(subject.size).to eq(file_entry.metadata[:size])
+ end
+ end
end
describe 'non-existent/', path: 'non-existent/' do
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index ddedb7c3443..fea186fd4f4 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1062,7 +1062,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
it "allows ordering by date" do
- expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE)
+ expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE | Rugged::SORT_TOPO)
repository.find_commits(order: :date)
end
diff --git a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
index 4cd8cf313a5..45ccd3d6459 100644
--- a/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
+++ b/spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
@@ -82,9 +82,9 @@ describe Gitlab::HealthChecks::FsShardsCheck do
it { is_expected.to include(metric_class.new(:filesystem_readable, 0, shard: :default)) }
it { is_expected.to include(metric_class.new(:filesystem_writable, 0, shard: :default)) }
- it { is_expected.to include(have_attributes(name: :filesystem_access_latency, value: be > 0, labels: { shard: :default })) }
- it { is_expected.to include(have_attributes(name: :filesystem_read_latency, value: be > 0, labels: { shard: :default })) }
- it { is_expected.to include(have_attributes(name: :filesystem_write_latency, value: be > 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_access_latency, value: be >= 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_read_latency, value: be >= 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_write_latency, value: be >= 0, labels: { shard: :default })) }
end
context 'storage points to directory that has both read and write rights' do
@@ -96,9 +96,9 @@ describe Gitlab::HealthChecks::FsShardsCheck do
it { is_expected.to include(metric_class.new(:filesystem_readable, 1, shard: :default)) }
it { is_expected.to include(metric_class.new(:filesystem_writable, 1, shard: :default)) }
- it { is_expected.to include(have_attributes(name: :filesystem_access_latency, value: be > 0, labels: { shard: :default })) }
- it { is_expected.to include(have_attributes(name: :filesystem_read_latency, value: be > 0, labels: { shard: :default })) }
- it { is_expected.to include(have_attributes(name: :filesystem_write_latency, value: be > 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_access_latency, value: be >= 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_read_latency, value: be >= 0, labels: { shard: :default })) }
+ it { is_expected.to include(have_attributes(name: :filesystem_write_latency, value: be >= 0, labels: { shard: :default })) }
end
end
end
diff --git a/spec/lib/gitlab/health_checks/simple_check_shared.rb b/spec/lib/gitlab/health_checks/simple_check_shared.rb
index 1fa6d0faef9..3f871d66034 100644
--- a/spec/lib/gitlab/health_checks/simple_check_shared.rb
+++ b/spec/lib/gitlab/health_checks/simple_check_shared.rb
@@ -8,7 +8,7 @@ shared_context 'simple_check' do |metrics_prefix, check_name, success_result|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 1)) }
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 0)) }
- it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be > 0)) }
+ it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be >= 0)) }
end
context 'Check is misbehaving' do
@@ -18,7 +18,7 @@ shared_context 'simple_check' do |metrics_prefix, check_name, success_result|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 0)) }
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 0)) }
- it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be > 0)) }
+ it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be >= 0)) }
end
context 'Check is timeouting' do
@@ -28,7 +28,7 @@ shared_context 'simple_check' do |metrics_prefix, check_name, success_result|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 0)) }
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 1)) }
- it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be > 0)) }
+ it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency", value: be >= 0)) }
end
end
diff --git a/spec/lib/gitlab/i18n_spec.rb b/spec/lib/gitlab/i18n_spec.rb
new file mode 100644
index 00000000000..52f2614d5ca
--- /dev/null
+++ b/spec/lib/gitlab/i18n_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+module Gitlab
+ describe I18n, lib: true do
+ let(:user) { create(:user, preferred_language: 'es') }
+
+ describe '.set_locale' do
+ it 'sets the locale based on current user preferred language' do
+ Gitlab::I18n.set_locale(user)
+
+ expect(FastGettext.locale).to eq('es')
+ expect(::I18n.locale).to eq(:es)
+ end
+ end
+
+ describe '.reset_locale' do
+ it 'resets the locale to the default language' do
+ Gitlab::I18n.set_locale(user)
+
+ Gitlab::I18n.reset_locale
+
+ expect(FastGettext.locale).to eq('en')
+ expect(::I18n.locale).to eq(:en)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index ebfaab4eacd..59c8b48a2be 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -351,6 +351,7 @@ Project:
- auto_cancel_pending_pipelines
- printing_merge_request_link_enabled
- build_allow_git_fetch
+- last_repository_updated_at
Author:
- name
ProjectFeature:
diff --git a/spec/lib/gitlab/prometheus_spec.rb b/spec/lib/gitlab/prometheus_spec.rb
index 280264188e2..fc453a2704b 100644
--- a/spec/lib/gitlab/prometheus_spec.rb
+++ b/spec/lib/gitlab/prometheus_spec.rb
@@ -49,6 +49,36 @@ describe Gitlab::Prometheus, lib: true do
end
end
+ describe 'failure to reach a provided prometheus url' do
+ let(:prometheus_url) {"https://prometheus.invalid.example.com"}
+
+ context 'exceptions are raised' do
+ it 'raises a Gitlab::PrometheusError error when a SocketError is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, SocketError)
+
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "Can't connect to #{prometheus_url}")
+ expect(req_stub).to have_been_requested
+ end
+
+ it 'raises a Gitlab::PrometheusError error when a SSLError is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, OpenSSL::SSL::SSLError)
+
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "#{prometheus_url} contains invalid SSL data")
+ expect(req_stub).to have_been_requested
+ end
+
+ it 'raises a Gitlab::PrometheusError error when a HTTParty::Error is rescued' do
+ req_stub = stub_prometheus_request_with_exception(prometheus_url, HTTParty::Error)
+
+ expect { subject.send(:get, prometheus_url) }
+ .to raise_error(Gitlab::PrometheusError, "Network connection error")
+ expect(req_stub).to have_been_requested
+ end
+ end
+ end
+
describe '#query' do
let(:prometheus_query) { prometheus_cpu_query('env-slug') }
let(:query_url) { prometheus_query_url(prometheus_query) }
diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb
index 6675d26734e..a97a0f8452b 100644
--- a/spec/lib/gitlab/shell_spec.rb
+++ b/spec/lib/gitlab/shell_spec.rb
@@ -91,4 +91,45 @@ describe Gitlab::Shell, lib: true do
end
end
end
+
+ describe 'projects commands' do
+ let(:projects_path) { 'tmp/tests/shell-projects-test/bin/gitlab-projects' }
+
+ before do
+ allow(Gitlab.config.gitlab_shell).to receive(:path).and_return('tmp/tests/shell-projects-test')
+ allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800)
+ end
+
+ describe '#fetch_remote' do
+ it 'returns true when the command succeeds' do
+ expect(Gitlab::Popen).to receive(:popen)
+ .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800']).and_return([nil, 0])
+
+ expect(gitlab_shell.fetch_remote('current/storage', 'project/path', 'new/storage')).to be true
+ end
+
+ it 'raises an exception when the command fails' do
+ expect(Gitlab::Popen).to receive(:popen)
+ .with([projects_path, 'fetch-remote', 'current/storage', 'project/path.git', 'new/storage', '800']).and_return(["error", 1])
+
+ expect { gitlab_shell.fetch_remote('current/storage', 'project/path', 'new/storage') }.to raise_error(Gitlab::Shell::Error, "error")
+ end
+ end
+
+ describe '#import_repository' do
+ it 'returns true when the command succeeds' do
+ expect(Gitlab::Popen).to receive(:popen)
+ .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"]).and_return([nil, 0])
+
+ expect(gitlab_shell.import_repository('current/storage', 'project/path', 'https://gitlab.com/gitlab-org/gitlab-ce.git')).to be true
+ end
+
+ it 'raises an exception when the command fails' do
+ expect(Gitlab::Popen).to receive(:popen)
+ .with([projects_path, 'import-project', 'current/storage', 'project/path.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', "800"]).and_return(["error", 1])
+
+ expect { gitlab_shell.import_repository('current/storage', 'project/path', 'https://gitlab.com/gitlab-org/gitlab-ce.git') }.to raise_error(Gitlab::Shell::Error, "error")
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/slash_commands/command_definition_spec.rb b/spec/lib/gitlab/slash_commands/command_definition_spec.rb
index c9c2f314e57..5b9173d3d3f 100644
--- a/spec/lib/gitlab/slash_commands/command_definition_spec.rb
+++ b/spec/lib/gitlab/slash_commands/command_definition_spec.rb
@@ -167,6 +167,58 @@ describe Gitlab::SlashCommands::CommandDefinition do
end
end
end
+
+ context 'when the command defines parse_params block' do
+ before do
+ subject.parse_params_block = ->(raw) { raw.strip }
+ subject.action_block = ->(parsed) { self.received_arg = parsed }
+ end
+
+ it 'executes the command passing the parsed param' do
+ subject.execute(context, {}, 'something ')
+
+ expect(context.received_arg).to eq('something')
+ end
+ end
+ end
+ end
+ end
+
+ describe '#explain' do
+ context 'when the command is not available' do
+ before do
+ subject.condition_block = proc { false }
+ subject.explanation = 'Explanation'
+ end
+
+ it 'returns nil' do
+ result = subject.explain({}, {}, nil)
+
+ expect(result).to be_nil
+ end
+ end
+
+ context 'when the explanation is a static string' do
+ before do
+ subject.explanation = 'Explanation'
+ end
+
+ it 'returns this static string' do
+ result = subject.explain({}, {}, nil)
+
+ expect(result).to eq 'Explanation'
+ end
+ end
+
+ context 'when the explanation is dynamic' do
+ before do
+ subject.explanation = proc { |arg| "Dynamic #{arg}" }
+ end
+
+ it 'invokes the proc' do
+ result = subject.explain({}, {}, 'explanation')
+
+ expect(result).to eq 'Dynamic explanation'
end
end
end
diff --git a/spec/lib/gitlab/slash_commands/dsl_spec.rb b/spec/lib/gitlab/slash_commands/dsl_spec.rb
index 2763d950716..33b49a5ddf9 100644
--- a/spec/lib/gitlab/slash_commands/dsl_spec.rb
+++ b/spec/lib/gitlab/slash_commands/dsl_spec.rb
@@ -11,67 +11,99 @@ describe Gitlab::SlashCommands::Dsl do
end
params 'The first argument'
- command :one_arg, :once, :first do |arg1|
- arg1
+ explanation 'Static explanation'
+ command :explanation_with_aliases, :once, :first do |arg|
+ arg
end
desc do
"A dynamic description for #{noteable.upcase}"
end
params 'The first argument', 'The second argument'
- command :two_args do |arg1, arg2|
- [arg1, arg2]
+ command :dynamic_description do |args|
+ args.split
end
command :cc
+ explanation do |arg|
+ "Action does something with #{arg}"
+ end
condition do
project == 'foo'
end
command :cond_action do |arg|
arg
end
+
+ parse_params do |raw_arg|
+ raw_arg.strip
+ end
+ command :with_params_parsing do |parsed|
+ parsed
+ end
end
end
describe '.command_definitions' do
it 'returns an array with commands definitions' do
- no_args_def, one_arg_def, two_args_def, cc_def, cond_action_def = DummyClass.command_definitions
+ no_args_def, explanation_with_aliases_def, dynamic_description_def,
+ cc_def, cond_action_def, with_params_parsing_def =
+ DummyClass.command_definitions
expect(no_args_def.name).to eq(:no_args)
expect(no_args_def.aliases).to eq([:none])
expect(no_args_def.description).to eq('A command with no args')
+ expect(no_args_def.explanation).to eq('')
expect(no_args_def.params).to eq([])
expect(no_args_def.condition_block).to be_nil
expect(no_args_def.action_block).to be_a_kind_of(Proc)
+ expect(no_args_def.parse_params_block).to be_nil
- expect(one_arg_def.name).to eq(:one_arg)
- expect(one_arg_def.aliases).to eq([:once, :first])
- expect(one_arg_def.description).to eq('')
- expect(one_arg_def.params).to eq(['The first argument'])
- expect(one_arg_def.condition_block).to be_nil
- expect(one_arg_def.action_block).to be_a_kind_of(Proc)
+ expect(explanation_with_aliases_def.name).to eq(:explanation_with_aliases)
+ expect(explanation_with_aliases_def.aliases).to eq([:once, :first])
+ expect(explanation_with_aliases_def.description).to eq('')
+ expect(explanation_with_aliases_def.explanation).to eq('Static explanation')
+ expect(explanation_with_aliases_def.params).to eq(['The first argument'])
+ expect(explanation_with_aliases_def.condition_block).to be_nil
+ expect(explanation_with_aliases_def.action_block).to be_a_kind_of(Proc)
+ expect(explanation_with_aliases_def.parse_params_block).to be_nil
- expect(two_args_def.name).to eq(:two_args)
- expect(two_args_def.aliases).to eq([])
- expect(two_args_def.to_h(noteable: "issue")[:description]).to eq('A dynamic description for ISSUE')
- expect(two_args_def.params).to eq(['The first argument', 'The second argument'])
- expect(two_args_def.condition_block).to be_nil
- expect(two_args_def.action_block).to be_a_kind_of(Proc)
+ expect(dynamic_description_def.name).to eq(:dynamic_description)
+ expect(dynamic_description_def.aliases).to eq([])
+ expect(dynamic_description_def.to_h(noteable: 'issue')[:description]).to eq('A dynamic description for ISSUE')
+ expect(dynamic_description_def.explanation).to eq('')
+ expect(dynamic_description_def.params).to eq(['The first argument', 'The second argument'])
+ expect(dynamic_description_def.condition_block).to be_nil
+ expect(dynamic_description_def.action_block).to be_a_kind_of(Proc)
+ expect(dynamic_description_def.parse_params_block).to be_nil
expect(cc_def.name).to eq(:cc)
expect(cc_def.aliases).to eq([])
expect(cc_def.description).to eq('')
+ expect(cc_def.explanation).to eq('')
expect(cc_def.params).to eq([])
expect(cc_def.condition_block).to be_nil
expect(cc_def.action_block).to be_nil
+ expect(cc_def.parse_params_block).to be_nil
expect(cond_action_def.name).to eq(:cond_action)
expect(cond_action_def.aliases).to eq([])
expect(cond_action_def.description).to eq('')
+ expect(cond_action_def.explanation).to be_a_kind_of(Proc)
expect(cond_action_def.params).to eq([])
expect(cond_action_def.condition_block).to be_a_kind_of(Proc)
expect(cond_action_def.action_block).to be_a_kind_of(Proc)
+ expect(cond_action_def.parse_params_block).to be_nil
+
+ expect(with_params_parsing_def.name).to eq(:with_params_parsing)
+ expect(with_params_parsing_def.aliases).to eq([])
+ expect(with_params_parsing_def.description).to eq('')
+ expect(with_params_parsing_def.explanation).to eq('')
+ expect(with_params_parsing_def.params).to eq([])
+ expect(with_params_parsing_def.condition_block).to be_nil
+ expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc)
+ expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc)
end
end
end
diff --git a/spec/models/ci/artifact_blob_spec.rb b/spec/models/ci/artifact_blob_spec.rb
new file mode 100644
index 00000000000..968593d7e9b
--- /dev/null
+++ b/spec/models/ci/artifact_blob_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe Ci::ArtifactBlob, models: true do
+ let(:build) { create(:ci_build, :artifacts) }
+ let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/another-subdirectory/banana_sample.gif') }
+
+ subject { described_class.new(entry) }
+
+ describe '#id' do
+ it 'returns a hash of the path' do
+ expect(subject.id).to eq(Digest::SHA1.hexdigest(entry.path))
+ end
+ end
+
+ describe '#name' do
+ it 'returns the entry name' do
+ expect(subject.name).to eq(entry.name)
+ end
+ end
+
+ describe '#path' do
+ it 'returns the entry path' do
+ expect(subject.path).to eq(entry.path)
+ end
+ end
+
+ describe '#size' do
+ it 'returns the entry size' do
+ expect(subject.size).to eq(entry.metadata[:size])
+ end
+ end
+
+ describe '#mode' do
+ it 'returns the entry mode' do
+ expect(subject.mode).to eq(entry.metadata[:mode])
+ end
+ end
+
+ describe '#external_storage' do
+ it 'returns :build_artifact' do
+ expect(subject.external_storage).to eq(:build_artifact)
+ end
+ end
+end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index e5954d80f00..b8cb967c4cc 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -15,13 +15,39 @@ describe Event, models: true do
end
describe 'Callbacks' do
- describe 'after_create :reset_project_activity' do
- let(:project) { create(:empty_project) }
+ let(:project) { create(:empty_project) }
+ describe 'after_create :reset_project_activity' do
it 'calls the reset_project_activity method' do
expect_any_instance_of(described_class).to receive(:reset_project_activity)
- create_event(project, project.owner)
+ create_push_event(project, project.owner)
+ end
+ end
+
+ describe 'after_create :set_last_repository_updated_at' do
+ context 'with a push event' do
+ it 'updates the project last_repository_updated_at' do
+ project.update(last_repository_updated_at: 1.year.ago)
+
+ create_push_event(project, project.owner)
+
+ project.reload
+
+ expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
+ end
+ end
+
+ context 'without a push event' do
+ it 'does not update the project last_repository_updated_at' do
+ project.update(last_repository_updated_at: 1.year.ago)
+
+ create(:closed_issue_event, project: project, author: project.owner)
+
+ project.reload
+
+ expect(project.last_repository_updated_at).to be_within(1.minute).of(1.year.ago)
+ end
end
end
end
@@ -29,7 +55,7 @@ describe Event, models: true do
describe "Push event" do
let(:project) { create(:empty_project, :private) }
let(:user) { project.owner }
- let(:event) { create_event(project, user) }
+ let(:event) { create_push_event(project, user) }
it do
expect(event.push?).to be_truthy
@@ -243,7 +269,7 @@ describe Event, models: true do
expect(project).not_to receive(:update_column).
with(:last_activity_at, a_kind_of(Time))
- create_event(project, project.owner)
+ create_push_event(project, project.owner)
end
end
@@ -251,11 +277,11 @@ describe Event, models: true do
it 'updates the project' do
project.update(last_activity_at: 1.year.ago)
- create_event(project, project.owner)
+ create_push_event(project, project.owner)
project.reload
- project.last_activity_at <= 1.minute.ago
+ expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
end
end
end
@@ -278,7 +304,7 @@ describe Event, models: true do
end
end
- def create_event(project, user, attrs = {})
+ def create_push_event(project, user, attrs = {})
data = {
before: Gitlab::Git::BLANK_SHA,
after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
diff --git a/spec/models/network/graph_spec.rb b/spec/models/network/graph_spec.rb
index 46b36e11c23..0fe8a591a45 100644
--- a/spec/models/network/graph_spec.rb
+++ b/spec/models/network/graph_spec.rb
@@ -10,17 +10,17 @@ describe Network::Graph, models: true do
expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } )
end
- describe "#commits" do
+ describe '#commits' do
let(:graph) { described_class.new(project, 'refs/heads/master', project.repository.commit, nil) }
- it "returns a list of commits" do
+ it 'returns a list of commits' do
commits = graph.commits
expect(commits).not_to be_empty
expect(commits).to all( be_kind_of(Network::Commit) )
end
- it "sorts the commits by commit date (descending)" do
+ it 'it the commits by commit date (descending)' do
# Remove duplicate timestamps because they make it harder to
# assert that the commits are sorted as expected.
commits = graph.commits.uniq(&:date)
@@ -29,5 +29,20 @@ describe Network::Graph, models: true do
expect(commits).not_to be_empty
expect(commits.map(&:id)).to eq(sorted_commits.map(&:id))
end
+
+ it 'sorts children before parents for commits with the same timestamp' do
+ commits_by_time = graph.commits.group_by(&:date)
+
+ commits_by_time.each do |time, commits|
+ commit_ids = commits.map(&:id)
+
+ commits.each_with_index do |commit, index|
+ parent_indexes = commit.parent_ids.map { |parent_id| commit_ids.find_index(parent_id) }.compact
+
+ # All parents of the current commit should appear after it
+ expect(parent_indexes).to all( be > index )
+ end
+ end
+ end
end
end
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index d15079b686b..f3126bc1e57 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -94,7 +94,7 @@ describe PrometheusService, models: true, caching: true do
[404, 500].each do |status|
context "when Prometheus responds with #{status}" do
before do
- stub_all_prometheus_requests(environment.slug, status: status, body: 'QUERY FAILED!')
+ stub_all_prometheus_requests(environment.slug, status: status, body: "QUERY FAILED!")
end
it { is_expected.to eq(success: false, result: %(#{status} - "QUERY FAILED!")) }
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 36ce3070a6e..316ece87faa 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1925,4 +1925,12 @@ describe Project, models: true do
not_to raise_error
end
end
+
+ describe '#last_repository_updated_at' do
+ it 'sets to created_at upon creation' do
+ project = create(:empty_project, created_at: 2.hours.ago)
+
+ expect(project.last_repository_updated_at.to_i).to eq(project.created_at.to_i)
+ end
+ end
end
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index b5b9cd024b0..969e9f7a130 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -213,9 +213,12 @@ describe ProjectWiki, models: true do
end
it 'updates project activity' do
- expect(subject).to receive(:update_project_activity)
-
subject.create_page('Test Page', 'This is content')
+
+ project.reload
+
+ expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
+ expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
end
end
@@ -240,9 +243,12 @@ describe ProjectWiki, models: true do
end
it 'updates project activity' do
- expect(subject).to receive(:update_project_activity)
-
subject.update_page(@gollum_page, 'Yet more content', :markdown, 'Updated page again')
+
+ project.reload
+
+ expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
+ expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
end
end
@@ -258,9 +264,12 @@ describe ProjectWiki, models: true do
end
it 'updates project activity' do
- expect(subject).to receive(:update_project_activity)
-
subject.delete_page(@page)
+
+ project.reload
+
+ expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
+ expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 1c2df4c9d97..13179174956 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1663,4 +1663,12 @@ describe User, models: true do
expect(User.active.count).to eq(1)
end
end
+
+ describe 'preferred language' do
+ it 'is English by default' do
+ user = create(:user)
+
+ expect(user.preferred_language).to eq('en')
+ end
+ end
end
diff --git a/spec/policies/personal_snippet_policy_spec.rb b/spec/policies/personal_snippet_policy_spec.rb
new file mode 100644
index 00000000000..58aa1145c9e
--- /dev/null
+++ b/spec/policies/personal_snippet_policy_spec.rb
@@ -0,0 +1,141 @@
+require 'spec_helper'
+
+describe PersonalSnippetPolicy, models: true do
+ let(:regular_user) { create(:user) }
+ let(:external_user) { create(:user, :external) }
+ let(:admin_user) { create(:user, :admin) }
+
+ let(:author_permissions) do
+ [
+ :update_personal_snippet,
+ :admin_personal_snippet,
+ :destroy_personal_snippet
+ ]
+ end
+
+ def permissions(user)
+ described_class.abilities(user, snippet).to_set
+ end
+
+ context 'public snippet' do
+ let(:snippet) { create(:personal_snippet, :public) }
+
+ context 'no user' do
+ subject { permissions(nil) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'regular user' do
+ subject { permissions(regular_user) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'author' do
+ subject { permissions(snippet.author) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.to include(:comment_personal_snippet)
+ is_expected.to include(*author_permissions)
+ end
+ end
+ end
+
+ context 'internal snippet' do
+ let(:snippet) { create(:personal_snippet, :internal) }
+
+ context 'no user' do
+ subject { permissions(nil) }
+
+ it do
+ is_expected.not_to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'regular user' do
+ subject { permissions(regular_user) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'external user' do
+ subject { permissions(external_user) }
+
+ it do
+ is_expected.not_to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'snippet author' do
+ subject { permissions(snippet.author) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.to include(:comment_personal_snippet)
+ is_expected.to include(*author_permissions)
+ end
+ end
+ end
+
+ context 'private snippet' do
+ let(:snippet) { create(:project_snippet, :private) }
+
+ context 'no user' do
+ subject { permissions(nil) }
+
+ it do
+ is_expected.not_to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'regular user' do
+ subject { permissions(regular_user) }
+
+ it do
+ is_expected.not_to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'external user' do
+ subject { permissions(external_user) }
+
+ it do
+ is_expected.not_to include(:read_personal_snippet)
+ is_expected.not_to include(:comment_personal_snippet)
+ is_expected.not_to include(*author_permissions)
+ end
+ end
+
+ context 'snippet author' do
+ subject { permissions(snippet.author) }
+
+ it do
+ is_expected.to include(:read_personal_snippet)
+ is_expected.to include(:comment_personal_snippet)
+ is_expected.to include(*author_permissions)
+ end
+ end
+ end
+end
diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb
deleted file mode 100644
index d20866c0d44..00000000000
--- a/spec/requests/projects/artifacts_controller_spec.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-require 'spec_helper'
-
-describe Projects::ArtifactsController do
- let(:user) { create(:user) }
- let(:project) { create(:project, :repository) }
-
- let(:pipeline) do
- create(:ci_pipeline,
- project: project,
- sha: project.commit.sha,
- ref: project.default_branch,
- status: 'success')
- end
-
- let(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
-
- describe 'GET /:project/builds/artifacts/:ref_name/browse?job=name' do
- before do
- project.team << [user, :developer]
-
- login_as(user)
- end
-
- def path_from_ref(
- ref = pipeline.ref, job = build.name, path = 'browse')
- latest_succeeded_namespace_project_artifacts_path(
- project.namespace,
- project,
- [ref, path].join('/'),
- job: job)
- end
-
- context 'cannot find the build' do
- shared_examples 'not found' do
- it { expect(response).to have_http_status(:not_found) }
- end
-
- context 'has no such ref' do
- before do
- get path_from_ref('TAIL', build.name)
- end
-
- it_behaves_like 'not found'
- end
-
- context 'has no such build' do
- before do
- get path_from_ref(pipeline.ref, 'NOBUILD')
- end
-
- it_behaves_like 'not found'
- end
-
- context 'has no path' do
- before do
- get path_from_ref(pipeline.sha, build.name, '')
- end
-
- it_behaves_like 'not found'
- end
- end
-
- context 'found the build and redirect' do
- shared_examples 'redirect to the build' do
- it 'redirects' do
- path = browse_namespace_project_build_artifacts_path(
- project.namespace,
- project,
- build)
-
- expect(response).to redirect_to(path)
- end
- end
-
- context 'with regular branch' do
- before do
- pipeline.update(ref: 'master',
- sha: project.commit('master').sha)
-
- get path_from_ref('master')
- end
-
- it_behaves_like 'redirect to the build'
- end
-
- context 'with branch name containing slash' do
- before do
- pipeline.update(ref: 'improve/awesome',
- sha: project.commit('improve/awesome').sha)
-
- get path_from_ref('improve/awesome')
- end
-
- it_behaves_like 'redirect to the build'
- end
-
- context 'with branch name and path containing slashes' do
- before do
- pipeline.update(ref: 'improve/awesome',
- sha: project.commit('improve/awesome').sha)
-
- get path_from_ref('improve/awesome', build.name, 'file/README.md')
- end
-
- it 'redirects' do
- path = file_namespace_project_build_artifacts_path(
- project.namespace,
- project,
- build,
- 'README.md')
-
- expect(response).to redirect_to(path)
- end
- end
- end
- end
-end
diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_key_entity_spec.rb
new file mode 100644
index 00000000000..e73fbe190ca
--- /dev/null
+++ b/spec/serializers/deploy_key_entity_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe DeployKeyEntity do
+ include RequestAwareEntity
+
+ let(:user) { create(:user) }
+ let(:project) { create(:empty_project, :internal)}
+ let(:project_private) { create(:empty_project, :private)}
+ let(:deploy_key) { create(:deploy_key) }
+ let!(:deploy_key_internal) { create(:deploy_keys_project, project: project, deploy_key: deploy_key) }
+ let!(:deploy_key_private) { create(:deploy_keys_project, project: project_private, deploy_key: deploy_key) }
+
+ let(:entity) { described_class.new(deploy_key, user: user) }
+
+ it 'returns deploy keys with projects a user can read' do
+ expected_result = {
+ id: deploy_key.id,
+ user_id: deploy_key.user_id,
+ title: deploy_key.title,
+ fingerprint: deploy_key.fingerprint,
+ can_push: deploy_key.can_push,
+ destroyed_when_orphaned: true,
+ almost_orphaned: false,
+ created_at: deploy_key.created_at,
+ updated_at: deploy_key.updated_at,
+ projects: [
+ {
+ id: project.id,
+ name: project.name,
+ full_path: namespace_project_path(project.namespace, project),
+ full_name: project.full_name
+ }
+ ]
+ }
+
+ expect(entity.as_json).to eq(expected_result)
+ end
+end
diff --git a/spec/services/preview_markdown_service_spec.rb b/spec/services/preview_markdown_service_spec.rb
new file mode 100644
index 00000000000..b2fb5c91313
--- /dev/null
+++ b/spec/services/preview_markdown_service_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe PreviewMarkdownService do
+ let(:user) { create(:user) }
+ let(:project) { create(:empty_project) }
+
+ before do
+ project.add_developer(user)
+ end
+
+ describe 'user references' do
+ let(:params) { { text: "Take a look #{user.to_reference}" } }
+ let(:service) { described_class.new(project, user, params) }
+
+ it 'returns users referenced in text' do
+ result = service.execute
+
+ expect(result[:users]).to eq [user.username]
+ end
+ end
+
+ context 'new note with slash commands' do
+ let(:issue) { create(:issue, project: project) }
+ let(:params) do
+ {
+ text: "Please do it\n/assign #{user.to_reference}",
+ slash_commands_target_type: 'Issue',
+ slash_commands_target_id: issue.id
+ }
+ end
+ let(:service) { described_class.new(project, user, params) }
+
+ it 'removes slash commands from text' do
+ result = service.execute
+
+ expect(result[:text]).to eq 'Please do it'
+ end
+
+ it 'explains slash commands effect' do
+ result = service.execute
+
+ expect(result[:commands]).to eq "Assigns #{user.to_reference}."
+ end
+ end
+
+ context 'merge request description' do
+ let(:params) do
+ {
+ text: "My work\n/estimate 2y",
+ slash_commands_target_type: 'MergeRequest'
+ }
+ end
+ let(:service) { described_class.new(project, user, params) }
+
+ it 'removes slash commands from text' do
+ result = service.execute
+
+ expect(result[:text]).to eq 'My work'
+ end
+
+ it 'explains slash commands effect' do
+ result = service.execute
+
+ expect(result[:commands]).to eq 'Sets time estimate to 2y.'
+ end
+ end
+end
diff --git a/spec/services/slash_commands/interpret_service_spec.rb b/spec/services/slash_commands/interpret_service_spec.rb
index 9c16421fef0..24f2c1407aa 100644
--- a/spec/services/slash_commands/interpret_service_spec.rb
+++ b/spec/services/slash_commands/interpret_service_spec.rb
@@ -826,4 +826,211 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
+
+ describe '#explain' do
+ let(:service) { described_class.new(project, developer) }
+ let(:merge_request) { create(:merge_request, source_project: project) }
+
+ describe 'close command' do
+ let(:content) { '/close' }
+
+ it 'includes issuable name' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Closes this issue.'])
+ end
+ end
+
+ describe 'reopen command' do
+ let(:content) { '/reopen' }
+ let(:merge_request) { create(:merge_request, :closed, source_project: project) }
+
+ it 'includes issuable name' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Reopens this merge request.'])
+ end
+ end
+
+ describe 'title command' do
+ let(:content) { '/title This is new title' }
+
+ it 'includes new title' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Changes the title to "This is new title".'])
+ end
+ end
+
+ describe 'assign command' do
+ let(:content) { "/assign @#{developer.username} do it!" }
+
+ it 'includes only the user reference' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(["Assigns @#{developer.username}."])
+ end
+ end
+
+ describe 'unassign command' do
+ let(:content) { '/unassign' }
+ let(:issue) { create(:issue, project: project, assignee: developer) }
+
+ it 'includes current assignee reference' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(["Removes assignee @#{developer.username}."])
+ end
+ end
+
+ describe 'milestone command' do
+ let(:content) { '/milestone %wrong-milestone' }
+ let!(:milestone) { create(:milestone, project: project, title: '9.10') }
+
+ it 'is empty when milestone reference is wrong' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq([])
+ end
+ end
+
+ describe 'remove milestone command' do
+ let(:content) { '/remove_milestone' }
+ let(:merge_request) { create(:merge_request, source_project: project, milestone: milestone) }
+
+ it 'includes current milestone name' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Removes %"9.10" milestone.'])
+ end
+ end
+
+ describe 'label command' do
+ let(:content) { '/label ~missing' }
+ let!(:label) { create(:label, project: project) }
+
+ it 'is empty when there are no correct labels' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq([])
+ end
+ end
+
+ describe 'unlabel command' do
+ let(:content) { '/unlabel' }
+
+ it 'says all labels if no parameter provided' do
+ merge_request.update!(label_ids: [bug.id])
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Removes all labels.'])
+ end
+ end
+
+ describe 'relabel command' do
+ let(:content) { '/relabel Bug' }
+ let!(:bug) { create(:label, project: project, title: 'Bug') }
+ let(:feature) { create(:label, project: project, title: 'Feature') }
+
+ it 'includes label name' do
+ issue.update!(label_ids: [feature.id])
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(["Replaces all labels with ~#{bug.id} label."])
+ end
+ end
+
+ describe 'subscribe command' do
+ let(:content) { '/subscribe' }
+
+ it 'includes issuable name' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Subscribes to this issue.'])
+ end
+ end
+
+ describe 'unsubscribe command' do
+ let(:content) { '/unsubscribe' }
+
+ it 'includes issuable name' do
+ merge_request.subscribe(developer, project)
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Unsubscribes from this merge request.'])
+ end
+ end
+
+ describe 'due command' do
+ let(:content) { '/due April 1st 2016' }
+
+ it 'includes the date' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Sets the due date to Apr 1, 2016.'])
+ end
+ end
+
+ describe 'wip command' do
+ let(:content) { '/wip' }
+
+ it 'includes the new status' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Marks this merge request as Work In Progress.'])
+ end
+ end
+
+ describe 'award command' do
+ let(:content) { '/award :confetti_ball: ' }
+
+ it 'includes the emoji' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Toggles :confetti_ball: emoji award.'])
+ end
+ end
+
+ describe 'estimate command' do
+ let(:content) { '/estimate 79d' }
+
+ it 'includes the formatted duration' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Sets time estimate to 3mo 3w 4d.'])
+ end
+ end
+
+ describe 'spend command' do
+ let(:content) { '/spend -120m' }
+
+ it 'includes the formatted duration and proper verb' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(['Substracts 2h spent time.'])
+ end
+ end
+
+ describe 'target branch command' do
+ let(:content) { '/target_branch my-feature ' }
+
+ it 'includes the branch name' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to eq(['Sets target branch to my-feature.'])
+ end
+ end
+
+ describe 'board move command' do
+ let(:content) { '/board_move ~bug' }
+ let!(:bug) { create(:label, project: project, title: 'bug') }
+ let!(:board) { create(:board, project: project) }
+
+ it 'includes the label name' do
+ _, explanations = service.explain(content, issue)
+
+ expect(explanations).to eq(["Moves issue to ~#{bug.id} column in the board."])
+ end
+ end
+ end
end
diff --git a/spec/services/projects/upload_service_spec.rb b/spec/services/upload_service_spec.rb
index d2cefa46bfa..95ba28dbecd 100644
--- a/spec/services/projects/upload_service_spec.rb
+++ b/spec/services/upload_service_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Projects::UploadService, services: true do
+describe UploadService, services: true do
describe 'File service' do
before do
@user = create(:user)
@@ -68,6 +68,6 @@ describe Projects::UploadService, services: true do
end
def upload_file(project, file)
- Projects::UploadService.new(project, file).execute
+ described_class.new(project, file, FileUploader).execute
end
end
diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_slash_commands_shared_examples.rb
index f7499ede09c..32f9b979b15 100644
--- a/spec/support/features/issuable_slash_commands_shared_examples.rb
+++ b/spec/support/features/issuable_slash_commands_shared_examples.rb
@@ -58,6 +58,7 @@ shared_examples 'issuable record that supports slash commands in its description
expect(page).not_to have_content '/label ~bug'
expect(page).not_to have_content '/milestone %"ASAP"'
+ wait_for_ajax
issuable.reload
note = issuable.notes.user.first
@@ -257,4 +258,19 @@ shared_examples 'issuable record that supports slash commands in its description
end
end
end
+
+ describe "preview of note on #{issuable_type}" do
+ it 'removes slash commands from note and explains them' do
+ visit public_send("namespace_project_#{issuable_type}_path", project.namespace, project, issuable)
+
+ page.within('.js-main-target-form') do
+ fill_in 'note[note]', with: "Awesome!\n/assign @bob "
+ click_on 'Preview'
+
+ expect(page).to have_content 'Awesome!'
+ expect(page).not_to have_content '/assign @bob'
+ expect(page).to have_content 'Assigns @bob.'
+ end
+ end
+ end
end
diff --git a/spec/support/prometheus_helpers.rb b/spec/support/prometheus_helpers.rb
index cc79b11616a..a204365431b 100644
--- a/spec/support/prometheus_helpers.rb
+++ b/spec/support/prometheus_helpers.rb
@@ -33,6 +33,10 @@ module PrometheusHelpers
})
end
+ def stub_prometheus_request_with_exception(url, exception_type)
+ WebMock.stub_request(:get, url).to_raise(exception_type)
+ end
+
def stub_all_prometheus_requests(environment_slug, body: nil, status: 200)
stub_prometheus_request(
prometheus_query_url(prometheus_memory_query(environment_slug)),
diff --git a/spec/support/time_tracking_shared_examples.rb b/spec/support/time_tracking_shared_examples.rb
index bd5d71f964a..c8e7af19f89 100644
--- a/spec/support/time_tracking_shared_examples.rb
+++ b/spec/support/time_tracking_shared_examples.rb
@@ -8,6 +8,7 @@ shared_examples 'issuable time tracker' do
it 'updates the sidebar component when estimate is added' do
submit_time('/estimate 3w 1d 1h')
+ wait_for_ajax
page.within '.time-tracking-estimate-only-pane' do
expect(page).to have_content '3w 1d 1h'
end
@@ -16,6 +17,7 @@ shared_examples 'issuable time tracker' do
it 'updates the sidebar component when spent is added' do
submit_time('/spend 3w 1d 1h')
+ wait_for_ajax
page.within '.time-tracking-spend-only-pane' do
expect(page).to have_content '3w 1d 1h'
end
@@ -25,6 +27,7 @@ shared_examples 'issuable time tracker' do
submit_time('/estimate 3w 1d 1h')
submit_time('/spend 3w 1d 1h')
+ wait_for_ajax
page.within '.time-tracking-comparison-pane' do
expect(page).to have_content '3w 1d 1h'
end
@@ -34,7 +37,12 @@ shared_examples 'issuable time tracker' do
submit_time('/estimate 3w 1d 1h')
submit_time('/remove_estimate')
+<<<<<<< HEAD
page.within '.time-tracking-component-wrap' do
+=======
+ wait_for_ajax
+ page.within '#issuable-time-tracker' do
+>>>>>>> 10c1bf2d77fd0ab21309d0b136cbc0ac11f56c77
expect(page).to have_content 'No estimate or time spent'
end
end
@@ -43,7 +51,12 @@ shared_examples 'issuable time tracker' do
submit_time('/spend 3w 1d 1h')
submit_time('/remove_time_spent')
+<<<<<<< HEAD
page.within '.time-tracking-component-wrap' do
+=======
+ wait_for_ajax
+ page.within '#issuable-time-tracker' do
+>>>>>>> 10c1bf2d77fd0ab21309d0b136cbc0ac11f56c77
expect(page).to have_content 'No estimate or time spent'
end
end
diff --git a/spec/tasks/gitlab/shell_rake_spec.rb b/spec/tasks/gitlab/shell_rake_spec.rb
index 226d34fe2c9..ee3614c50f6 100644
--- a/spec/tasks/gitlab/shell_rake_spec.rb
+++ b/spec/tasks/gitlab/shell_rake_spec.rb
@@ -11,6 +11,10 @@ describe 'gitlab:shell rake tasks' do
it 'invokes create_hooks task' do
expect(Rake::Task['gitlab:shell:create_hooks']).to receive(:invoke)
+ storages = Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
+ expect(Kernel).to receive(:system).with('bin/install', *storages).and_call_original
+ expect(Kernel).to receive(:system).with('bin/compile').and_call_original
+
run_rake_task('gitlab:shell:install')
end
end
diff --git a/spec/uploaders/personal_file_uploader_spec.rb b/spec/uploaders/personal_file_uploader_spec.rb
new file mode 100644
index 00000000000..fb92f2ae3ab
--- /dev/null
+++ b/spec/uploaders/personal_file_uploader_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe PersonalFileUploader do
+ let(:uploader) { described_class.new(build_stubbed(:empty_project)) }
+ let(:snippet) { create(:personal_snippet) }
+
+ describe '.absolute_path' do
+ it 'returns the correct absolute path by building it dynamically' do
+ upload = double(model: snippet, path: 'secret/foo.jpg')
+
+ dynamic_segment = "personal_snippet/#{snippet.id}"
+
+ expect(described_class.absolute_path(upload)).to end_with("#{dynamic_segment}/secret/foo.jpg")
+ end
+ end
+
+ describe '#to_h' do
+ it 'returns the hass' do
+ uploader = described_class.new(snippet, 'secret')
+
+ allow(uploader).to receive(:file).and_return(double(extension: 'txt', filename: 'file_name'))
+ expected_url = "/uploads/personal_snippet/#{snippet.id}/secret/file_name"
+
+ expect(uploader.to_h).to eq(
+ alt: 'file_name',
+ url: expected_url,
+ markdown: "[file_name](#{expected_url})"
+ )
+ end
+ end
+end
diff --git a/spec/views/projects/tags/index.html.haml_spec.rb b/spec/views/projects/tags/index.html.haml_spec.rb
new file mode 100644
index 00000000000..33122365e9a
--- /dev/null
+++ b/spec/views/projects/tags/index.html.haml_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe 'projects/tags/index', :view do
+ let(:project) { create(:project) }
+
+ before do
+ assign(:project, project)
+ assign(:repository, project.repository)
+ assign(:tags, [])
+
+ allow(view).to receive(:current_ref).and_return('master')
+ allow(view).to receive(:can?).and_return(false)
+ end
+
+ it 'defaults sort dropdown toggle to last updated' do
+ render
+
+ expect(rendered).to have_button('Last updated')
+ end
+end