2019-07-19 07:11:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe IdeController do
|
2021-07-01 17:08:38 -04:00
|
|
|
let_it_be(:reporter) { create(:user) }
|
|
|
|
|
|
|
|
let_it_be(:project) do
|
|
|
|
create(:project, :private).tap do |p|
|
|
|
|
p.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-05 10:09:12 -05:00
|
|
|
let_it_be(:creator) { project.creator }
|
|
|
|
let_it_be(:other_user) { create(:user) }
|
|
|
|
|
|
|
|
let(:user) { creator }
|
2021-03-22 20:09:09 -04:00
|
|
|
let(:branch) { '' }
|
2019-07-19 07:11:27 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2021-03-05 10:09:12 -05:00
|
|
|
describe '#index', :aggregate_failures do
|
|
|
|
subject { get route }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
shared_examples 'user access rights check' do
|
|
|
|
context 'user can read project' do
|
|
|
|
it 'increases the views counter' do
|
|
|
|
expect(Gitlab::UsageDataCounters::WebIdeCounter).to receive(:increment_views_count)
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
subject
|
2021-03-22 20:09:09 -04:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
context 'user can read project but cannot push code' do
|
|
|
|
include ProjectForksHelper
|
2021-03-22 20:09:09 -04:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
let(:user) { reporter }
|
2021-03-22 20:09:09 -04:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
context 'when user does not have fork' do
|
|
|
|
it 'instantiates fork_info instance var with fork_path and returns 200' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
|
|
|
expect(assigns(:fork_info)).to eq({ fork_path: controller.helpers.ide_fork_and_edit_path(project, branch, '', with_notice: false) })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has nil fork_info if user cannot fork' do
|
|
|
|
project.project_feature.update!(forking_access_level: ProjectFeature::DISABLED)
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:fork_info)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has fork' do
|
|
|
|
let!(:fork) { fork_project(project, user, repository: true, namespace: user.namespace) }
|
|
|
|
|
|
|
|
it 'instantiates fork_info instance var with ide_path and returns 200' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
|
|
|
expect(assigns(:fork_info)).to eq({ ide_path: controller.helpers.ide_edit_path(fork, branch, '') })
|
|
|
|
end
|
|
|
|
end
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
context 'user cannot read project' do
|
|
|
|
let(:user) { other_user }
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'returns 404' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '/-/ide' do
|
|
|
|
let(:route) { '/-/ide' }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'returns 404' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '/-/ide/project' do
|
|
|
|
let(:route) { '/-/ide/project' }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'returns 404' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '/-/ide/project/:project' do
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}" }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project instance var and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
|
|
|
expect(assigns(:branch)).to be_nil
|
|
|
|
expect(assigns(:path)).to be_nil
|
|
|
|
expect(assigns(:merge_request)).to be_nil
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
%w(edit blob tree).each do |action|
|
|
|
|
context "/-/ide/project/:project/#{action}" do
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}/#{action}" }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project instance var and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
|
|
|
expect(assigns(:branch)).to be_nil
|
|
|
|
expect(assigns(:path)).to be_nil
|
|
|
|
expect(assigns(:merge_request)).to be_nil
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
context "/-/ide/project/:project/#{action}/:branch" do
|
2021-03-22 20:09:09 -04:00
|
|
|
let(:branch) { 'master' }
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}" }
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project and branch instance vars and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:branch)).to eq branch
|
2021-03-05 10:09:12 -05:00
|
|
|
expect(assigns(:path)).to be_nil
|
|
|
|
expect(assigns(:merge_request)).to be_nil
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
context "/-/ide/project/:project/#{action}/:branch/-" do
|
2021-03-22 20:09:09 -04:00
|
|
|
let(:branch) { 'branch/slash' }
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}/-" }
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project and branch instance vars and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:branch)).to eq branch
|
2021-03-05 10:09:12 -05:00
|
|
|
expect(assigns(:path)).to be_nil
|
|
|
|
expect(assigns(:merge_request)).to be_nil
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
context "/-/ide/project/:project/#{action}/:branch/-/:path" do
|
2021-03-22 20:09:09 -04:00
|
|
|
let(:branch) { 'master' }
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}/-/foo/.bar" }
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project, branch, and path instance vars and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:branch)).to eq branch
|
2021-03-05 10:09:12 -05:00
|
|
|
expect(assigns(:path)).to eq 'foo/.bar'
|
|
|
|
expect(assigns(:merge_request)).to be_nil
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context '/-/ide/project/:project/merge_requests/:merge_request_id' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
|
|
|
|
|
|
|
let(:route) { "/-/ide/project/#{project.full_path}/merge_requests/#{merge_request.id}" }
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'instantiates project and merge_request instance vars and returns 200' do
|
2021-03-05 10:09:12 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:project)).to eq project
|
|
|
|
expect(assigns(:branch)).to be_nil
|
|
|
|
expect(assigns(:path)).to be_nil
|
|
|
|
expect(assigns(:merge_request)).to eq merge_request.id.to_s
|
2021-03-22 20:09:09 -04:00
|
|
|
expect(assigns(:fork_info)).to be_nil
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it_behaves_like 'user access rights check'
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
2022-06-07 05:09:00 -04:00
|
|
|
|
|
|
|
describe 'Snowplow view event', :snowplow do
|
|
|
|
it 'is tracked' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect_snowplow_event(
|
|
|
|
category: described_class.to_s,
|
|
|
|
action: 'web_ide_views',
|
|
|
|
namespace: project.namespace,
|
|
|
|
user: user
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when route_hll_to_snowplow_phase2 FF is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(route_hll_to_snowplow_phase2: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not track Snowplow event' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect_no_snowplow_event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
2019-07-19 07:11:27 -04:00
|
|
|
end
|