Commit 7b04b63e authored by Jacopo's avatar Jacopo Committed by jacopo-beschi-intersail

New directory from interface on existing branch

The user can create a new directory on a different branch than the
source branch when the branch already exists.
parent 0eff4f14
......@@ -89,4 +89,9 @@ class Projects::ApplicationController < ApplicationController
def builds_enabled
return render_404 unless @project.feature_available?(:builds, current_user)
end
def update_ref
branch_exists = @repository.find_branch(@target_branch)
@ref = @target_branch if branch_exists
end
end
......@@ -89,11 +89,6 @@ class Projects::BlobController < Projects::ApplicationController
private
def update_ref
branch_exists = @repository.find_branch(@target_branch)
@ref = @target_branch if branch_exists
end
def blob
@blob ||= Blob.decorate(@repository.blob_at(@commit.id, @path))
......
......@@ -34,6 +34,7 @@ class Projects::TreeController < Projects::ApplicationController
def create_dir
return render_404 unless @commit_params.values.all?
update_ref
create_commit(Files::CreateDirService, success_notice: "The directory has been successfully created.",
success_path: namespace_project_tree_path(@project.namespace, @project, File.join(@target_branch, @dir_name)),
failure_path: namespace_project_tree_path(@project.namespace, @project, @ref))
......
---
title: New directory from interface on existing branch
merge_request: 9921
author: Jacopo Beschi @jacopo-beschi
......@@ -2,6 +2,7 @@ require 'spec_helper'
feature 'New blob creation', feature: true, js: true do
include WaitForAjax
include TargetBranchHelpers
given(:user) { create(:user) }
given(:role) { :developer }
......@@ -20,19 +21,6 @@ feature 'New blob creation', feature: true, js: true do
execute_script("ace.edit('editor').setValue('#{content}')")
end
def select_branch_index(index)
first('button.js-target-branch').click
wait_for_ajax
all('a[data-group="Branches"]')[index].click
end
def create_new_branch(name)
first('button.js-target-branch').click
click_link 'Create new branch'
fill_in 'new_branch_name', with: name
click_button 'Create'
end
def commit_file
click_button 'Commit Changes'
end
......@@ -53,12 +41,12 @@ feature 'New blob creation', feature: true, js: true do
context 'with different target branch' do
background do
edit_file
select_branch_index(0)
select_branch('feature')
commit_file
end
scenario 'creates the blob in the different branch' do
expect(page).to have_content 'test'
expect(page).to have_content 'feature'
expect(page).to have_content 'successfully created'
end
end
......
require 'spec_helper'
feature 'New directory creation', feature: true, js: true do
include WaitForAjax
include TargetBranchHelpers
given(:user) { create(:user) }
given(:role) { :developer }
given(:project) { create(:project) }
background do
login_as(user)
project.team << [user, role]
visit namespace_project_tree_path(project.namespace, project, 'master')
open_new_directory_modal
fill_in 'dir_name', with: 'new_directory'
end
def open_new_directory_modal
first('.add-to-tree').click
click_link 'New directory'
end
def create_directory
click_button 'Create directory'
end
context 'with default target branch' do
background do
create_directory
end
scenario 'creates the directory in the default branch' do
expect(page).to have_content 'master'
expect(page).to have_content 'The directory has been successfully created'
expect(page).to have_content 'new_directory'
end
end
context 'with different target branch' do
background do
select_branch('feature')
create_directory
end
scenario 'creates the directory in the different branch' do
expect(page).to have_content 'feature'
expect(page).to have_content 'The directory has been successfully created'
end
end
context 'with a new target branch' do
given(:new_branch_name) { 'new-feature' }
background do
create_new_branch(new_branch_name)
create_directory
end
scenario 'creates the directory in the new branch' do
expect(page).to have_content new_branch_name
expect(page).to have_content 'The directory has been successfully created'
end
scenario 'redirects to the merge request' do
expect(page).to have_content 'New Merge Request'
expect(page).to have_content "From #{new_branch_name} into master"
expect(page).to have_content 'Add new directory'
expect(current_path).to eq(new_namespace_project_merge_request_path(project.namespace, project))
end
end
end
module TargetBranchHelpers
def select_branch(name)
first('button.js-target-branch').click
wait_for_ajax
all('a[data-group="Branches"]').find do |el|
el.text == name
end.click
end
def create_new_branch(name)
first('button.js-target-branch').click
click_link 'Create new branch'
fill_in 'new_branch_name', with: name
click_button 'Create'
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