summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-05-29 19:20:40 +0000
committerRobert Speicher <robert@gitlab.com>2018-05-29 19:20:40 +0000
commitff575b782e53e42a85ebfe65a559864f45c848b1 (patch)
tree4b5deca3a45b26214cf29682ecdb900de8531a83
parent4aae86f6f71ab381de1d987a04d5e9c250cd2080 (diff)
parent9471c3f673abab7b3179c1dc2931a2c44aa1f3a2 (diff)
downloadgitlab-ce-ff575b782e53e42a85ebfe65a559864f45c848b1.tar.gz
Merge branch '6045-extract-ee-specific-specs-lines' into 'master'
[CE] Resolve "Extract EE specific files/lines for some controller specs" Closes #6045 See merge request gitlab-org/gitlab-ce!19089
-rw-r--r--app/controllers/projects/clusters_controller.rb13
-rw-r--r--app/controllers/projects/environments_controller.rb10
-rw-r--r--lib/gitlab/ee_compat_check.rb4
-rw-r--r--spec/controllers/boards/issues_controller_spec.rb2
-rw-r--r--spec/controllers/projects/boards_controller_spec.rb66
-rw-r--r--spec/controllers/projects/branches_controller_spec.rb18
-rw-r--r--spec/controllers/projects/clusters_controller_spec.rb9
-rw-r--r--spec/controllers/projects/environments_controller_spec.rb7
-rw-r--r--spec/controllers/projects/group_links_controller_spec.rb12
-rw-r--r--spec/controllers/projects/imports_controller_spec.rb18
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb2
-rw-r--r--spec/controllers/projects/project_members_controller_spec.rb2
12 files changed, 110 insertions, 53 deletions
diff --git a/app/controllers/projects/clusters_controller.rb b/app/controllers/projects/clusters_controller.rb
index aeaba3a0acf..d58039b7d42 100644
--- a/app/controllers/projects/clusters_controller.rb
+++ b/app/controllers/projects/clusters_controller.rb
@@ -71,19 +71,6 @@ class Projects::ClustersController < Projects::ApplicationController
.present(current_user: current_user)
end
- def create_params
- params.require(:cluster).permit(
- :enabled,
- :name,
- :provider_type,
- provider_gcp_attributes: [
- :gcp_project_id,
- :zone,
- :num_nodes,
- :machine_type
- ])
- end
-
def update_params
if cluster.managed?
params.require(:cluster).permit(
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb
index 52d528e816e..0821362f5df 100644
--- a/app/controllers/projects/environments_controller.rb
+++ b/app/controllers/projects/environments_controller.rb
@@ -7,6 +7,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize]
before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :metrics]
before_action :verify_api_request!, only: :terminal_websocket_authorize
+ before_action :expire_etag_cache, only: [:index]
def index
@environments = project.environments
@@ -148,6 +149,15 @@ class Projects::EnvironmentsController < Projects::ApplicationController
Gitlab::Workhorse.verify_api_request!(request.headers)
end
+ def expire_etag_cache
+ return if request.format.json?
+
+ # this forces to reload json content
+ Gitlab::EtagCaching::Store.new.tap do |store|
+ store.touch(project_environments_path(project, format: :json))
+ end
+ end
+
def environment_params
params.require(:environment).permit(:name, :external_url)
end
diff --git a/lib/gitlab/ee_compat_check.rb b/lib/gitlab/ee_compat_check.rb
index 8cf59fa8e28..8c72d00c1f3 100644
--- a/lib/gitlab/ee_compat_check.rb
+++ b/lib/gitlab/ee_compat_check.rb
@@ -138,8 +138,8 @@ module Gitlab
def ee_branch_presence_check!
ee_remotes.keys.each do |remote|
- [ee_branch_prefix, ee_branch_suffix].each do |branch|
- _, status = step("Fetching #{remote}/#{ee_branch_prefix}", %W[git fetch #{remote} #{branch}])
+ [ce_branch, ee_branch_prefix, ee_branch_suffix].each do |branch|
+ _, status = step("Fetching #{remote}/#{branch}", %W[git fetch #{remote} #{branch}])
if status.zero?
@ee_remote_with_branch = remote
diff --git a/spec/controllers/boards/issues_controller_spec.rb b/spec/controllers/boards/issues_controller_spec.rb
index 4770e187db6..dcb0faffbd4 100644
--- a/spec/controllers/boards/issues_controller_spec.rb
+++ b/spec/controllers/boards/issues_controller_spec.rb
@@ -17,7 +17,7 @@ describe Boards::IssuesController do
project.add_guest(guest)
end
- describe 'GET index' do
+ describe 'GET index', :request_store do
let(:johndoe) { create(:user, avatar: fixture_file_upload(File.join(Rails.root, 'spec/fixtures/dk.png'))) }
context 'with invalid board id' do
diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb
index 4d765229bde..509f19ed030 100644
--- a/spec/controllers/projects/boards_controller_spec.rb
+++ b/spec/controllers/projects/boards_controller_spec.rb
@@ -27,6 +27,20 @@ describe Projects::BoardsController do
expect(response).to render_template :index
expect(response.content_type).to eq 'text/html'
end
+
+ context 'with unauthorized user' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
+ allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
+ end
+
+ it 'returns a not found 404 response' do
+ list_boards
+
+ expect(response).to have_gitlab_http_status(404)
+ expect(response.content_type).to eq 'text/html'
+ end
+ end
end
context 'when format is JSON' do
@@ -40,18 +54,19 @@ describe Projects::BoardsController do
expect(response).to match_response_schema('boards')
expect(parsed_response.length).to eq 2
end
- end
- context 'with unauthorized user' do
- before do
- allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
- allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
- end
+ context 'with unauthorized user' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
+ allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
+ end
- it 'returns a not found 404 response' do
- list_boards
+ it 'returns a not found 404 response' do
+ list_boards format: :json
- expect(response).to have_gitlab_http_status(404)
+ expect(response).to have_gitlab_http_status(404)
+ expect(response.content_type).to eq 'application/json'
+ end
end
end
@@ -88,6 +103,20 @@ describe Projects::BoardsController do
expect(response).to render_template :show
expect(response.content_type).to eq 'text/html'
end
+
+ context 'with unauthorized user' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
+ allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
+ end
+
+ it 'returns a not found 404 response' do
+ read_board board: board
+
+ expect(response).to have_gitlab_http_status(404)
+ expect(response.content_type).to eq 'text/html'
+ end
+ end
end
context 'when format is JSON' do
@@ -96,18 +125,19 @@ describe Projects::BoardsController do
expect(response).to match_response_schema('board')
end
- end
- context 'with unauthorized user' do
- before do
- allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
- allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
- end
+ context 'with unauthorized user' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
+ allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false)
+ end
- it 'returns a not found 404 response' do
- read_board board: board
+ it 'returns a not found 404 response' do
+ read_board board: board, format: :json
- expect(response).to have_gitlab_http_status(404)
+ expect(response).to have_gitlab_http_status(404)
+ expect(response.content_type).to eq 'application/json'
+ end
end
end
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb
index 16fb377b002..4860ea5dcce 100644
--- a/spec/controllers/projects/branches_controller_spec.rb
+++ b/spec/controllers/projects/branches_controller_spec.rb
@@ -146,6 +146,24 @@ describe Projects::BranchesController do
it_behaves_like 'same behavior between KubernetesService and Platform::Kubernetes'
end
+
+ it 'redirects to autodeploy setup page' do
+ result = { status: :success, branch: double(name: branch) }
+
+ create(:cluster, :provided_by_gcp, projects: [project])
+
+ expect_any_instance_of(CreateBranchService).to receive(:execute).and_return(result)
+ expect(SystemNoteService).to receive(:new_issue_branch).and_return(true)
+
+ post :create,
+ namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ branch_name: branch,
+ issue_iid: issue.iid
+
+ expect(response.location).to include(project_new_blob_path(project, branch))
+ expect(response).to have_gitlab_http_status(302)
+ end
end
context 'when create branch service fails' do
diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb
index 82b20e12850..380e50c8cac 100644
--- a/spec/controllers/projects/clusters_controller_spec.rb
+++ b/spec/controllers/projects/clusters_controller_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
describe Projects::ClustersController do
include AccessMatchersForController
- include GoogleApi::CloudPlatformHelpers
set(:project) { create(:project) }
@@ -333,7 +332,7 @@ describe Projects::ClustersController do
context 'when cluster is provided by GCP' do
context 'when cluster is created' do
- let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
+ let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
it "destroys and redirects back to clusters list" do
expect { go }
@@ -347,7 +346,7 @@ describe Projects::ClustersController do
end
context 'when cluster is being created' do
- let!(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }
+ let!(:cluster) { create(:cluster, :providing_by_gcp, :production_environment, projects: [project]) }
it "destroys and redirects back to clusters list" do
expect { go }
@@ -361,7 +360,7 @@ describe Projects::ClustersController do
end
context 'when cluster is provided by user' do
- let!(:cluster) { create(:cluster, :provided_by_user, projects: [project]) }
+ let!(:cluster) { create(:cluster, :provided_by_user, :production_environment, projects: [project]) }
it "destroys and redirects back to clusters list" do
expect { go }
@@ -376,7 +375,7 @@ describe Projects::ClustersController do
end
describe 'security' do
- set(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
+ set(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
it { expect { go }.to be_allowed_for(:admin) }
it { expect { go }.to be_allowed_for(:owner).of(project) }
diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb
index ff9ab53d8c3..47d4942acbd 100644
--- a/spec/controllers/projects/environments_controller_spec.rb
+++ b/spec/controllers/projects/environments_controller_spec.rb
@@ -21,6 +21,13 @@ describe Projects::EnvironmentsController do
expect(response).to have_gitlab_http_status(:ok)
end
+
+ it 'expires etag cache to force reload environments list' do
+ expect_any_instance_of(Gitlab::EtagCaching::Store)
+ .to receive(:touch).with(project_environments_path(project, format: :json))
+
+ get :index, environment_params
+ end
end
context 'when requesting JSON response for folders' do
diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb
index 5bfc3d31401..72f6af112b3 100644
--- a/spec/controllers/projects/group_links_controller_spec.rb
+++ b/spec/controllers/projects/group_links_controller_spec.rb
@@ -21,6 +21,18 @@ describe Projects::GroupLinksController do
end
end
+ context 'when project is not allowed to be shared with a group' do
+ before do
+ group.update_attributes(share_with_group_lock: false)
+ end
+
+ include_context 'link project to group'
+
+ it 'responds with status 404' do
+ expect(response).to have_gitlab_http_status(404)
+ end
+ end
+
context 'when user has access to group he want to link project to' do
before do
group.add_developer(user)
diff --git a/spec/controllers/projects/imports_controller_spec.rb b/spec/controllers/projects/imports_controller_spec.rb
index 7fb4c1b7425..011843baffc 100644
--- a/spec/controllers/projects/imports_controller_spec.rb
+++ b/spec/controllers/projects/imports_controller_spec.rb
@@ -2,16 +2,15 @@ require 'spec_helper'
describe Projects::ImportsController do
let(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ before do
+ sign_in(user)
+ project.add_master(user)
+ end
describe 'GET #show' do
context 'when repository does not exists' do
- let(:project) { create(:project) }
-
- before do
- sign_in(user)
- project.add_master(user)
- end
-
it 'renders template' do
get :show, namespace_id: project.namespace.to_param, project_id: project
@@ -28,11 +27,6 @@ describe Projects::ImportsController do
context 'when repository exists' do
let(:project) { create(:project_empty_repo, import_url: 'https://github.com/vim/vim.git') }
- before do
- sign_in(user)
- project.add_master(user)
- end
-
context 'when import is in progress' do
before do
project.update_attribute(:import_status, :started)
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index ca86b0bc737..106611b37c9 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -1,4 +1,4 @@
-require('spec_helper')
+require 'spec_helper'
describe Projects::IssuesController do
let(:project) { create(:project) }
diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb
index 46b08a03b19..d84b31ad978 100644
--- a/spec/controllers/projects/project_members_controller_spec.rb
+++ b/spec/controllers/projects/project_members_controller_spec.rb
@@ -184,7 +184,7 @@ describe Projects::ProjectMembersController do
project.add_master(user)
end
- it 'cannot remove himself from the project' do
+ it 'cannot remove themselves from the project' do
delete :leave, namespace_id: project.namespace,
project_id: project