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
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-04-17 06:07:56 +0300
committerShinya Maeda <shinya@gitlab.com>2018-04-17 06:07:56 +0300
commit23634e45678b13954fc00fd4e57425ff5cb559aa (patch)
tree636a39d3306c664d25df413f8e6c329fcf3a8fea /spec/controllers
parent76485cbf8ba555c929fd2f54ca2051a382760f20 (diff)
parentc39ad568e469b288a510c03b1aebefd78d8a9ee5 (diff)
Merge branch 'master' into live-trace-v2
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin/application_settings_controller_spec.rb5
-rw-r--r--spec/controllers/concerns/checks_collaboration_spec.rb55
-rw-r--r--spec/controllers/dashboard_controller_spec.rb2
-rw-r--r--spec/controllers/profiles_controller_spec.rb22
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb18
-rw-r--r--spec/controllers/projects/repositories_controller_spec.rb19
6 files changed, 114 insertions, 7 deletions
diff --git a/spec/controllers/admin/application_settings_controller_spec.rb b/spec/controllers/admin/application_settings_controller_spec.rb
index cc1b1e5039e..b4fc2aa326f 100644
--- a/spec/controllers/admin/application_settings_controller_spec.rb
+++ b/spec/controllers/admin/application_settings_controller_spec.rb
@@ -72,11 +72,10 @@ describe Admin::ApplicationSettingsController do
expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20])
end
- it 'falls back to defaults when settings are omitted' do
- put :update, application_setting: {}
+ it 'updates the restricted_visibility_levels when empty array is passed' do
+ put :update, application_setting: { restricted_visibility_levels: [] }
expect(response).to redirect_to(admin_application_settings_path)
- expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PRIVATE)
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end
end
diff --git a/spec/controllers/concerns/checks_collaboration_spec.rb b/spec/controllers/concerns/checks_collaboration_spec.rb
new file mode 100644
index 00000000000..1bd764290ae
--- /dev/null
+++ b/spec/controllers/concerns/checks_collaboration_spec.rb
@@ -0,0 +1,55 @@
+require 'spec_helper'
+
+describe ChecksCollaboration do
+ include ProjectForksHelper
+
+ let(:helper) do
+ fake_class = Class.new(ApplicationController) do
+ include ChecksCollaboration
+ end
+
+ fake_class.new
+ end
+
+ describe '#can_collaborate_with_project?' do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, :public) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+ allow(helper).to receive(:can?) do |user, ability, subject|
+ Ability.allowed?(user, ability, subject)
+ end
+ end
+
+ it 'is true if the user can push to the project' do
+ project.add_developer(user)
+
+ expect(helper.can_collaborate_with_project?(project)).to be_truthy
+ end
+
+ it 'is true when the user can push to a branch of the project' do
+ fake_access = double('Gitlab::UserAccess')
+ expect(fake_access).to receive(:can_push_to_branch?).with('a-branch').and_return(true)
+ expect(Gitlab::UserAccess).to receive(:new).with(user, project: project).and_return(fake_access)
+
+ expect(helper.can_collaborate_with_project?(project, ref: 'a-branch')).to be_truthy
+ end
+
+ context 'when the user has forked the project' do
+ before do
+ fork_project(project, user, namespace: user.namespace)
+ end
+
+ it 'is true' do
+ expect(helper.can_collaborate_with_project?(project)).to be_truthy
+ end
+
+ it 'is false when the project is archived' do
+ project.archived = true
+
+ expect(helper.can_collaborate_with_project?(project)).to be_falsy
+ end
+ end
+ end
+end
diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb
index 97c2c3fb940..3458d679107 100644
--- a/spec/controllers/dashboard_controller_spec.rb
+++ b/spec/controllers/dashboard_controller_spec.rb
@@ -11,9 +11,11 @@ describe DashboardController do
describe 'GET issues' do
it_behaves_like 'issuables list meta-data', :issue, :issues
+ it_behaves_like 'issuables requiring filter', :issues
end
describe 'GET merge requests' do
it_behaves_like 'issuables list meta-data', :merge_request, :merge_requests
+ it_behaves_like 'issuables requiring filter', :merge_requests
end
end
diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb
index 891485406c6..de6ef919221 100644
--- a/spec/controllers/profiles_controller_spec.rb
+++ b/spec/controllers/profiles_controller_spec.rb
@@ -84,6 +84,28 @@ describe ProfilesController, :request_store do
expect(user.username).to eq(new_username)
end
+ it 'updates a username using JSON request' do
+ sign_in(user)
+
+ put :update_username,
+ user: { username: new_username },
+ format: :json
+
+ expect(response.status).to eq(200)
+ expect(json_response['message']).to eq('Username successfully changed')
+ end
+
+ it 'renders an error message when the username was not updated' do
+ sign_in(user)
+
+ put :update_username,
+ user: { username: 'invalid username.git' },
+ format: :json
+
+ expect(response.status).to eq(422)
+ expect(json_response['message']).to match(/Username change failed/)
+ end
+
it 'raises a correct error when the username is missing' do
sign_in(user)
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 01b5506b64b..ca86b0bc737 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -938,7 +938,7 @@ describe Projects::IssuesController do
end
describe 'POST create_merge_request' do
- let(:project) { create(:project, :repository) }
+ let(:project) { create(:project, :repository, :public) }
before do
project.add_developer(user)
@@ -955,6 +955,22 @@ describe Projects::IssuesController do
expect(response).to match_response_schema('merge_request')
end
+ it 'is not available when the project is archived' do
+ project.update!(archived: true)
+
+ create_merge_request
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+
+ it 'is not available for users who cannot create merge requests' do
+ sign_in(create(:user))
+
+ create_merge_request
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+
def create_merge_request
post :create_merge_request, namespace_id: project.namespace.to_param,
project_id: project.to_param,
diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb
index 04d16e98913..c3b71458e38 100644
--- a/spec/controllers/projects/repositories_controller_spec.rb
+++ b/spec/controllers/projects/repositories_controller_spec.rb
@@ -6,7 +6,7 @@ describe Projects::RepositoriesController do
describe "GET archive" do
context 'as a guest' do
it 'responds with redirect in correct format' do
- get :archive, namespace_id: project.namespace, project_id: project, format: "zip", ref: 'master'
+ get :archive, namespace_id: project.namespace, project_id: project, id: "master", format: "zip"
expect(response.header["Content-Type"]).to start_with('text/html')
expect(response).to be_redirect
@@ -22,7 +22,20 @@ describe Projects::RepositoriesController do
end
it "uses Gitlab::Workhorse" do
- get :archive, namespace_id: project.namespace, project_id: project, ref: "master", format: "zip"
+ get :archive, namespace_id: project.namespace, project_id: project, id: "master", format: "zip"
+
+ expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
+ end
+
+ it 'responds with redirect to the short name archive if fully qualified' do
+ get :archive, namespace_id: project.namespace, project_id: project, id: "master/#{project.path}-master", format: "zip"
+
+ expect(assigns(:ref)).to eq("master")
+ expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
+ end
+
+ it 'handles legacy queries with no ref' do
+ get :archive, namespace_id: project.namespace, project_id: project, format: "zip"
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
@@ -33,7 +46,7 @@ describe Projects::RepositoriesController do
end
it "renders Not Found" do
- get :archive, namespace_id: project.namespace, project_id: project, ref: "master", format: "zip"
+ get :archive, namespace_id: project.namespace, project_id: project, id: "master", format: "zip"
expect(response).to have_gitlab_http_status(404)
end