debian-mirror-gitlab/spec/requests/ide_controller_spec.rb

203 lines
6.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe IdeController do
2021-04-17 20:07:23 +05:30
let_it_be(:project) { create(:project, :public) }
let_it_be(:creator) { project.creator }
let_it_be(:other_user) { create(:user) }
let(:user) { creator }
2021-04-29 21:17:54 +05:30
let(:branch) { '' }
2019-10-12 21:52:04 +05:30
before do
sign_in(user)
end
it 'increases the views counter' do
expect(Gitlab::UsageDataCounters::WebIdeCounter).to receive(:increment_views_count)
2021-02-22 17:27:13 +05:30
get ide_url
2019-10-12 21:52:04 +05:30
end
2021-04-17 20:07:23 +05:30
describe '#index', :aggregate_failures do
subject { get route }
shared_examples 'user cannot push code' do
include ProjectForksHelper
let(:user) { other_user }
context 'when user does not have fork' do
2021-04-29 21:17:54 +05:30
it 'instantiates fork_info instance var with fork_path and return 200' do
2021-04-17 20:07:23 +05:30
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to eq project
2021-04-29 21:17:54 +05:30
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
2021-04-17 20:07:23 +05:30
end
end
2021-04-29 21:17:54 +05:30
context 'when user has fork' do
let!(:fork) { fork_project(project, user, repository: true, namespace: user.namespace) }
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
it 'instantiates fork_info instance var with ide_path and return 200' do
2021-04-17 20:07:23 +05:30
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to eq project
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to eq({ ide_path: controller.helpers.ide_edit_path(fork, branch, '') })
2021-04-17 20:07:23 +05:30
end
end
end
context '/-/ide' do
let(:route) { '/-/ide' }
it 'does not instantiate any instance var and return 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to be_nil
expect(assigns(:branch)).to be_nil
expect(assigns(:path)).to be_nil
expect(assigns(:merge_request)).to be_nil
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
end
context '/-/ide/project' do
let(:route) { '/-/ide/project' }
it 'does not instantiate any instance var and return 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to be_nil
expect(assigns(:branch)).to be_nil
expect(assigns(:path)).to be_nil
expect(assigns(:merge_request)).to be_nil
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
end
context '/-/ide/project/:project' do
let(:route) { "/-/ide/project/#{project.full_path}" }
it 'instantiates project instance var and return 200' do
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-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
%w(edit blob tree).each do |action|
context "/-/ide/project/:project/#{action}" do
let(:route) { "/-/ide/project/#{project.full_path}/#{action}" }
it 'instantiates project instance var and return 200' do
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-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
context "/-/ide/project/:project/#{action}/:branch" do
2021-04-29 21:17:54 +05:30
let(:branch) { 'master' }
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}" }
2021-04-17 20:07:23 +05:30
it 'instantiates project and branch instance vars and return 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to eq project
2021-04-29 21:17:54 +05:30
expect(assigns(:branch)).to eq branch
2021-04-17 20:07:23 +05:30
expect(assigns(:path)).to be_nil
expect(assigns(:merge_request)).to be_nil
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
context "/-/ide/project/:project/#{action}/:branch/-" do
2021-04-29 21:17:54 +05:30
let(:branch) { 'branch/slash' }
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}/-" }
2021-04-17 20:07:23 +05:30
it 'instantiates project and branch instance vars and return 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to eq project
2021-04-29 21:17:54 +05:30
expect(assigns(:branch)).to eq branch
2021-04-17 20:07:23 +05:30
expect(assigns(:path)).to be_nil
expect(assigns(:merge_request)).to be_nil
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
context "/-/ide/project/:project/#{action}/:branch/-/:path" do
2021-04-29 21:17:54 +05:30
let(:branch) { 'master' }
let(:route) { "/-/ide/project/#{project.full_path}/#{action}/#{branch}/-/foo/.bar" }
2021-04-17 20:07:23 +05:30
it 'instantiates project, branch, and path instance vars and return 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:project)).to eq project
2021-04-29 21:17:54 +05:30
expect(assigns(:branch)).to eq branch
2021-04-17 20:07:23 +05:30
expect(assigns(:path)).to eq 'foo/.bar'
expect(assigns(:merge_request)).to be_nil
2021-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
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}" }
it 'instantiates project and merge_request instance vars and return 200' do
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-04-29 21:17:54 +05:30
expect(assigns(:fork_info)).to be_nil
2021-04-17 20:07:23 +05:30
end
it_behaves_like 'user cannot push code'
end
end
end
2019-10-12 21:52:04 +05:30
end