Commit e8ca579d authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Add a project forks spec helper

The helper creates a fork of a project with all provided attributes,
but skipping the creation of the repository on disk.
parent 3c5f4d3b4989
......@@ -58,13 +58,13 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'I should see my fork on the list' do
page.within('.js-projects-list-holder') do
project = @user.fork_of(@project)
project = @user.fork_of(@project.reload)
expect(page).to have_content("#{project.namespace.human_name} / #{project.name}")
end
end
step 'I make forked repo invalid' do
project = @user.fork_of(@project)
project = @user.fork_of(@project.reload)
project.path = 'test-crappy-path'
project.save!
end
......
......@@ -5,6 +5,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
include SharedPaths
include Select2Helper
include WaitForRequests
include ProjectForksHelper
step 'I am a member of project "Shop"' do
@project = ::Project.find_by(name: "Shop")
......@@ -13,7 +14,9 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
end
step 'I have a project forked off of "Shop" called "Forked Shop"' do
@forked_project = Projects::ForkService.new(@project, @user).execute
@forked_project = fork_project(@project, @user,
namespace: @user.namespace,
repository: true)
end
step 'I click link "New Merge Request"' do
......
......@@ -10,7 +10,7 @@
Knapsack::Adapters::SpinachAdapter.bind
end
%w(select2_helper test_env repo_helpers wait_for_requests sidekiq).each do |f|
%w(select2_helper test_env repo_helpers wait_for_requests sidekiq project_forks_helper).each do |f|
require Rails.root.join('spec', 'support', f)
end
......
require 'rails_helper'
describe Projects::BlobController do
include ProjectForksHelper
let(:project) { create(:project, :public, :repository) }
describe "GET show" do
......@@ -226,9 +228,8 @@ def blob_after_edit_path
end
context 'when user has forked project' do
let(:forked_project_link) { create(:forked_project_link, forked_from_project: project) }
let!(:forked_project) { forked_project_link.forked_to_project }
let(:guest) { forked_project.owner }
let!(:forked_project) { fork_project(project, guest, namespace: guest.namespace, repository: true) }
let(:guest) { create(:user) }
before do
sign_in(guest)
......
require 'spec_helper'
describe Projects::MergeRequests::DiffsController do
include ProjectForksHelper
let(:project) { create(:project, :repository) }
let(:user) { project.owner }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
......@@ -37,12 +39,12 @@ def go(extra_params = {})
render_views
let(:project) { create(:project, :repository) }
let(:fork_project) { create(:forked_project_with_submodules) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: fork_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
let(:forked_project) { fork_project_with_submodules(project) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: forked_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
before do
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
fork_project.save
project.add_developer(user)
merge_request.reload
go
end
......
require 'spec_helper'
describe Projects::MergeRequestsController do
include ProjectForksHelper
let(:project) { create(:project, :repository) }
let(:user) { project.owner }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
......@@ -204,14 +206,11 @@ def get_merge_requests(page = nil)
context 'there is no source project' do
let(:project) { create(:project, :repository) }
let(:fork_project) { create(:forked_project_with_submodules) }
let(:merge_request) { create(:merge_request, source_project: fork_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
let(:forked_project) { fork_project_with_submodules(project) }
let!(:merge_request) { create(:merge_request, source_project: forked_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: project) }
before do
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
fork_project.save
merge_request.reload
fork_project.destroy
forked_project.destroy
end
it 'closes MR without errors' do
......@@ -599,21 +598,16 @@ def post_assign_issues
describe 'GET ci_environments_status' do
context 'the environment is from a forked project' do
let!(:forked) { create(:project, :repository) }
let!(:forked) { fork_project(project, user, repository: true) }
let!(:environment) { create(:environment, project: forked) }
let!(:deployment) { create(:deployment, environment: environment, sha: forked.commit.id, ref: 'master') }
let(:admin) { create(:admin) }
let(:merge_request) do
create(:forked_project_link, forked_to_project: forked,
forked_from_project: project)
create(:merge_request, source_project: forked, target_project: project)
end
before do
forked.team << [user, :master]
get :ci_environments_status,
namespace_id: merge_request.project.namespace.to_param,
project_id: merge_request.project,
......
require 'spec_helper'
describe Projects::NotesController do
include ProjectForksHelper
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
......@@ -210,18 +212,16 @@
context 'when creating a commit comment from an MR fork' do
let(:project) { create(:project, :repository) }
let(:fork_project) do
create(:project, :repository).tap do |fork|
create(:forked_project_link, forked_to_project: fork, forked_from_project: project)
end
let(:forked_project) do
fork_project(project, nil, repository: true)
end
let(:merge_request) do
create(:merge_request, source_project: fork_project, target_project: project, source_branch: 'feature', target_branch: 'master')
create(:merge_request, source_project: forked_project, target_project: project, source_branch: 'feature', target_branch: 'master')
end
let(:existing_comment) do
create(:note_on_commit, note: 'a note', project: fork_project, commit_id: merge_request.commit_shas.first)
create(:note_on_commit, note: 'a note', project: forked_project, commit_id: merge_request.commit_shas.first)
end
def post_create(extra_params = {})
......@@ -231,7 +231,7 @@ def post_create(extra_params = {})
project_id: project,
target_type: 'merge_request',
target_id: merge_request.id,
note_project_id: fork_project.id,
note_project_id: forked_project.id,
in_reply_to_discussion_id: existing_comment.discussion_id
}.merge(extra_params)
end
......@@ -253,16 +253,16 @@ def post_create(extra_params = {})
end
context 'when the user has access to the fork' do
let(:discussion) { fork_project.notes.find_discussion(existing_comment.discussion_id) }
let(:discussion) { forked_project.notes.find_discussion(existing_comment.discussion_id) }
before do
fork_project.add_developer(user)
forked_project.add_developer(user)
existing_comment
end
it 'creates the note' do
expect { post_create }.to change { fork_project.notes.count }.by(1)
expect { post_create }.to change { forked_project.notes.count }.by(1)
end
end
end
......
require('spec_helper')
describe ProjectsController do
include ProjectForksHelper
let(:project) { create(:project) }
let(:public_project) { create(:project, :public) }
let(:user) { create(:user) }
......@@ -377,10 +379,10 @@ def update_project(**parameters)
context "when the project is forked" do
let(:project) { create(:project, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
let(:forked_project) { fork_project(project, nil, repository: true) }
let(:merge_request) do
create(:merge_request,
source_project: fork_project,
source_project: forked_project,
target_project: project)
end
......@@ -388,7 +390,7 @@ def update_project(**parameters)
project.merge_requests << merge_request
sign_in(admin)
delete :destroy, namespace_id: fork_project.namespace, id: fork_project
delete :destroy, namespace_id: forked_project.namespace, id: forked_project
expect(merge_request.reload.state).to eq('closed')
end
......@@ -455,18 +457,14 @@ def update_project(**parameters)
end
context 'with forked project' do
let(:project_fork) { create(:project, :repository, namespace: user.namespace) }
before do
create(:forked_project_link, forked_to_project: project_fork)
end
let(:forked_project) { fork_project(create(:project, :public), user) }
it 'removes fork from project' do
delete(:remove_fork,
namespace_id: project_fork.namespace.to_param,
id: project_fork.to_param, format: :js)
namespace_id: forked_project.namespace.to_param,
id: forked_project.to_param, format: :js)
expect(project_fork.forked?).to be_falsey
expect(forked_project.reload.forked?).to be_falsey
expect(flash[:notice]).to eq('The fork relationship has been removed.')
expect(response).to render_template(:remove_fork)
end
......
......@@ -3,12 +3,13 @@
feature 'Dashboard Merge Requests' do
include FilterItemSelectHelper
include SortingHelper
include ProjectForksHelper
let(:current_user) { create :user }
let(:project) { create(:project) }
let(:public_project) { create(:project, :public, :repository) }
let(:forked_project) { Projects::ForkService.new(public_project, current_user).execute }
let(:forked_project) { fork_project(public_project, current_user, repository: true) }
before do
project.add_master(current_user)
......
require 'spec_helper'
feature 'Creating a merge request from a fork', :js do
include ProjectForksHelper
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let!(:source_project) { ::Projects::ForkService.new(project, user).execute }
let!(:source_project) do
fork_project(project, user,
repository: true,
namespace: user.namespace)
end
before do
source_project.add_master(user)
......@@ -49,7 +55,6 @@
target_project_member = target_project.owner
CreateBranchService.new(target_project, target_project_member)
.execute('a-brand-new-branch-to-test', 'master')
visit project_new_merge_request_path(source_project)
first('.js-target-project').click
......@@ -66,13 +71,18 @@
end
context 'creating to the source of a fork' do
let(:target_project) { project }
let!(:target_project) { project }
it_behaves_like('create merge request to other project')
end
context 'creating to a sibling of a fork' do
let!(:target_project) { ::Projects::ForkService.new(project, create(:user)).execute }
let!(:target_project) do
other_user = create(:user)
fork_project(project, other_user,
repository: true,
namespace: other_user.namespace)
end
it_behaves_like('create merge request to other project')
end
......
require 'spec_helper'
feature 'Merge request created from fork' do
include ProjectForksHelper
given(:user) { create(:user) }
given(:project) { create(:project, :public, :repository) }
given(:fork_project) { create(:project, :public, :repository) }
given(:forked_project) { fork_project(project, user, repository: true) }
given!(:merge_request) do
create(:forked_project_link, forked_to_project: fork_project,
forked_from_project: project)
create(:merge_request_with_diffs, source_project: fork_project,
create(:merge_request_with_diffs, source_project: forked_project,
target_project: project,
description: 'Test merge request')
end
background do
fork_project.team << [user, :master]
forked_project.team << [user, :master]
sign_in user
end
......@@ -31,7 +30,7 @@
background do
create(:note_on_commit, note: comment,
project: fork_project,
project: forked_project,
commit_id: merge_request.commit_shas.first)
end
......@@ -55,7 +54,7 @@
context 'source project is deleted' do
background do
MergeRequests::MergeService.new(project, user).execute(merge_request)
fork_project.destroy!
forked_project.destroy!
end
scenario 'user can access merge request', js: true do
......@@ -69,7 +68,7 @@
context 'pipeline present in source project' do
given(:pipeline) do
create(:ci_pipeline,
project: fork_project,
project: forked_project,
sha: merge_request.diff_head_sha,
ref: merge_request.source_branch)
end
......
require 'spec_helper'
feature 'Diffs URL', js: true do
include ProjectForksHelper
let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) }
......@@ -68,7 +70,7 @@
context 'when editing file' do
let(:author_user) { create(:user) }
let(:user) { create(:user) }
let(:forked_project) { Projects::ForkService.new(project, author_user).execute }
let(:forked_project) { fork_project(project, author_user, repository: true) }
let(:merge_request) { create(:merge_request_with_diffs, source_project: forked_project, target_project: project, author: author_user) }
let(:changelog_id) { Digest::SHA1.hexdigest("CHANGELOG") }
......
require 'rails_helper'
describe 'New/edit merge request', :js do
include ProjectForksHelper
let!(:project) { create(:project, :public, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
let(:forked_project) { fork_project(project, nil, repository: true) }
let!(:user) { create(:user) }
let!(:user2) { create(:user) }
let!(:milestone) { create(:milestone, project: project) }
......@@ -170,16 +172,16 @@
context 'forked project' do
before do
fork_project.team << [user, :master]
forked_project.team << [user, :master]
sign_in(user)
end
context 'new merge request' do
before do
visit project_new_merge_request_path(
fork_project,
forked_project,
merge_request: {
source_project_id: fork_project.id,
source_project_id: forked_project.id,
target_project_id: project.id,
source_branch: 'fix',
target_branch: 'master'
......@@ -238,7 +240,7 @@
context 'edit merge request' do
before do
merge_request = create(:merge_request,
source_project: fork_project,
source_project: forked_project,
target_project: project,
source_branch: 'fix',
target_branch: 'master'
......
require 'spec_helper'
feature 'issuable templates', js: true do
include ProjectForksHelper
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' }
......@@ -116,15 +118,13 @@
context 'user creates a merge request from a forked project using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' }
let(:fork_user) { create(:user) }
let(:fork_project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: fork_project, target_project: project) }
let(:forked_project) { fork_project(project, fork_user) }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) }
background do
sign_out(:user)
project.team << [fork_user, :developer]
fork_project.team << [fork_user, :master]
create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project)
sign_in(fork_user)
......
......@@ -79,7 +79,7 @@
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Create directory')
fork = user.fork_of(project2)
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
end
......
......@@ -142,7 +142,7 @@
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes')
fork = user.fork_of(project2)
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
expect(page).to have_content('New commit message')
......
......@@ -59,7 +59,7 @@
fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Delete file')
fork = user.fork_of(project2)
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
expect(page).to have_content('New commit message')
......
......@@ -74,7 +74,7 @@
expect(page).to have_content('Replacement file commit message')
fork = user.fork_of(project2)
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
......
......@@ -39,6 +39,9 @@
expect(current_path).to eq(project_new_merge_request_path(project))
click_link('Changes')
find("a[data-action='diffs']", text: 'Changes').click
wait_for_requests
expect(page).to have_content('Lorem ipsum dolor sit amet')
expect(page).to have_content('Sed ut perspiciatis unde omnis')
......@@ -51,7 +54,7 @@
visit(project2_tree_path_root_ref)
end
it 'uploads and commit a new fileto a forked project', js: true do
it 'uploads and commit a new file to a forked project', js: true do
find('.add-to-tree').click
click_link('Upload file')
......@@ -69,11 +72,13 @@
expect(page).to have_content('New commit message')
fork = user.fork_of(project2)
fork = user.fork_of(project2.reload)
expect(current_path).to eq(project_new_merge_request_path(fork))
click_link('Changes')
find("a[data-action='diffs']", text: 'Changes').click
wait_for_requests
expect(page).to have_content('Lorem ipsum dolor sit amet')
expect(page).to have_content('Sed ut perspiciatis unde omnis')
......
require 'spec_helper'
feature 'Project' do
include ProjectForksHelper
describe 'creating from template' do
let(:user) { create(:user) }
let(:template) { Gitlab::ProjectTemplate.find(:rails) }
......@@ -57,11 +59,10 @@
describe 'remove forked relationship', js: true do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let(:project) { fork_project(create(:project, :public), user, namespace_id: user.namespace) }
before do
sign_in user
create(:forked_project_link, forked_to_project: project)
visit edit_project_path(project)
end
......@@ -71,7 +72,7 @@
remove_with_confirm('Remove fork relationship', project.path)
expect(page).to have_content 'The fork relationship has been removed.'
expect(project.forked?).to be_falsey
expect(project.reload.forked?).to be_falsey
expect(page).not_to have_content 'Remove fork relationship'
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