summaryrefslogtreecommitdiff
path: root/spec/controllers/projects
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/projects')
-rw-r--r--spec/controllers/projects/blob_controller_spec.rb72
-rw-r--r--spec/controllers/projects/boards_controller_spec.rb8
-rw-r--r--spec/controllers/projects/branches_controller_spec.rb8
-rw-r--r--spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb52
-rw-r--r--spec/controllers/projects/ci/pipeline_editor_controller_spec.rb13
-rw-r--r--spec/controllers/projects/commit_controller_spec.rb26
-rw-r--r--spec/controllers/projects/compare_controller_spec.rb243
-rw-r--r--spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb15
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb21
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb15
-rw-r--r--spec/controllers/projects/notes_controller_spec.rb50
-rw-r--r--spec/controllers/projects/security/configuration_controller_spec.rb36
-rw-r--r--spec/controllers/projects/snippets_controller_spec.rb6
-rw-r--r--spec/controllers/projects/templates_controller_spec.rb27
-rw-r--r--spec/controllers/projects/web_ide_schemas_controller_spec.rb4
15 files changed, 325 insertions, 271 deletions
diff --git a/spec/controllers/projects/blob_controller_spec.rb b/spec/controllers/projects/blob_controller_spec.rb
index 68551ce4858..c9a76049e19 100644
--- a/spec/controllers/projects/blob_controller_spec.rb
+++ b/spec/controllers/projects/blob_controller_spec.rb
@@ -20,8 +20,8 @@ RSpec.describe Projects::BlobController do
project.add_maintainer(user)
sign_in(user)
- stub_experiment(ci_syntax_templates: experiment_active)
- stub_experiment_for_subject(ci_syntax_templates: in_experiment_group)
+ stub_experiment(ci_syntax_templates_b: experiment_active)
+ stub_experiment_for_subject(ci_syntax_templates_b: in_experiment_group)
end
context 'when the experiment is not active' do
@@ -35,48 +35,62 @@ RSpec.describe Projects::BlobController do
end
end
- context 'when the experiment is active and the user is in the control group' do
+ context 'when the experiment is active' do
let(:experiment_active) { true }
- let(:in_experiment_group) { false }
-
- it 'records the experiment user in the control group' do
- expect(Experiment).to receive(:add_user)
- .with(:ci_syntax_templates, :control, user, namespace_id: project.namespace_id)
- request
- end
- end
+ context 'when the user is in the control group' do
+ let(:in_experiment_group) { false }
- context 'when the experiment is active and the user is in the experimental group' do
- let(:experiment_active) { true }
- let(:in_experiment_group) { true }
-
- it 'records the experiment user in the experimental group' do
- expect(Experiment).to receive(:add_user)
- .with(:ci_syntax_templates, :experimental, user, namespace_id: project.namespace_id)
+ it 'records the experiment user in the control group' do
+ expect(Experiment).to receive(:add_user)
+ .with(:ci_syntax_templates_b, :control, user, namespace_id: project.namespace_id)
- request
+ request
+ end
end
- context 'when requesting a non default config file type' do
- let(:file_name) { '.non_default_ci_config' }
- let(:project) { create(:project, :public, :repository, ci_config_path: file_name) }
+ context 'when the user is in the experimental group' do
+ let(:in_experiment_group) { true }
it 'records the experiment user in the experimental group' do
expect(Experiment).to receive(:add_user)
- .with(:ci_syntax_templates, :experimental, user, namespace_id: project.namespace_id)
+ .with(:ci_syntax_templates_b, :experimental, user, namespace_id: project.namespace_id)
request
end
- end
- context 'when requesting a different file type' do
- let(:file_name) { '.gitignore' }
+ context 'when requesting a non default config file type' do
+ let(:file_name) { '.non_default_ci_config' }
+ let(:project) { create(:project, :public, :repository, ci_config_path: file_name) }
- it 'does not record the experiment user' do
- expect(Experiment).not_to receive(:add_user)
+ it 'records the experiment user in the experimental group' do
+ expect(Experiment).to receive(:add_user)
+ .with(:ci_syntax_templates_b, :experimental, user, namespace_id: project.namespace_id)
- request
+ request
+ end
+ end
+
+ context 'when requesting a different file type' do
+ let(:file_name) { '.gitignore' }
+
+ it 'does not record the experiment user' do
+ expect(Experiment).not_to receive(:add_user)
+
+ request
+ end
+ end
+
+ context 'when the group is created longer than 90 days ago' do
+ before do
+ project.namespace.update_attribute(:created_at, 91.days.ago)
+ end
+
+ it 'does not record the experiment user' do
+ expect(Experiment).not_to receive(:add_user)
+
+ request
+ end
end
end
end
diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb
index 1ed61e0990f..cde3a8d4761 100644
--- a/spec/controllers/projects/boards_controller_spec.rb
+++ b/spec/controllers/projects/boards_controller_spec.rb
@@ -34,7 +34,7 @@ RSpec.describe Projects::BoardsController do
before do
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
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)
+ allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
end
it 'returns a not found 404 response' do
@@ -78,7 +78,7 @@ RSpec.describe Projects::BoardsController do
before do
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
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)
+ allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
end
it 'returns a not found 404 response' do
@@ -134,7 +134,7 @@ RSpec.describe Projects::BoardsController do
before do
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
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)
+ allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
end
it 'returns a not found 404 response' do
@@ -172,7 +172,7 @@ RSpec.describe Projects::BoardsController do
before do
expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original
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)
+ allow(Ability).to receive(:allowed?).with(user, :read_issue_board, project).and_return(false)
end
it 'returns a not found 404 response' do
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb
index 14a5e7da7d2..a99db2664a7 100644
--- a/spec/controllers/projects/branches_controller_spec.rb
+++ b/spec/controllers/projects/branches_controller_spec.rb
@@ -648,7 +648,9 @@ RSpec.describe Projects::BranchesController do
end
it 'sets active and stale branches' do
- expect(assigns[:active_branches]).to eq([])
+ expect(assigns[:active_branches].map(&:name)).not_to include(
+ "feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"
+ )
expect(assigns[:stale_branches].map(&:name)).to eq(
["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"]
)
@@ -660,7 +662,9 @@ RSpec.describe Projects::BranchesController do
end
it 'sets active and stale branches' do
- expect(assigns[:active_branches]).to eq([])
+ expect(assigns[:active_branches].map(&:name)).not_to include(
+ "feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"
+ )
expect(assigns[:stale_branches].map(&:name)).to eq(
["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"]
)
diff --git a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
index 81318b49cd9..3c4376909f8 100644
--- a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
+++ b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
@@ -4,29 +4,25 @@ require 'spec_helper'
RSpec.describe Projects::Ci::DailyBuildGroupReportResultsController do
describe 'GET index' do
- let(:project) { create(:project, :public, :repository) }
- let(:ref_path) { 'refs/heads/master' }
- let(:param_type) { 'coverage' }
- let(:start_date) { '2019-12-10' }
- let(:end_date) { '2020-03-09' }
- let(:allowed_to_read) { true }
- let(:user) { create(:user) }
- let(:feature_enabled?) { true }
+ let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:ref_path) { 'refs/heads/master' }
+ let_it_be(:param_type) { 'coverage' }
+ let_it_be(:start_date) { '2019-12-10' }
+ let_it_be(:end_date) { '2020-03-09' }
+ let_it_be(:allowed_to_read) { true }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:rspec_coverage_1) { create_daily_coverage('rspec', 79.0, '2020-03-09') }
+ let_it_be(:rspec_coverage_2) { create_daily_coverage('rspec', 77.0, '2020-03-08') }
+ let_it_be(:karma_coverage) { create_daily_coverage('karma', 81.0, '2019-12-10') }
+ let_it_be(:minitest_coverage) { create_daily_coverage('minitest', 67.0, '2019-12-09') }
+ let_it_be(:mocha_coverage) { create_daily_coverage('mocha', 71.0, '2019-12-09') }
before do
- create_daily_coverage('rspec', 79.0, '2020-03-09')
- create_daily_coverage('rspec', 77.0, '2020-03-08')
- create_daily_coverage('karma', 81.0, '2019-12-10')
- create_daily_coverage('minitest', 67.0, '2019-12-09')
- create_daily_coverage('mocha', 71.0, '2019-12-09')
-
sign_in(user)
allow(Ability).to receive(:allowed?).and_call_original
allow(Ability).to receive(:allowed?).with(user, :read_build_report_results, project).and_return(allowed_to_read)
- stub_feature_flags(coverage_data_new_finder: feature_enabled?)
-
get :index, params: {
namespace_id: project.namespace,
project_id: project,
@@ -140,33 +136,13 @@ RSpec.describe Projects::Ci::DailyBuildGroupReportResultsController do
context 'when format is JSON' do
let(:format) { :json }
- context 'when coverage_data_new_finder flag is enabled' do
- let(:feature_enabled?) { true }
-
- it_behaves_like 'JSON results'
- end
-
- context 'when coverage_data_new_finder flag is disabled' do
- let(:feature_enabled?) { false }
-
- it_behaves_like 'JSON results'
- end
+ it_behaves_like 'JSON results'
end
context 'when format is CSV' do
let(:format) { :csv }
- context 'when coverage_data_new_finder flag is enabled' do
- let(:feature_enabled?) { true }
-
- it_behaves_like 'CSV results'
- end
-
- context 'when coverage_data_new_finder flag is disabled' do
- let(:feature_enabled?) { false }
-
- it_behaves_like 'CSV results'
- end
+ it_behaves_like 'CSV results'
end
end
diff --git a/spec/controllers/projects/ci/pipeline_editor_controller_spec.rb b/spec/controllers/projects/ci/pipeline_editor_controller_spec.rb
index 1bf6ff95c44..942402a6d00 100644
--- a/spec/controllers/projects/ci/pipeline_editor_controller_spec.rb
+++ b/spec/controllers/projects/ci/pipeline_editor_controller_spec.rb
@@ -36,18 +36,5 @@ RSpec.describe Projects::Ci::PipelineEditorController do
expect(response).to have_gitlab_http_status(:not_found)
end
end
-
- context 'when ci_pipeline_editor_page feature flag is disabled' do
- before do
- stub_feature_flags(ci_pipeline_editor_page: false)
- project.add_developer(user)
-
- get :show, params: { namespace_id: project.namespace, project_id: project }
- end
-
- it 'responds with 404' do
- expect(response).to have_gitlab_http_status(:not_found)
- end
- end
end
end
diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb
index 706bf787b2d..2d7f036be21 100644
--- a/spec/controllers/projects/commit_controller_spec.rb
+++ b/spec/controllers/projects/commit_controller_spec.rb
@@ -9,6 +9,8 @@ RSpec.describe Projects::CommitController do
let(:commit) { project.commit("master") }
let(:master_pickable_sha) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' }
let(:master_pickable_commit) { project.commit(master_pickable_sha) }
+ let(:pipeline) { create(:ci_pipeline, project: project, ref: project.default_branch, sha: commit.sha, status: :running) }
+ let(:build) { create(:ci_build, pipeline: pipeline, status: :running) }
before do
sign_in(user)
@@ -33,6 +35,19 @@ RSpec.describe Projects::CommitController do
expect(response).to be_ok
end
+
+ context 'when a pipeline job is running' do
+ before do
+ build.run
+ end
+
+ it 'defines last pipeline information' do
+ go(id: commit.id)
+
+ expect(assigns(:last_pipeline)).to have_attributes(id: pipeline.id, status: 'running')
+ expect(assigns(:last_pipeline_stages)).not_to be_empty
+ end
+ end
end
context 'with invalid id' do
@@ -363,15 +378,22 @@ RSpec.describe Projects::CommitController do
context 'when the commit exists' do
context 'when the commit has pipelines' do
before do
- create(:ci_pipeline, project: project, sha: commit.id)
+ build.run
end
context 'when rendering a HTML format' do
- it 'shows pipelines' do
+ before do
get_pipelines(id: commit.id)
+ end
+ it 'shows pipelines' do
expect(response).to be_ok
end
+
+ it 'defines last pipeline information' do
+ expect(assigns(:last_pipeline)).to have_attributes(id: pipeline.id, status: 'running')
+ expect(assigns(:last_pipeline_stages)).not_to be_empty
+ end
end
context 'when rendering a JSON format' do
diff --git a/spec/controllers/projects/compare_controller_spec.rb b/spec/controllers/projects/compare_controller_spec.rb
index 6aa4bfe235b..80a6d3960cd 100644
--- a/spec/controllers/projects/compare_controller_spec.rb
+++ b/spec/controllers/projects/compare_controller_spec.rb
@@ -3,8 +3,21 @@
require 'spec_helper'
RSpec.describe Projects::CompareController do
- let(:project) { create(:project, :repository) }
- let(:user) { create(:user) }
+ include ProjectForksHelper
+
+ using RSpec::Parameterized::TableSyntax
+
+ let_it_be(:project) { create(:project, :repository, :public) }
+ let_it_be(:user) { create(:user) }
+
+ let(:private_fork) { fork_project(project, nil, repository: true).tap { |fork| fork.update!(visibility: 'private') } }
+ let(:public_fork) do
+ fork_project(project, nil, repository: true).tap do |fork|
+ fork.update!(visibility: 'public')
+ # Create a reference that only exists in this project
+ fork.repository.create_ref('refs/heads/improve/awesome', 'refs/heads/improve/more-awesome')
+ end
+ end
before do
sign_in(user)
@@ -32,18 +45,20 @@ RSpec.describe Projects::CompareController do
{
namespace_id: project.namespace,
project_id: project,
- from: source_ref,
- to: target_ref,
+ from_project_id: from_project_id,
+ from: from_ref,
+ to: to_ref,
w: whitespace
}
end
let(:whitespace) { nil }
- context 'when the refs exist' do
+ context 'when the refs exist in the same project' do
context 'when we set the white space param' do
- let(:source_ref) { "08f22f25" }
- let(:target_ref) { "66eceea0" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { '08f22f25' }
+ let(:to_ref) { '66eceea0' }
let(:whitespace) { 1 }
it 'shows some diffs with ignore whitespace change option' do
@@ -60,8 +75,9 @@ RSpec.describe Projects::CompareController do
end
context 'when we do not set the white space param' do
- let(:source_ref) { "improve%2Fawesome" }
- let(:target_ref) { "feature" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { 'feature' }
let(:whitespace) { nil }
it 'sets the diffs and commits ivars' do
@@ -74,9 +90,40 @@ RSpec.describe Projects::CompareController do
end
end
+ context 'when the refs exist in different projects that the user can see' do
+ let(:from_project_id) { public_fork.id }
+ let(:from_ref) { 'improve%2Fmore-awesome' }
+ let(:to_ref) { 'feature' }
+ let(:whitespace) { nil }
+
+ it 'shows the diff' do
+ show_request
+
+ expect(response).to be_successful
+ expect(assigns(:diffs).diff_files.first).not_to be_nil
+ expect(assigns(:commits).length).to be >= 1
+ end
+ end
+
+ context 'when the refs exist in different projects but the user cannot see' do
+ let(:from_project_id) { private_fork.id }
+ let(:from_ref) { 'improve%2Fmore-awesome' }
+ let(:to_ref) { 'feature' }
+ let(:whitespace) { nil }
+
+ it 'does not show the diff' do
+ show_request
+
+ expect(response).to be_successful
+ expect(assigns(:diffs)).to be_empty
+ expect(assigns(:commits)).to be_empty
+ end
+ end
+
context 'when the source ref does not exist' do
- let(:source_ref) { 'non-existent-source-ref' }
- let(:target_ref) { "feature" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { 'non-existent-source-ref' }
+ let(:to_ref) { 'feature' }
it 'sets empty diff and commit ivars' do
show_request
@@ -88,8 +135,9 @@ RSpec.describe Projects::CompareController do
end
context 'when the target ref does not exist' do
- let(:target_ref) { 'non-existent-target-ref' }
- let(:source_ref) { "improve%2Fawesome" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { 'non-existent-target-ref' }
it 'sets empty diff and commit ivars' do
show_request
@@ -101,8 +149,9 @@ RSpec.describe Projects::CompareController do
end
context 'when the target ref is invalid' do
- let(:target_ref) { "master%' AND 2554=4423 AND '%'='" }
- let(:source_ref) { "improve%2Fawesome" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { "master%' AND 2554=4423 AND '%'='" }
it 'shows a flash message and redirects' do
show_request
@@ -113,8 +162,9 @@ RSpec.describe Projects::CompareController do
end
context 'when the source ref is invalid' do
- let(:source_ref) { "master%' AND 2554=4423 AND '%'='" }
- let(:target_ref) { "improve%2Fawesome" }
+ let(:from_project_id) { nil }
+ let(:from_ref) { "master%' AND 2554=4423 AND '%'='" }
+ let(:to_ref) { 'improve%2Fawesome' }
it 'shows a flash message and redirects' do
show_request
@@ -126,24 +176,33 @@ RSpec.describe Projects::CompareController do
end
describe 'GET diff_for_path' do
- def diff_for_path(extra_params = {})
- params = {
+ subject(:diff_for_path_request) { get :diff_for_path, params: request_params }
+
+ let(:request_params) do
+ {
+ from_project_id: from_project_id,
+ from: from_ref,
+ to: to_ref,
namespace_id: project.namespace,
- project_id: project
+ project_id: project,
+ old_path: old_path,
+ new_path: new_path
}
-
- get :diff_for_path, params: params.merge(extra_params)
end
let(:existing_path) { 'files/ruby/feature.rb' }
- let(:source_ref) { "improve%2Fawesome" }
- let(:target_ref) { "feature" }
- context 'when the source and target refs exist' do
+ let(:from_project_id) { nil }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { 'feature' }
+ let(:old_path) { existing_path }
+ let(:new_path) { existing_path }
+
+ context 'when the source and target refs exist in the same project' do
context 'when the user has access target the project' do
context 'when the path exists in the diff' do
it 'disables diff notes' do
- diff_for_path(from: source_ref, to: target_ref, old_path: existing_path, new_path: existing_path)
+ diff_for_path_request
expect(assigns(:diff_notes_disabled)).to be_truthy
end
@@ -154,16 +213,17 @@ RSpec.describe Projects::CompareController do
meth.call(diffs)
end
- diff_for_path(from: source_ref, to: target_ref, old_path: existing_path, new_path: existing_path)
+ diff_for_path_request
end
end
context 'when the path does not exist in the diff' do
- before do
- diff_for_path(from: source_ref, to: target_ref, old_path: existing_path.succ, new_path: existing_path.succ)
- end
+ let(:old_path) { existing_path.succ }
+ let(:new_path) { existing_path.succ }
it 'returns a 404' do
+ diff_for_path_request
+
expect(response).to have_gitlab_http_status(:not_found)
end
end
@@ -172,31 +232,56 @@ RSpec.describe Projects::CompareController do
context 'when the user does not have access target the project' do
before do
project.team.truncate
- diff_for_path(from: source_ref, to: target_ref, old_path: existing_path, new_path: existing_path)
end
it 'returns a 404' do
+ diff_for_path_request
+
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
- context 'when the source ref does not exist' do
- before do
- diff_for_path(from: source_ref.succ, to: target_ref, old_path: existing_path, new_path: existing_path)
+ context 'when the source and target refs exist in different projects and the user can see' do
+ let(:from_project_id) { public_fork.id }
+ let(:from_ref) { 'improve%2Fmore-awesome' }
+
+ it 'shows the diff for that path' do
+ expect(controller).to receive(:render_diff_for_path).and_wrap_original do |meth, diffs|
+ expect(diffs.diff_files.map(&:new_path)).to contain_exactly(existing_path)
+ meth.call(diffs)
+ end
+
+ diff_for_path_request
+ end
+ end
+
+ context 'when the source and target refs exist in different projects and the user cannot see' do
+ let(:from_project_id) { private_fork.id }
+
+ it 'does not show the diff for that path' do
+ diff_for_path_request
+
+ expect(response).to have_gitlab_http_status(:not_found)
end
+ end
+
+ context 'when the source ref does not exist' do
+ let(:from_ref) { 'this-ref-does-not-exist' }
it 'returns a 404' do
+ diff_for_path_request
+
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when the target ref does not exist' do
- before do
- diff_for_path(from: source_ref, to: target_ref.succ, old_path: existing_path, new_path: existing_path)
- end
+ let(:to_ref) { 'this-ref-does-not-exist' }
it 'returns a 404' do
+ diff_for_path_request
+
expect(response).to have_gitlab_http_status(:not_found)
end
end
@@ -209,53 +294,54 @@ RSpec.describe Projects::CompareController do
{
namespace_id: project.namespace,
project_id: project,
- from: source_ref,
- to: target_ref
+ from_project_id: from_project_id,
+ from: from_ref,
+ to: to_ref
}
end
context 'when sending valid params' do
- let(:source_ref) { "improve%2Fawesome" }
- let(:target_ref) { "feature" }
+ let(:from_ref) { 'awesome%2Ffeature' }
+ let(:to_ref) { 'feature' }
- it 'redirects back to show' do
- create_request
-
- expect(response).to redirect_to(project_compare_path(project, to: target_ref, from: source_ref))
- end
- end
+ context 'without a from_project_id' do
+ let(:from_project_id) { nil }
- context 'when sending invalid params' do
- context 'when the source ref is empty and target ref is set' do
- let(:source_ref) { '' }
- let(:target_ref) { 'master' }
-
- it 'redirects back to index and preserves the target ref' do
+ it 'redirects to the show page' do
create_request
- expect(response).to redirect_to(project_compare_index_path(project, to: target_ref))
+ expect(response).to redirect_to(project_compare_path(project, from: from_ref, to: to_ref))
end
end
- context 'when the target ref is empty and source ref is set' do
- let(:source_ref) { 'master' }
- let(:target_ref) { '' }
+ context 'with a from_project_id' do
+ let(:from_project_id) { 'something or another' }
- it 'redirects back to index and preserves source ref' do
+ it 'redirects to the show page without interpreting from_project_id' do
create_request
- expect(response).to redirect_to(project_compare_index_path(project, from: source_ref))
+ expect(response).to redirect_to(project_compare_path(project, from: from_ref, to: to_ref, from_project_id: from_project_id))
end
end
+ end
+
+ context 'when sending invalid params' do
+ where(:from_ref, :to_ref, :from_project_id, :expected_redirect_params) do
+ '' | '' | '' | {}
+ 'main' | '' | '' | { from: 'main' }
+ '' | 'main' | '' | { to: 'main' }
+ '' | '' | '1' | { from_project_id: 1 }
+ 'main' | '' | '1' | { from: 'main', from_project_id: 1 }
+ '' | 'main' | '1' | { to: 'main', from_project_id: 1 }
+ end
- context 'when the target and source ref are empty' do
- let(:source_ref) { '' }
- let(:target_ref) { '' }
+ with_them do
+ let(:expected_redirect) { project_compare_index_path(project, expected_redirect_params) }
- it 'redirects back to index' do
+ it 'redirects back to the index' do
create_request
- expect(response).to redirect_to(namespace_project_compare_index_path)
+ expect(response).to redirect_to(expected_redirect)
end
end
end
@@ -268,15 +354,15 @@ RSpec.describe Projects::CompareController do
{
namespace_id: project.namespace,
project_id: project,
- from: source_ref,
- to: target_ref,
+ from: from_ref,
+ to: to_ref,
format: :json
}
end
context 'when the source and target refs exist' do
- let(:source_ref) { "improve%2Fawesome" }
- let(:target_ref) { "feature" }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { 'feature' }
context 'when the user has access to the project' do
render_views
@@ -285,14 +371,14 @@ RSpec.describe Projects::CompareController do
let(:non_signature_commit) { build(:commit, project: project, safe_message: "message", sha: 'non_signature_commit') }
before do
- escaped_source_ref = Addressable::URI.unescape(source_ref)
- escaped_target_ref = Addressable::URI.unescape(target_ref)
+ escaped_from_ref = Addressable::URI.unescape(from_ref)
+ escaped_to_ref = Addressable::URI.unescape(to_ref)
- compare_service = CompareService.new(project, escaped_target_ref)
- compare = compare_service.execute(project, escaped_source_ref)
+ compare_service = CompareService.new(project, escaped_to_ref)
+ compare = compare_service.execute(project, escaped_from_ref)
- expect(CompareService).to receive(:new).with(project, escaped_target_ref).and_return(compare_service)
- expect(compare_service).to receive(:execute).with(project, escaped_source_ref).and_return(compare)
+ expect(CompareService).to receive(:new).with(project, escaped_to_ref).and_return(compare_service)
+ expect(compare_service).to receive(:execute).with(project, escaped_from_ref).and_return(compare)
expect(compare).to receive(:commits).and_return([signature_commit, non_signature_commit])
expect(non_signature_commit).to receive(:has_signature?).and_return(false)
@@ -313,6 +399,7 @@ RSpec.describe Projects::CompareController do
context 'when the user does not have access to the project' do
before do
project.team.truncate
+ project.update!(visibility: 'private')
end
it 'returns a 404' do
@@ -324,8 +411,8 @@ RSpec.describe Projects::CompareController do
end
context 'when the source ref does not exist' do
- let(:source_ref) { 'non-existent-ref-source' }
- let(:target_ref) { "feature" }
+ let(:from_ref) { 'non-existent-ref-source' }
+ let(:to_ref) { 'feature' }
it 'returns no signatures' do
signatures_request
@@ -336,8 +423,8 @@ RSpec.describe Projects::CompareController do
end
context 'when the target ref does not exist' do
- let(:target_ref) { 'non-existent-ref-target' }
- let(:source_ref) { "improve%2Fawesome" }
+ let(:from_ref) { 'improve%2Fawesome' }
+ let(:to_ref) { 'non-existent-ref-target' }
it 'returns no signatures' do
signatures_request
diff --git a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb
index f664604ac15..e0f86876f67 100644
--- a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb
+++ b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb
@@ -37,13 +37,24 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do
# For security, .svg images should only ever be served with Content-Disposition: attachment.
# If this specs ever fails we must assess whether we should be serving svg images.
# See https://gitlab.com/gitlab-org/gitlab/issues/12771
- it 'serves files with `Content-Disposition: attachment`' do
+ it 'serves files with `Content-Disposition` header set to attachment plus the filename' do
subject
- expect(response.header['Content-Disposition']).to eq('attachment')
+ expect(response.header['Content-Disposition']).to match "attachment; filename=\"#{design.filename}\""
expect(response).to have_gitlab_http_status(:ok)
end
+ context 'when the feature flag attachment_with_filename is disabled' do
+ it 'serves files with just `attachment` in the disposition header' do
+ stub_feature_flags(attachment_with_filename: false)
+
+ subject
+
+ expect(response.header['Content-Disposition']).to eq('attachment')
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+ end
+
it 'serves files with Workhorse' do
subject
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 81ffd2c4512..74062038248 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe Projects::IssuesController do
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user, reload: true) { create(:user) }
let(:issue) { create(:issue, project: project) }
+ let(:spam_action_response_fields) { { 'stub_spam_action_response_fields' => true } }
describe "GET #index" do
context 'external issue tracker' do
@@ -613,12 +614,15 @@ RSpec.describe Projects::IssuesController do
context 'when allow_possible_spam feature flag is false' do
before do
stub_feature_flags(allow_possible_spam: false)
+ expect(controller).to(receive(:spam_action_response_fields).with(issue)) do
+ spam_action_response_fields
+ end
end
- it 'renders json with recaptcha_html' do
+ it 'renders json with spam_action_response_fields' do
subject
- expect(json_response).to have_key('recaptcha_html')
+ expect(json_response).to eq(spam_action_response_fields)
end
end
@@ -948,12 +952,17 @@ RSpec.describe Projects::IssuesController do
context 'renders properly' do
render_views
- it 'renders recaptcha_html json response' do
+ before do
+ expect(controller).to(receive(:spam_action_response_fields).with(issue)) do
+ spam_action_response_fields
+ end
+ end
+
+ it 'renders spam_action_response_fields json response' do
update_issue
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response).to have_key('recaptcha_html')
- expect(json_response['recaptcha_html']).not_to be_empty
+ expect(response).to have_gitlab_http_status(:conflict)
+ expect(json_response).to eq(spam_action_response_fields)
end
end
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 9b37c46fd86..93d5e7eff6c 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -2048,21 +2048,6 @@ RSpec.describe Projects::MergeRequestsController do
end
end
- context 'with SELECT FOR UPDATE lock' do
- before do
- stub_feature_flags(merge_request_rebase_nowait_lock: false)
- end
-
- it 'executes rebase' do
- allow_any_instance_of(MergeRequest).to receive(:with_lock).with(true).and_call_original
- expect(RebaseWorker).to receive(:perform_async)
-
- post_rebase
-
- expect(response).to have_gitlab_http_status(:ok)
- end
- end
-
context 'with NOWAIT lock' do
it 'returns a 409' do
allow_any_instance_of(MergeRequest).to receive(:with_lock).with('FOR UPDATE NOWAIT').and_raise(ActiveRecord::LockWaitTimeout)
diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb
index edebaf294c4..add249e2c74 100644
--- a/spec/controllers/projects/notes_controller_spec.rb
+++ b/spec/controllers/projects/notes_controller_spec.rb
@@ -150,7 +150,7 @@ RSpec.describe Projects::NotesController do
end
it 'returns an empty page of notes' do
- expect(Gitlab::EtagCaching::Middleware).to receive(:skip!)
+ expect(Gitlab::EtagCaching::Middleware).not_to receive(:skip!)
request.headers['X-Last-Fetched-At'] = microseconds(Time.zone.now)
@@ -169,8 +169,6 @@ RSpec.describe Projects::NotesController do
end
it 'returns all notes' do
- expect(Gitlab::EtagCaching::Middleware).to receive(:skip!)
-
get :index, params: request_params
expect(json_response['notes'].count).to eq((page_1 + page_2 + page_3).size + 1)
@@ -764,49 +762,9 @@ RSpec.describe Projects::NotesController do
end
end
- context 'when the endpoint receives requests above the limit' do
- before do
- stub_application_setting(notes_create_limit: 3)
- end
-
- it 'prevents from creating more notes', :request_store do
- 3.times { create! }
-
- expect { create! }
- .to change { Gitlab::GitalyClient.get_request_count }.by(0)
-
- create!
- expect(response.body).to eq(_('This endpoint has been requested too many times. Try again later.'))
- expect(response).to have_gitlab_http_status(:too_many_requests)
- end
-
- it 'logs the event in auth.log' do
- attributes = {
- message: 'Application_Rate_Limiter_Request',
- env: :notes_create_request_limit,
- remote_ip: '0.0.0.0',
- request_method: 'POST',
- path: "/#{project.full_path}/notes",
- user_id: user.id,
- username: user.username
- }
-
- expect(Gitlab::AuthLogger).to receive(:error).with(attributes).once
-
- project.add_developer(user)
- sign_in(user)
-
- 4.times { create! }
- end
-
- it 'allows user in allow-list to create notes, even if the case is different' do
- user.update_attribute(:username, user.username.titleize)
- stub_application_setting(notes_create_limit_allowlist: ["#{user.username.downcase}"])
- 3.times { create! }
-
- create!
- expect(response).to have_gitlab_http_status(:found)
- end
+ it_behaves_like 'request exceeding rate limit', :clean_gitlab_redis_cache do
+ let(:params) { request_params.except(:format) }
+ let(:request_full_path) { project_notes_path(project) }
end
end
diff --git a/spec/controllers/projects/security/configuration_controller_spec.rb b/spec/controllers/projects/security/configuration_controller_spec.rb
index ef255d1efd0..848db16fb02 100644
--- a/spec/controllers/projects/security/configuration_controller_spec.rb
+++ b/spec/controllers/projects/security/configuration_controller_spec.rb
@@ -13,42 +13,28 @@ RSpec.describe Projects::Security::ConfigurationController do
end
describe 'GET show' do
- context 'when feature flag is disabled' do
+ context 'when user has guest access' do
before do
- stub_feature_flags(secure_security_and_compliance_configuration_page_on_ce: false)
+ project.add_guest(user)
end
- it 'renders not found' do
+ it 'denies access' do
get :show, params: { namespace_id: project.namespace, project_id: project }
- expect(response).to have_gitlab_http_status(:not_found)
+ expect(response).to have_gitlab_http_status(:forbidden)
end
end
- context 'when feature flag is enabled' do
- context 'when user has guest access' do
- before do
- project.add_guest(user)
- end
-
- it 'denies access' do
- get :show, params: { namespace_id: project.namespace, project_id: project }
-
- expect(response).to have_gitlab_http_status(:forbidden)
- end
+ context 'when user has developer access' do
+ before do
+ project.add_developer(user)
end
- context 'when user has developer access' do
- before do
- project.add_developer(user)
- end
-
- it 'grants access' do
- get :show, params: { namespace_id: project.namespace, project_id: project }
+ it 'grants access' do
+ get :show, params: { namespace_id: project.namespace, project_id: project }
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to render_template(:show)
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:show)
end
end
end
diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb
index f9221c5a4ef..793ffbbfad9 100644
--- a/spec/controllers/projects/snippets_controller_spec.rb
+++ b/spec/controllers/projects/snippets_controller_spec.rb
@@ -207,14 +207,14 @@ RSpec.describe Projects::SnippetsController do
subject
expect(assigns(:snippet)).to eq(project_snippet)
- expect(assigns(:blobs)).to eq(project_snippet.blobs)
+ expect(assigns(:blobs).map(&:name)).to eq(project_snippet.blobs.map(&:name))
expect(response).to have_gitlab_http_status(:ok)
end
it 'does not show the blobs expanded by default' do
subject
- expect(project_snippet.blobs.map(&:expanded?)).to be_all(false)
+ expect(assigns(:blobs).map(&:expanded?)).to be_all(false)
end
context 'when param expanded is set' do
@@ -223,7 +223,7 @@ RSpec.describe Projects::SnippetsController do
it 'shows all blobs expanded' do
subject
- expect(project_snippet.blobs.map(&:expanded?)).to be_all(true)
+ expect(assigns(:blobs).map(&:expanded?)).to be_all(true)
end
end
end
diff --git a/spec/controllers/projects/templates_controller_spec.rb b/spec/controllers/projects/templates_controller_spec.rb
index fe282baf769..bd299efb5b5 100644
--- a/spec/controllers/projects/templates_controller_spec.rb
+++ b/spec/controllers/projects/templates_controller_spec.rb
@@ -160,13 +160,28 @@ RSpec.describe Projects::TemplatesController do
end
shared_examples 'template names request' do
- it 'returns the template names' do
- get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json)
+ context 'when feature flag enabled' do
+ it 'returns the template names', :aggregate_failures do
+ get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json)
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response.size).to eq(2)
- expect(json_response.size).to eq(2)
- expect(json_response.map { |x| x.slice('name') }).to match(expected_template_names)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['Project Templates'].size).to eq(2)
+ expect(json_response['Project Templates'].map { |x| x.slice('name') }).to match(expected_template_names)
+ end
+ end
+
+ context 'when feature flag disabled' do
+ before do
+ stub_feature_flags(inherited_issuable_templates: false)
+ end
+
+ it 'returns the template names', :aggregate_failures do
+ get(:names, params: { namespace_id: project.namespace, template_type: template_type, project_id: project }, format: :json)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.size).to eq(2)
+ expect(json_response.map { |x| x.slice('name') }).to match(expected_template_names)
+ end
end
it 'fails for user with no access' do
diff --git a/spec/controllers/projects/web_ide_schemas_controller_spec.rb b/spec/controllers/projects/web_ide_schemas_controller_spec.rb
index fbec941aecc..136edd2f7ad 100644
--- a/spec/controllers/projects/web_ide_schemas_controller_spec.rb
+++ b/spec/controllers/projects/web_ide_schemas_controller_spec.rb
@@ -53,13 +53,13 @@ RSpec.describe Projects::WebIdeSchemasController do
end
context 'when an error occurs parsing the schema' do
- let(:result) { { status: :error, message: 'Some error occured' } }
+ let(:result) { { status: :error, message: 'Some error occurred' } }
it 'returns 422 with the error' do
subject
expect(response).to have_gitlab_http_status(:unprocessable_entity)
- expect(response.body).to eq('{"status":"error","message":"Some error occured"}')
+ expect(response.body).to eq('{"status":"error","message":"Some error occurred"}')
end
end
end