summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-30 15:09:15 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-30 15:09:15 +0000
commit536aa3a1f4b96abc4ca34489bf2cbe503afcded7 (patch)
tree88d08f7dfa29a32d6526773c4fe0fefd9f2bc7d1 /spec
parent50ae4065530c4eafbeb7c5ff2c462c48c02947ca (diff)
downloadgitlab-ce-536aa3a1f4b96abc4ca34489bf2cbe503afcded7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/spam_logs_controller_spec.rb2
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb12
-rw-r--r--spec/controllers/projects/snippets_controller_spec.rb6
-rw-r--r--spec/controllers/snippets_controller_spec.rb6
-rw-r--r--spec/features/projects/serverless/functions_spec.rb5
-rw-r--r--spec/finders/projects/serverless/functions_finder_spec.rb66
-rw-r--r--spec/lib/gitlab/database/subquery_spec.rb17
-rw-r--r--spec/requests/api/issues/post_projects_issues_spec.rb2
-rw-r--r--spec/requests/api/issues/put_projects_issues_spec.rb2
-rw-r--r--spec/requests/api/merge_requests_spec.rb6
-rw-r--r--spec/requests/api/project_snippets_spec.rb4
-rw-r--r--spec/requests/api/snippets_spec.rb4
-rw-r--r--spec/services/issues/create_service_spec.rb6
-rw-r--r--spec/services/notes/update_service_spec.rb6
-rw-r--r--spec/services/snippets/create_service_spec.rb2
-rw-r--r--spec/services/spam/akismet_service_spec.rb (renamed from spec/services/akismet_service_spec.rb)2
-rw-r--r--spec/services/spam/spam_check_service_spec.rb6
-rw-r--r--spec/support/helpers/kubernetes_helpers.rb13
18 files changed, 120 insertions, 47 deletions
diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb
index baf4216dcde..15fb57d5add 100644
--- a/spec/controllers/admin/spam_logs_controller_spec.rb
+++ b/spec/controllers/admin/spam_logs_controller_spec.rb
@@ -39,7 +39,7 @@ describe Admin::SpamLogsController do
describe '#mark_as_ham' do
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:submit_ham).and_return(true)
end
end
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index e2ffc595c44..e5ca2226111 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -422,7 +422,7 @@ describe Projects::IssuesController do
context 'when Akismet is enabled and the issue is identified as spam' do
before do
stub_application_setting(recaptcha_enabled: true)
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
@@ -702,7 +702,7 @@ describe Projects::IssuesController do
context 'when an issue is not identified as spam' do
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: false)
end
end
@@ -715,7 +715,7 @@ describe Projects::IssuesController do
context 'when an issue is identified as spam' do
context 'when captcha is not verified' do
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
@@ -954,7 +954,7 @@ describe Projects::IssuesController do
before do
stub_feature_flags(allow_possible_spam: false)
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: false)
end
end
@@ -971,7 +971,7 @@ describe Projects::IssuesController do
end
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
@@ -1096,7 +1096,7 @@ describe Projects::IssuesController do
describe 'POST #mark_as_spam' do
context 'properly submits to Akismet' do
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(submit_spam: true)
end
expect_next_instance_of(ApplicationSetting) do |setting|
diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb
index 8233c0a0adb..0a8aa60ee02 100644
--- a/spec/controllers/projects/snippets_controller_spec.rb
+++ b/spec/controllers/projects/snippets_controller_spec.rb
@@ -92,7 +92,7 @@ describe Projects::SnippetsController do
context 'when the snippet is spam' do
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -172,7 +172,7 @@ describe Projects::SnippetsController do
context 'when the snippet is spam' do
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -282,7 +282,7 @@ describe Projects::SnippetsController do
let(:snippet) { create(:project_snippet, :private, project: project, author: user) }
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive_messages(submit_spam: true)
end
stub_application_setting(akismet_enabled: true)
diff --git a/spec/controllers/snippets_controller_spec.rb b/spec/controllers/snippets_controller_spec.rb
index f8fc9a72e00..daa560649f0 100644
--- a/spec/controllers/snippets_controller_spec.rb
+++ b/spec/controllers/snippets_controller_spec.rb
@@ -275,7 +275,7 @@ describe SnippetsController do
context 'when the snippet is spam' do
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -349,7 +349,7 @@ describe SnippetsController do
context 'when the snippet is spam' do
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -459,7 +459,7 @@ describe SnippetsController do
let(:snippet) { create(:personal_snippet, :public, author: user) }
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive_messages(submit_spam: true)
end
stub_application_setting(akismet_enabled: true)
diff --git a/spec/features/projects/serverless/functions_spec.rb b/spec/features/projects/serverless/functions_spec.rb
index c661ceb8eda..e494a0e9626 100644
--- a/spec/features/projects/serverless/functions_spec.rb
+++ b/spec/features/projects/serverless/functions_spec.rb
@@ -16,7 +16,12 @@ describe 'Functions', :js do
shared_examples "it's missing knative installation" do
before do
+ functions_finder = Projects::Serverless::FunctionsFinder.new(project)
visit project_serverless_functions_path(project)
+ allow(Projects::Serverless::FunctionsFinder)
+ .to receive(:new)
+ .and_return(functions_finder)
+ synchronous_reactive_cache(functions_finder)
end
it 'sees an empty state require Knative installation' do
diff --git a/spec/finders/projects/serverless/functions_finder_spec.rb b/spec/finders/projects/serverless/functions_finder_spec.rb
index d5644daebab..67eda297b91 100644
--- a/spec/finders/projects/serverless/functions_finder_spec.rb
+++ b/spec/finders/projects/serverless/functions_finder_spec.rb
@@ -26,9 +26,69 @@ describe Projects::Serverless::FunctionsFinder do
project.add_maintainer(user)
end
- describe '#installed' do
- it 'when reactive_caching is still fetching data' do
- expect(described_class.new(project).knative_installed).to eq 'checking'
+ describe '#knative_installed' do
+ context 'when environment does not exist yet' do
+ shared_examples 'before first deployment' do
+ let(:service) { cluster.platform_kubernetes }
+ let(:deployment) { nil }
+
+ it 'returns true if Knative is installed on cluster' do
+ stub_kubeclient_discover_knative_found(service.api_url)
+ function_finder = described_class.new(project)
+ synchronous_reactive_cache(function_finder)
+
+ expect(function_finder.knative_installed).to be true
+ end
+
+ it 'returns false if Knative is not installed on cluster' do
+ stub_kubeclient_discover_knative_not_found(service.api_url)
+ function_finder = described_class.new(project)
+ synchronous_reactive_cache(function_finder)
+
+ expect(function_finder.knative_installed).to be false
+ end
+ end
+ context 'when project level cluster is present and enabled' do
+ it_behaves_like 'before first deployment' do
+ let(:cluster) { create(:cluster, :project, :provided_by_gcp, enabled: true) }
+ let(:project) { cluster.project }
+ end
+ end
+
+ context 'when group level cluster is present and enabled' do
+ it_behaves_like 'before first deployment' do
+ let(:cluster) { create(:cluster, :group, :provided_by_gcp, enabled: true) }
+ let(:project) { create(:project, group: cluster.groups.first) }
+ end
+ end
+
+ context 'when instance level cluster is present and enabled' do
+ it_behaves_like 'before first deployment' do
+ let(:project) { create(:project) }
+ let(:cluster) { create(:cluster, :instance, :provided_by_gcp, enabled: true) }
+ end
+ end
+
+ context 'when project level cluster is present, but disabled' do
+ let(:cluster) { create(:cluster, :project, :provided_by_gcp, enabled: false) }
+ let(:project) { cluster.project }
+ let(:service) { cluster.platform_kubernetes }
+ let(:deployment) { nil }
+
+ it 'returns false even if Knative is installed on cluster' do
+ stub_kubeclient_discover_knative_found(service.api_url)
+ function_finder = described_class.new(project)
+ synchronous_reactive_cache(function_finder)
+
+ expect(function_finder.knative_installed).to be false
+ end
+ end
+ end
+
+ context 'when reactive_caching is still fetching data' do
+ it 'returns "checking"' do
+ expect(described_class.new(project).knative_installed).to eq 'checking'
+ end
end
context 'when reactive_caching has finished' do
diff --git a/spec/lib/gitlab/database/subquery_spec.rb b/spec/lib/gitlab/database/subquery_spec.rb
deleted file mode 100644
index 70380e02f16..00000000000
--- a/spec/lib/gitlab/database/subquery_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Database::Subquery do
- describe '.self_join' do
- set(:project) { create(:project) }
-
- it 'allows you to delete_all rows with WHERE and LIMIT' do
- events = create_list(:event, 8, project: project)
-
- expect do
- described_class.self_join(Event.where('id < ?', events[5]).recent.limit(2)).delete_all
- end.to change { Event.count }.by(-2)
- end
- end
-end
diff --git a/spec/requests/api/issues/post_projects_issues_spec.rb b/spec/requests/api/issues/post_projects_issues_spec.rb
index 6597a3ab3ba..341d0e8ae6b 100644
--- a/spec/requests/api/issues/post_projects_issues_spec.rb
+++ b/spec/requests/api/issues/post_projects_issues_spec.rb
@@ -392,7 +392,7 @@ describe API::Issues do
expect_next_instance_of(Spam::SpamCheckService) do |spam_service|
expect(spam_service).to receive_messages(check_for_spam?: true)
end
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
diff --git a/spec/requests/api/issues/put_projects_issues_spec.rb b/spec/requests/api/issues/put_projects_issues_spec.rb
index e6fec2fa1fc..8e78aca59b2 100644
--- a/spec/requests/api/issues/put_projects_issues_spec.rb
+++ b/spec/requests/api/issues/put_projects_issues_spec.rb
@@ -197,7 +197,7 @@ describe API::Issues do
expect_next_instance_of(Spam::SpamCheckService) do |spam_service|
expect(spam_service).to receive_messages(check_for_spam?: true)
end
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 58ae4565582..33ac175e945 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -1069,10 +1069,16 @@ describe API::MergeRequests do
describe 'GET /projects/:id/merge_requests/:merge_request_iid/:context_commits' do
it 'returns a 200 when merge request is valid' do
+ context_commit = merge_request.context_commits.first
+
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user)
+
expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.context_commits.size)
+ expect(json_response.first['id']).to eq(context_commit.id)
+ expect(json_response.first['title']).to eq(context_commit.title)
end
it 'returns a 404 when merge_request_iid not found' do
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb
index bfb6f10efa3..ccbfe040fca 100644
--- a/spec/requests/api/project_snippets_spec.rb
+++ b/spec/requests/api/project_snippets_spec.rb
@@ -179,7 +179,7 @@ describe API::ProjectSnippets do
end
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -271,7 +271,7 @@ describe API::ProjectSnippets do
end
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb
index f32be7a8765..1749ec89bc1 100644
--- a/spec/requests/api/snippets_spec.rb
+++ b/spec/requests/api/snippets_spec.rb
@@ -238,7 +238,7 @@ describe API::Snippets do
end
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
@@ -327,7 +327,7 @@ describe API::Snippets do
end
before do
- allow_next_instance_of(AkismetService) do |instance|
+ allow_next_instance_of(Spam::AkismetService) do |instance|
allow(instance).to receive(:spam?).and_return(true)
end
end
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb
index 3246578c743..44d4cd70f9a 100644
--- a/spec/services/issues/create_service_spec.rb
+++ b/spec/services/issues/create_service_spec.rb
@@ -355,7 +355,7 @@ describe Issues::CreateService do
opts[:recaptcha_verified] = true
opts[:spam_log_id] = spam_logs.last.id
- expect(AkismetService).not_to receive(:new)
+ expect(Spam::AkismetService).not_to receive(:new)
end
it 'does no mark an issue as a spam ' do
@@ -392,7 +392,7 @@ describe Issues::CreateService do
context 'when akismet detects spam' do
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
@@ -442,7 +442,7 @@ describe Issues::CreateService do
context 'when akismet does not detect spam' do
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: false)
end
end
diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb
index 73fcdd787aa..ab28e08ec83 100644
--- a/spec/services/notes/update_service_spec.rb
+++ b/spec/services/notes/update_service_spec.rb
@@ -30,6 +30,12 @@ describe Notes::UpdateService do
@note.reload
end
+ it 'does not update the note when params is blank' do
+ Timecop.freeze(1.day.from_now) do
+ expect { update_note({}) }.not_to change { note.reload.updated_at }
+ end
+ end
+
context 'suggestions' do
it 'refreshes note suggestions' do
markdown = <<-MARKDOWN.strip_heredoc
diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb
index 3ada50e80aa..7aa8f0ebf8f 100644
--- a/spec/services/snippets/create_service_spec.rb
+++ b/spec/services/snippets/create_service_spec.rb
@@ -99,7 +99,7 @@ describe Snippets::CreateService do
end
before do
- expect_next_instance_of(AkismetService) do |akismet_service|
+ expect_next_instance_of(Spam::AkismetService) do |akismet_service|
expect(akismet_service).to receive_messages(spam?: true)
end
end
diff --git a/spec/services/akismet_service_spec.rb b/spec/services/spam/akismet_service_spec.rb
index 355ff1611a0..a496cd1890e 100644
--- a/spec/services/akismet_service_spec.rb
+++ b/spec/services/spam/akismet_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe AkismetService do
+describe Spam::AkismetService do
let(:fake_akismet_client) { double(:akismet_client) }
let_it_be(:text) { "Would you like to buy some tinned meat product?" }
diff --git a/spec/services/spam/spam_check_service_spec.rb b/spec/services/spam/spam_check_service_spec.rb
index 5e06d14b8bc..732b64b52a0 100644
--- a/spec/services/spam/spam_check_service_spec.rb
+++ b/spec/services/spam/spam_check_service_spec.rb
@@ -85,7 +85,7 @@ describe Spam::SpamCheckService do
before do
issue.closed_at = Time.zone.now
- allow(AkismetService).to receive(:new).and_return(double(spam?: true))
+ allow(Spam::AkismetService).to receive(:new).and_return(double(spam?: true))
end
it 'returns false' do
@@ -105,7 +105,7 @@ describe Spam::SpamCheckService do
context 'when indicated as spam by akismet' do
before do
- allow(AkismetService).to receive(:new).and_return(double(spam?: true))
+ allow(Spam::AkismetService).to receive(:new).and_return(double(spam?: true))
end
context 'when allow_possible_spam feature flag is false' do
@@ -135,7 +135,7 @@ describe Spam::SpamCheckService do
context 'when not indicated as spam by akismet' do
before do
- allow(AkismetService).to receive(:new).and_return(double(spam?: false))
+ allow(Spam::AkismetService).to receive(:new).and_return(double(spam?: false))
end
it 'returns false' do
diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb
index 77acad31d62..8e5042e2ad3 100644
--- a/spec/support/helpers/kubernetes_helpers.rb
+++ b/spec/support/helpers/kubernetes_helpers.rb
@@ -60,6 +60,12 @@ module KubernetesHelpers
.to_return(status: [404, "Resource Not Found"])
end
+ def stub_kubeclient_discover_knative_found(api_url)
+ WebMock
+ .stub_request(:get, api_url + '/apis/serving.knative.dev/v1alpha1')
+ .to_return(kube_response(kube_knative_discovery_body))
+ end
+
def stub_kubeclient_service_pods(response = nil, options = {})
stub_kubeclient_discover(service.api_url)
@@ -288,6 +294,13 @@ module KubernetesHelpers
}
end
+ def kube_knative_discovery_body
+ {
+ "kind" => "APIResourceList",
+ "resources" => []
+ }
+ end
+
def kube_extensions_v1beta1_discovery_body
{
"kind" => "APIResourceList",