Commit 888559be authored by Paul Slaughter's avatar Paul Slaughter

Move ide_merge_request_path to routing_helper

- We'll create a follow up for handling the other ide_*
paths in blob
parent 7ef2f425
......@@ -32,19 +32,6 @@ module BlobHelper
File.join(segments)
end
def ide_merge_request_path(merge_request)
target_project = merge_request.target_project
source_project = merge_request.source_project
web_ide_path_base = File.join([ide_path, 'project', source_project.full_path, 'merge_requests', merge_request.iid.to_s])
if target_project != source_project
"#{web_ide_path_base}?#{{ target_project: target_project.full_path }.to_query}"
else
web_ide_path_base
end
end
def ide_fork_and_edit_path(project = @project, ref = @ref, path = @path, options = {})
if current_user
project_forks_path(project,
......
......@@ -343,6 +343,18 @@ module GitlabRoutingHelper
Gitlab::UrlBuilder.wiki_page_url(wiki, page, only_path: true, **options)
end
def gitlab_ide_merge_request_path(merge_request)
target_project = merge_request.target_project
source_project = merge_request.source_project
params = {}
if target_project != source_project
params = { target_project: target_project.full_path }
end
ide_merge_request_path(source_project.namespace, source_project, merge_request, params)
end
private
def snippet_query_params(snippet, *args)
......
......@@ -48,7 +48,7 @@ class DiffFileBaseEntity < Grape::Entity
next unless has_edit_path?(merge_request)
ide_merge_request_path(merge_request)
gitlab_ide_merge_request_path(merge_request)
end
expose :old_path_html do |diff_file|
......
......@@ -122,6 +122,7 @@ Rails.application.routes.draw do
get 'ide' => 'ide#index'
get 'ide/*vueroute' => 'ide#index', format: false
get 'ide/project/:namespace/:project/merge_requests/:id' => 'ide#index', format: false, as: :ide_merge_request
draw :operations
draw :jira_connect
......
......@@ -3,10 +3,24 @@
require 'spec_helper'
RSpec.describe DiffFileBaseEntity do
let(:project) { create(:project, :repository) }
include ProjectForksHelper
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:repository) { project.repository }
let(:entity) { described_class.new(diff_file, options).as_json }
shared_examples 'nil if removed source branch' do |key|
before do
allow(merge_request).to receive(:source_branch_exists?).and_return(false)
end
specify do
expect(entity[key]).to eq(nil)
end
end
context 'submodule information for a' do
let(:commit_sha) { "" }
let(:commit) { project.commit(commit_sha) }
......@@ -67,7 +81,7 @@ RSpec.describe DiffFileBaseEntity do
context 'edit_path' do
let(:diff_file) { merge_request.diffs.diff_files.to_a.last }
let(:options) { { request: EntityRequest.new(current_user: create(:user)), merge_request: merge_request } }
let(:options) { { request: EntityRequest.new(current_user: user), merge_request: merge_request } }
let(:params) { {} }
shared_examples 'a diff file edit path to the source branch' do
......@@ -81,16 +95,7 @@ RSpec.describe DiffFileBaseEntity do
let(:params) { { from_merge_request_iid: merge_request.iid } }
it_behaves_like 'a diff file edit path to the source branch'
context 'removed source branch' do
before do
allow(merge_request).to receive(:source_branch_exists?).and_return(false)
end
it do
expect(entity[:edit_path]).to eq(nil)
end
end
it_behaves_like 'nil if removed source branch', :edit_path
end
context 'closed' do
......@@ -118,4 +123,30 @@ RSpec.describe DiffFileBaseEntity do
end
end
end
context 'ide_edit_path' do
let(:source_project) { project }
let(:merge_request) { create(:merge_request, iid: 123, target_project: target_project, source_project: source_project) }
let(:diff_file) { merge_request.diffs.diff_files.to_a.last }
let(:options) { { request: EntityRequest.new(current_user: user), merge_request: merge_request } }
let(:expected_merge_request_path) { "/-/ide/project/#{source_project.full_path}/merge_requests/#{merge_request.iid}" }
context 'when source_project and target_project are the same' do
let(:target_project) { source_project }
it_behaves_like 'nil if removed source branch', :ide_edit_path
it 'returns the merge_request ide route' do
expect(entity[:ide_edit_path]).to eq expected_merge_request_path
end
end
context 'when source_project and target_project are different' do
let(:target_project) { fork_project(source_project, source_project.owner, repository: true) }
it 'returns the merge_request ide route with the target_project as param' do
expect(entity[:ide_edit_path]).to eq("#{expected_merge_request_path}?target_project=#{ERB::Util.url_encode(target_project.full_path)}")
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment