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

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 7c00b538
...@@ -58,13 +58,13 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps ...@@ -58,13 +58,13 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps
step 'I should see my fork on the list' do step 'I should see my fork on the list' do
page.within('.js-projects-list-holder') 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}") expect(page).to have_content("#{project.namespace.human_name} / #{project.name}")
end end
end end
step 'I make forked repo invalid' do step 'I make forked repo invalid' do
project = @user.fork_of(@project) project = @user.fork_of(@project.reload)
project.path = 'test-crappy-path' project.path = 'test-crappy-path'
project.save! project.save!
end end
......
...@@ -5,6 +5,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -5,6 +5,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
include SharedPaths include SharedPaths
include Select2Helper include Select2Helper
include WaitForRequests include WaitForRequests
include ProjectForksHelper
step 'I am a member of project "Shop"' do step 'I am a member of project "Shop"' do
@project = ::Project.find_by(name: "Shop") @project = ::Project.find_by(name: "Shop")
...@@ -13,7 +14,9 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -13,7 +14,9 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
end end
step 'I have a project forked off of "Shop" called "Forked Shop"' do 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 end
step 'I click link "New Merge Request"' do step 'I click link "New Merge Request"' do
......
...@@ -10,7 +10,7 @@ if ENV['CI'] ...@@ -10,7 +10,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind Knapsack::Adapters::SpinachAdapter.bind
end 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) require Rails.root.join('spec', 'support', f)
end end
......
require 'rails_helper' require 'rails_helper'
describe Projects::BlobController do describe Projects::BlobController do
include ProjectForksHelper
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
describe "GET show" do describe "GET show" do
...@@ -226,9 +228,8 @@ describe Projects::BlobController do ...@@ -226,9 +228,8 @@ describe Projects::BlobController do
end end
context 'when user has forked project' do context 'when user has forked project' do
let(:forked_project_link) { create(:forked_project_link, forked_from_project: project) } let!(:forked_project) { fork_project(project, guest, namespace: guest.namespace, repository: true) }
let!(:forked_project) { forked_project_link.forked_to_project } let(:guest) { create(:user) }
let(:guest) { forked_project.owner }
before do before do
sign_in(guest) sign_in(guest)
......
require 'spec_helper' require 'spec_helper'
describe Projects::MergeRequests::DiffsController do describe Projects::MergeRequests::DiffsController do
include ProjectForksHelper
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { project.owner } let(:user) { project.owner }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
...@@ -37,12 +39,12 @@ describe Projects::MergeRequests::DiffsController do ...@@ -37,12 +39,12 @@ describe Projects::MergeRequests::DiffsController do
render_views render_views
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:fork_project) { create(:forked_project_with_submodules) } let(:forked_project) { fork_project_with_submodules(project) }
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(: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 before do
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id) project.add_developer(user)
fork_project.save
merge_request.reload merge_request.reload
go go
end end
......
require 'spec_helper' require 'spec_helper'
describe Projects::MergeRequestsController do describe Projects::MergeRequestsController do
include ProjectForksHelper
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { project.owner } let(:user) { project.owner }
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
...@@ -204,14 +206,11 @@ describe Projects::MergeRequestsController do ...@@ -204,14 +206,11 @@ describe Projects::MergeRequestsController do
context 'there is no source project' do context 'there is no source project' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:fork_project) { create(:forked_project_with_submodules) } let(:forked_project) { fork_project_with_submodules(project) }
let(:merge_request) { create(:merge_request, source_project: fork_project, source_branch: 'add-submodule-version-bump', target_branch: 'master', target_project: 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 before do
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id) forked_project.destroy
fork_project.save
merge_request.reload
fork_project.destroy
end end
it 'closes MR without errors' do it 'closes MR without errors' do
...@@ -599,21 +598,16 @@ describe Projects::MergeRequestsController do ...@@ -599,21 +598,16 @@ describe Projects::MergeRequestsController do
describe 'GET ci_environments_status' do describe 'GET ci_environments_status' do
context 'the environment is from a forked project' 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!(:environment) { create(:environment, project: forked) }
let!(:deployment) { create(:deployment, environment: environment, sha: forked.commit.id, ref: 'master') } let!(:deployment) { create(:deployment, environment: environment, sha: forked.commit.id, ref: 'master') }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let(:merge_request) do 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) create(:merge_request, source_project: forked, target_project: project)
end end
before do before do
forked.team << [user, :master]
get :ci_environments_status, get :ci_environments_status,
namespace_id: merge_request.project.namespace.to_param, namespace_id: merge_request.project.namespace.to_param,
project_id: merge_request.project, project_id: merge_request.project,
......
require 'spec_helper' require 'spec_helper'
describe Projects::NotesController do describe Projects::NotesController do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
...@@ -210,18 +212,16 @@ describe Projects::NotesController do ...@@ -210,18 +212,16 @@ describe Projects::NotesController do
context 'when creating a commit comment from an MR fork' do context 'when creating a commit comment from an MR fork' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:fork_project) do let(:forked_project) do
create(:project, :repository).tap do |fork| fork_project(project, nil, repository: true)
create(:forked_project_link, forked_to_project: fork, forked_from_project: project)
end
end end
let(:merge_request) do 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 end
let(:existing_comment) do 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 end
def post_create(extra_params = {}) def post_create(extra_params = {})
...@@ -231,7 +231,7 @@ describe Projects::NotesController do ...@@ -231,7 +231,7 @@ describe Projects::NotesController do
project_id: project, project_id: project,
target_type: 'merge_request', target_type: 'merge_request',
target_id: merge_request.id, 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 in_reply_to_discussion_id: existing_comment.discussion_id
}.merge(extra_params) }.merge(extra_params)
end end
...@@ -253,16 +253,16 @@ describe Projects::NotesController do ...@@ -253,16 +253,16 @@ describe Projects::NotesController do
end end
context 'when the user has access to the fork' do 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 before do
fork_project.add_developer(user) forked_project.add_developer(user)
existing_comment existing_comment
end end
it 'creates the note' do 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 end
end end
......
require('spec_helper') require('spec_helper')
describe ProjectsController do describe ProjectsController do
include ProjectForksHelper
let(:project) { create(:project) } let(:project) { create(:project) }
let(:public_project) { create(:project, :public) } let(:public_project) { create(:project, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -377,10 +379,10 @@ describe ProjectsController do ...@@ -377,10 +379,10 @@ describe ProjectsController do
context "when the project is forked" do context "when the project is forked" do
let(:project) { create(:project, :repository) } 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 let(:merge_request) do
create(:merge_request, create(:merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
...@@ -388,7 +390,7 @@ describe ProjectsController do ...@@ -388,7 +390,7 @@ describe ProjectsController do
project.merge_requests << merge_request project.merge_requests << merge_request
sign_in(admin) 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') expect(merge_request.reload.state).to eq('closed')
end end
...@@ -455,18 +457,14 @@ describe ProjectsController do ...@@ -455,18 +457,14 @@ describe ProjectsController do
end end
context 'with forked project' do context 'with forked project' do
let(:project_fork) { create(:project, :repository, namespace: user.namespace) } let(:forked_project) { fork_project(create(:project, :public), user) }
before do
create(:forked_project_link, forked_to_project: project_fork)
end
it 'removes fork from project' do it 'removes fork from project' do
delete(:remove_fork, delete(:remove_fork,
namespace_id: project_fork.namespace.to_param, namespace_id: forked_project.namespace.to_param,
id: project_fork.to_param, format: :js) 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(flash[:notice]).to eq('The fork relationship has been removed.')
expect(response).to render_template(:remove_fork) expect(response).to render_template(:remove_fork)
end end
......
...@@ -3,12 +3,13 @@ require 'spec_helper' ...@@ -3,12 +3,13 @@ require 'spec_helper'
feature 'Dashboard Merge Requests' do feature 'Dashboard Merge Requests' do
include FilterItemSelectHelper include FilterItemSelectHelper
include SortingHelper include SortingHelper
include ProjectForksHelper
let(:current_user) { create :user } let(:current_user) { create :user }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:public_project) { create(:project, :public, :repository) } 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 before do
project.add_master(current_user) project.add_master(current_user)
......
require 'spec_helper' require 'spec_helper'
feature 'Creating a merge request from a fork', :js do feature 'Creating a merge request from a fork', :js do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) } 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 before do
source_project.add_master(user) source_project.add_master(user)
...@@ -49,7 +55,6 @@ feature 'Creating a merge request from a fork', :js do ...@@ -49,7 +55,6 @@ feature 'Creating a merge request from a fork', :js do
target_project_member = target_project.owner target_project_member = target_project.owner
CreateBranchService.new(target_project, target_project_member) CreateBranchService.new(target_project, target_project_member)
.execute('a-brand-new-branch-to-test', 'master') .execute('a-brand-new-branch-to-test', 'master')
visit project_new_merge_request_path(source_project) visit project_new_merge_request_path(source_project)
first('.js-target-project').click first('.js-target-project').click
...@@ -66,13 +71,18 @@ feature 'Creating a merge request from a fork', :js do ...@@ -66,13 +71,18 @@ feature 'Creating a merge request from a fork', :js do
end end
context 'creating to the source of a fork' do 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') it_behaves_like('create merge request to other project')
end end
context 'creating to a sibling of a fork' do 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') it_behaves_like('create merge request to other project')
end end
......
require 'spec_helper' require 'spec_helper'
feature 'Merge request created from fork' do feature 'Merge request created from fork' do
include ProjectForksHelper
given(:user) { create(:user) } given(:user) { create(:user) }
given(:project) { create(:project, :public, :repository) } 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 given!(:merge_request) do
create(:forked_project_link, forked_to_project: fork_project, create(:merge_request_with_diffs, source_project: forked_project,
forked_from_project: project)
create(:merge_request_with_diffs, source_project: fork_project,
target_project: project, target_project: project,
description: 'Test merge request') description: 'Test merge request')
end end
background do background do
fork_project.team << [user, :master] forked_project.team << [user, :master]
sign_in user sign_in user
end end
...@@ -31,7 +30,7 @@ feature 'Merge request created from fork' do ...@@ -31,7 +30,7 @@ feature 'Merge request created from fork' do
background do background do
create(:note_on_commit, note: comment, create(:note_on_commit, note: comment,
project: fork_project, project: forked_project,
commit_id: merge_request.commit_shas.first) commit_id: merge_request.commit_shas.first)
end end
...@@ -55,7 +54,7 @@ feature 'Merge request created from fork' do ...@@ -55,7 +54,7 @@ feature 'Merge request created from fork' do
context 'source project is deleted' do context 'source project is deleted' do
background do background do
MergeRequests::MergeService.new(project, user).execute(merge_request) MergeRequests::MergeService.new(project, user).execute(merge_request)
fork_project.destroy! forked_project.destroy!
end end
scenario 'user can access merge request', js: true do scenario 'user can access merge request', js: true do
...@@ -69,7 +68,7 @@ feature 'Merge request created from fork' do ...@@ -69,7 +68,7 @@ feature 'Merge request created from fork' do
context 'pipeline present in source project' do context 'pipeline present in source project' do
given(:pipeline) do given(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
project: fork_project, project: forked_project,
sha: merge_request.diff_head_sha, sha: merge_request.diff_head_sha,
ref: merge_request.source_branch) ref: merge_request.source_branch)
end end
......
require 'spec_helper' require 'spec_helper'
feature 'Diffs URL', js: true do feature 'Diffs URL', js: true do
include ProjectForksHelper
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
...@@ -68,7 +70,7 @@ feature 'Diffs URL', js: true do ...@@ -68,7 +70,7 @@ feature 'Diffs URL', js: true do
context 'when editing file' do context 'when editing file' do
let(:author_user) { create(:user) } let(:author_user) { create(:user) }
let(: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(:merge_request) { create(:merge_request_with_diffs, source_project: forked_project, target_project: project, author: author_user) }
let(:changelog_id) { Digest::SHA1.hexdigest("CHANGELOG") } let(:changelog_id) { Digest::SHA1.hexdigest("CHANGELOG") }
......
require 'rails_helper' require 'rails_helper'
describe 'New/edit merge request', :js do describe 'New/edit merge request', :js do
include ProjectForksHelper
let!(:project) { create(:project, :public, :repository) } 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!(:user) { create(:user) }
let!(:user2) { create(:user) } let!(:user2) { create(:user) }
let!(:milestone) { create(:milestone, project: project) } let!(:milestone) { create(:milestone, project: project) }
...@@ -170,16 +172,16 @@ describe 'New/edit merge request', :js do ...@@ -170,16 +172,16 @@ describe 'New/edit merge request', :js do
context 'forked project' do context 'forked project' do
before do before do
fork_project.team << [user, :master] forked_project.team << [user, :master]
sign_in(user) sign_in(user)
end end
context 'new merge request' do context 'new merge request' do
before do before do
visit project_new_merge_request_path( visit project_new_merge_request_path(
fork_project, forked_project,
merge_request: { merge_request: {
source_project_id: fork_project.id, source_project_id: forked_project.id,
target_project_id: project.id, target_project_id: project.id,
source_branch: 'fix', source_branch: 'fix',
target_branch: 'master' target_branch: 'master'
...@@ -238,7 +240,7 @@ describe 'New/edit merge request', :js do ...@@ -238,7 +240,7 @@ describe 'New/edit merge request', :js do
context 'edit merge request' do context 'edit merge request' do
before do before do
merge_request = create(:merge_request, merge_request = create(:merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project, target_project: project,
source_branch: 'fix', source_branch: 'fix',
target_branch: 'master' target_branch: 'master'
......
require 'spec_helper' require 'spec_helper'
feature 'issuable templates', js: true do feature 'issuable templates', js: true do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' } let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' }
...@@ -116,15 +118,13 @@ feature 'issuable templates', js: true do ...@@ -116,15 +118,13 @@ feature 'issuable templates', js: true do
context 'user creates a merge request from a forked project using templates' do context 'user creates a merge request from a forked project using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' } let(:template_content) { 'this is a test "feature-proposal" template' }
let(:fork_user) { create(:user) } let(:fork_user) { create(:user) }
let(:fork_project) { create(:project, :public, :repository) } let(:forked_project) { fork_project(project, fork_user) }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: fork_project, target_project: project) } let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) }
background do background do
sign_out(:user) sign_out(:user)
project.team << [fork_user, :developer] 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) sign_in(fork_user)
......
...@@ -79,7 +79,7 @@ feature 'User creates a directory', js: true do ...@@ -79,7 +79,7 @@ feature 'User creates a directory', js: true do
fill_in(:commit_message, with: 'New commit message', visible: true) fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Create directory') 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)) expect(current_path).to eq(project_new_merge_request_path(fork))
end end
......
...@@ -142,7 +142,7 @@ describe 'User creates files' do ...@@ -142,7 +142,7 @@ describe 'User creates files' do
fill_in(:commit_message, with: 'New commit message', visible: true) fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Commit changes') 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(current_path).to eq(project_new_merge_request_path(fork))
expect(page).to have_content('New commit message') expect(page).to have_content('New commit message')
......
...@@ -59,7 +59,7 @@ describe 'User deletes files' do ...@@ -59,7 +59,7 @@ describe 'User deletes files' do
fill_in(:commit_message, with: 'New commit message', visible: true) fill_in(:commit_message, with: 'New commit message', visible: true)
click_button('Delete file') 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(current_path).to eq(project_new_merge_request_path(fork))
expect(page).to have_content('New commit message') expect(page).to have_content('New commit message')
......
...@@ -74,7 +74,7 @@ describe 'User replaces files' do ...@@ -74,7 +74,7 @@ describe 'User replaces files' do
expect(page).to have_content('Replacement file commit message') 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)) expect(current_path).to eq(project_new_merge_request_path(fork))
......
...@@ -39,6 +39,9 @@ describe 'User uploads files' do ...@@ -39,6 +39,9 @@ describe 'User uploads files' do
expect(current_path).to eq(project_new_merge_request_path(project)) expect(current_path).to eq(project_new_merge_request_path(project))
click_link('Changes') 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('Lorem ipsum dolor sit amet')
expect(page).to have_content('Sed ut perspiciatis unde omnis') expect(page).to have_content('Sed ut perspiciatis unde omnis')
...@@ -51,7 +54,7 @@ describe 'User uploads files' do ...@@ -51,7 +54,7 @@ describe 'User uploads files' do
visit(project2_tree_path_root_ref) visit(project2_tree_path_root_ref)
end 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 find('.add-to-tree').click
click_link('Upload file') click_link('Upload file')
...@@ -69,11 +72,13 @@ describe 'User uploads files' do ...@@ -69,11 +72,13 @@ describe 'User uploads files' do
expect(page).to have_content('New commit message') 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)) 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('Lorem ipsum dolor sit amet')
expect(page).to have_content('Sed ut perspiciatis unde omnis') expect(page).to have_content('Sed ut perspiciatis unde omnis')
......
require 'spec_helper' require 'spec_helper'
feature 'Project' do feature 'Project' do
include ProjectForksHelper
describe 'creating from template' do describe 'creating from template' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:template) { Gitlab::ProjectTemplate.find(:rails) } let(:template) { Gitlab::ProjectTemplate.find(:rails) }
...@@ -57,11 +59,10 @@ feature 'Project' do ...@@ -57,11 +59,10 @@ feature 'Project' do
describe 'remove forked relationship', js: true do describe 'remove forked relationship', js: true do
let(:user) { create(:user) } 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 before do
sign_in user sign_in user
create(:forked_project_link, forked_to_project: project)
visit edit_project_path(project) visit edit_project_path(project)
end end
...@@ -71,7 +72,7 @@ feature 'Project' do ...@@ -71,7 +72,7 @@ feature 'Project' do
remove_with_confirm('Remove fork relationship', project.path) remove_with_confirm('Remove fork relationship', project.path)
expect(page).to have_content 'The fork relationship has been removed.' 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' expect(page).not_to have_content 'Remove fork relationship'
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe MergeRequestsFinder do describe MergeRequestsFinder do
include ProjectForksHelper
let(:user) { create :user } let(:user) { create :user }
let(:user2) { create :user } let(:user2) { create :user }
let(:project1) { create(:project) } let(:project1) { create(:project, :public) }
let(:project2) { create(:project, forked_from_project: project1) } let(:project2) { fork_project(project1, user) }
let(:project3) { create(:project, :archived, forked_from_project: project1) } let(:project3) do
p = fork_project(project1, user)
p.update!(archived: true)
p
end
let!(:merge_request1) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1) } let!(:merge_request1) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1) }
let!(:merge_request2) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1, state: 'closed') } let!(:merge_request2) { create(:merge_request, :simple, author: user, source_project: project2, target_project: project1, state: 'closed') }
......
require 'spec_helper' require 'spec_helper'
describe MergeRequestsHelper do describe MergeRequestsHelper do
include ProjectForksHelper
describe 'ci_build_details_path' do describe 'ci_build_details_path' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:merge_request) { MergeRequest.new } let(:merge_request) { MergeRequest.new }
...@@ -31,10 +32,10 @@ describe MergeRequestsHelper do ...@@ -31,10 +32,10 @@ describe MergeRequestsHelper do
describe 'within different projects' do describe 'within different projects' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) } let(:forked_project) { fork_project(project) }
let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) } let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
subject { format_mr_branch_names(merge_request) } subject { format_mr_branch_names(merge_request) }
let(:source_title) { "#{fork_project.full_path}:#{merge_request.source_branch}" } let(:source_title) { "#{forked_project.full_path}:#{merge_request.source_branch}" }
let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" } let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" }
it { is_expected.to eq([source_title, target_title]) } it { is_expected.to eq([source_title, target_title]) }
......
require 'spec_helper' require 'spec_helper'
describe 'forked project import' do describe 'forked project import' do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project_with_repo) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') } let!(:project_with_repo) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') }
let!(:project) { create(:project, name: 'test-repo-restorer-no-repo', path: 'test-repo-restorer-no-repo') } let!(:project) { create(:project, name: 'test-repo-restorer-no-repo', path: 'test-repo-restorer-no-repo') }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: project.full_path) } let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: project.full_path) }
let(:forked_from_project) { create(:project, :repository) } let(:forked_from_project) { create(:project, :repository) }
let(:fork_link) { create(:forked_project_link, forked_from_project: project_with_repo) } let(:forked_project) { fork_project(project_with_repo, nil, repository: true) }
let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) } let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
...@@ -16,7 +18,7 @@ describe 'forked project import' do ...@@ -16,7 +18,7 @@ describe 'forked project import' do
end end
let!(:merge_request) do let!(:merge_request) do
create(:merge_request, source_project: fork_link.forked_to_project, target_project: project_with_repo) create(:merge_request, source_project: forked_project, target_project: project_with_repo)
end end
let(:saver) do let(:saver) do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::ImportExport::MergeRequestParser do describe Gitlab::ImportExport::MergeRequestParser do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') } let!(:project) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') }
let(:forked_from_project) { create(:project, :repository) } let(:forked_project) { fork_project(project) }
let(:fork_link) { create(:forked_project_link, forked_from_project: project) }
let!(:merge_request) do let!(:merge_request) do
create(:merge_request, source_project: fork_link.forked_to_project, target_project: project) create(:merge_request, source_project: forked_project, target_project: project)
end end
let(:parsed_merge_request) do let(:parsed_merge_request) do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::SearchResults do describe Gitlab::SearchResults do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, name: 'foo') } let!(:project) { create(:project, name: 'foo') }
let!(:issue) { create(:issue, project: project, title: 'foo') } let!(:issue) { create(:issue, project: project, title: 'foo') }
...@@ -42,7 +44,7 @@ describe Gitlab::SearchResults do ...@@ -42,7 +44,7 @@ describe Gitlab::SearchResults do
end end
it 'includes merge requests from source and target projects' do it 'includes merge requests from source and target projects' do
forked_project = create(:project, forked_from_project: project) forked_project = fork_project(project, user)
merge_request_2 = create(:merge_request, target_project: project, source_project: forked_project, title: 'foo') merge_request_2 = create(:merge_request, target_project: project, source_project: forked_project, title: 'foo')
results = described_class.new(user, Project.where(id: forked_project.id), 'foo') results = described_class.new(user, Project.where(id: forked_project.id), 'foo')
......
...@@ -2,11 +2,12 @@ require 'spec_helper' ...@@ -2,11 +2,12 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170508170547_add_head_pipeline_for_each_merge_request.rb') require Rails.root.join('db', 'post_migrate', '20170508170547_add_head_pipeline_for_each_merge_request.rb')
describe AddHeadPipelineForEachMergeRequest, :truncate do describe AddHeadPipelineForEachMergeRequest, :truncate do
include ProjectForksHelper
let(:migration) { described_class.new } let(:migration) { described_class.new }
let!(:project) { create(:project) } let!(:project) { create(:project) }
let!(:forked_project_link) { create(:forked_project_link, forked_from_project: project) } let!(:other_project) { fork_project(project) }
let!(:other_project) { forked_project_link.forked_to_project }
let!(:pipeline_1) { create(:ci_pipeline, project: project, ref: "branch_1") } let!(:pipeline_1) { create(:ci_pipeline, project: project, ref: "branch_1") }
let!(:pipeline_2) { create(:ci_pipeline, project: other_project, ref: "branch_1") } let!(:pipeline_2) { create(:ci_pipeline, project: other_project, ref: "branch_1") }
......
require 'spec_helper' require 'spec_helper'
describe ForkedProjectLink, "add link on fork" do describe ForkedProjectLink, "add link on fork" do
include ProjectForksHelper
let(:project_from) { create(:project, :repository) } let(:project_from) { create(:project, :repository) }
let(:project_to) { fork_project(project_from, user) } let(:project_to) { fork_project(project_from, user) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:namespace) { user.namespace }
before do before do
project_from.add_reporter(user) project_from.add_reporter(user)
...@@ -64,13 +65,4 @@ describe ForkedProjectLink, "add link on fork" do ...@@ -64,13 +65,4 @@ describe ForkedProjectLink, "add link on fork" do
expect(ForkedProjectLink.exists?(id: forked_project_link.id)).to eq(false) expect(ForkedProjectLink.exists?(id: forked_project_link.id)).to eq(false)
end end
end end
def fork_project(from_project, user)
service = Projects::ForkService.new(from_project, user)
shell = double('gitlab_shell', fork_repository: true)
allow(service).to receive(:gitlab_shell).and_return(shell)
service.execute
end
end end
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe MergeRequest do describe MergeRequest do
include RepoHelpers include RepoHelpers
include ProjectForksHelper
subject { create(:merge_request) } subject { create(:merge_request) }
...@@ -52,8 +53,8 @@ describe MergeRequest do ...@@ -52,8 +53,8 @@ describe MergeRequest do
context 'for forks' do context 'for forks' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:fork1) { create(:forked_project_link, forked_from_project: project).forked_to_project } let(:fork1) { fork_project(project) }
let(:fork2) { create(:forked_project_link, forked_from_project: project).forked_to_project } let(:fork2) { fork_project(project) }
it 'allows merge requests for sibling-forks' do it 'allows merge requests for sibling-forks' do
subject.source_project = fork1 subject.source_project = fork1
...@@ -685,7 +686,7 @@ describe MergeRequest do ...@@ -685,7 +686,7 @@ describe MergeRequest do
describe '#diverged_commits_count' do describe '#diverged_commits_count' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) } let(:forked_project) { fork_project(project, nil, repository: true) }
context 'when the target branch does not exist anymore' do context 'when the target branch does not exist anymore' do
subject { create(:merge_request, source_project: project, target_project: project) } subject { create(:merge_request, source_project: project, target_project: project) }
...@@ -713,7 +714,7 @@ describe MergeRequest do ...@@ -713,7 +714,7 @@ describe MergeRequest do
end end
context 'diverged on fork' do context 'diverged on fork' do
subject(:merge_request_fork_with_divergence) { create(:merge_request, :diverged, source_project: fork_project, target_project: project) } subject(:merge_request_fork_with_divergence) { create(:merge_request, :diverged, source_project: forked_project, target_project: project) }
it 'counts commits that are on target branch but not on source branch' do it 'counts commits that are on target branch but not on source branch' do
expect(subject.diverged_commits_count).to eq(29) expect(subject.diverged_commits_count).to eq(29)
...@@ -721,7 +722,7 @@ describe MergeRequest do ...@@ -721,7 +722,7 @@ describe MergeRequest do
end end
context 'rebased on fork' do context 'rebased on fork' do
subject(:merge_request_rebased) { create(:merge_request, :rebased, source_project: fork_project, target_project: project) } subject(:merge_request_rebased) { create(:merge_request, :rebased, source_project: forked_project, target_project: project) }
it 'counts commits that are on target branch but not on source branch' do it 'counts commits that are on target branch but not on source branch' do
expect(subject.diverged_commits_count).to eq(0) expect(subject.diverged_commits_count).to eq(0)
...@@ -1270,11 +1271,7 @@ describe MergeRequest do ...@@ -1270,11 +1271,7 @@ describe MergeRequest do
end end
context 'with environments on source project' do context 'with environments on source project' do
let(:source_project) do let(:source_project) { fork_project(project, nil, repository: true) }
create(:project, :repository) do |fork_project|
fork_project.create_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id)
end
end
let(:merge_request) do let(:merge_request) do
create(:merge_request, create(:merge_request,
...@@ -1438,14 +1435,14 @@ describe MergeRequest do ...@@ -1438,14 +1435,14 @@ describe MergeRequest do
describe "#source_project_missing?" do describe "#source_project_missing?" do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:fork_project) { create(:forked_project_link, forked_from_project: project).forked_to_project } let(:forked_project) { fork_project(project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) } let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
context "when the fork exists" do context "when the fork exists" do
let(:merge_request) do let(:merge_request) do
create(:merge_request, create(:merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
...@@ -1461,7 +1458,7 @@ describe MergeRequest do ...@@ -1461,7 +1458,7 @@ describe MergeRequest do
context "when the fork does not exist" do context "when the fork does not exist" do
let!(:merge_request) do let!(:merge_request) do
create(:merge_request, create(:merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
...@@ -1484,14 +1481,14 @@ describe MergeRequest do ...@@ -1484,14 +1481,14 @@ describe MergeRequest do
describe "#closed_without_fork?" do describe "#closed_without_fork?" do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:fork_project) { create(:project, forked_from_project: project) } let(:forked_project) { fork_project(project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) } let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
context "when the merge request is closed" do context "when the merge request is closed" do
let(:closed_merge_request) do let(:closed_merge_request) do
create(:closed_merge_request, create(:closed_merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
...@@ -1510,7 +1507,7 @@ describe MergeRequest do ...@@ -1510,7 +1507,7 @@ describe MergeRequest do
context "when the merge request is open" do context "when the merge request is open" do
let(:open_merge_request) do let(:open_merge_request) do
create(:merge_request, create(:merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
...@@ -1529,24 +1526,24 @@ describe MergeRequest do ...@@ -1529,24 +1526,24 @@ describe MergeRequest do
end end
context 'forked project' do context 'forked project' do
let(:project) { create(:project) } let(:project) { create(:project, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:fork_project) { create(:project, forked_from_project: project, namespace: user.namespace) } let(:forked_project) { fork_project(project, user) }
let!(:merge_request) do let!(:merge_request) do
create(:closed_merge_request, create(:closed_merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project) target_project: project)
end end
it 'returns false if unforked' do it 'returns false if unforked' do
Projects::UnlinkForkService.new(fork_project, user).execute Projects::UnlinkForkService.new(forked_project, user).execute
expect(merge_request.reload.reopenable?).to be_falsey expect(merge_request.reload.reopenable?).to be_falsey
end end
it 'returns false if the source project is deleted' do it 'returns false if the source project is deleted' do
Projects::DestroyService.new(fork_project, user).execute Projects::DestroyService.new(forked_project, user).execute
expect(merge_request.reload.reopenable?).to be_falsey expect(merge_request.reload.reopenable?).to be_falsey
end end
......
...@@ -1819,40 +1819,34 @@ describe Project do ...@@ -1819,40 +1819,34 @@ describe Project do
end end
context 'forks' do context 'forks' do
include ProjectForksHelper
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let!(:forked_project) { fork_project(project) } let!(:forked_project) { fork_project(project) }
def fork_project(project)
Projects::ForkService.new(project, create(:user)).execute
end
describe '#fork_network' do describe '#fork_network' do
it 'includes a fork of the project' do it 'includes a fork of the project' do
expect(project.fork_network).to include(forked_project) expect(project.fork_network.projects).to include(forked_project)
end end
it 'includes a fork of a fork' do it 'includes a fork of a fork' do
other_fork = fork_project(forked_project) other_fork = fork_project(forked_project)
expect(project.fork_network).to include(other_fork) expect(project.fork_network.projects).to include(other_fork)
end end
it 'includes sibling forks' do it 'includes sibling forks' do
other_fork = fork_project(project) other_fork = fork_project(project)
expect(forked_project.fork_network).to include(other_fork) expect(forked_project.fork_network.projects).to include(other_fork)
end end
it 'includes the base project' do it 'includes the base project' do
expect(forked_project.fork_network).to include(project) expect(forked_project.fork_network.projects).to include(project.reload)
end end
end end
describe '#in_fork_network_of?' do describe '#in_fork_network_of?' do
it 'is false when the project is not a fork' do
expect(project.in_fork_network_of?(double)).to be_falsy
end
it 'is true for a real fork' do it 'is true for a real fork' do
expect(forked_project.in_fork_network_of?(project)).to be_truthy expect(forked_project.in_fork_network_of?(project)).to be_truthy
end end
......
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe User do describe User do
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
include ProjectForksHelper
describe 'modules' do describe 'modules' do
subject { described_class } subject { described_class }
...@@ -1431,7 +1432,7 @@ describe User do ...@@ -1431,7 +1432,7 @@ describe User do
describe "#contributed_projects" do describe "#contributed_projects" do
subject { create(:user) } subject { create(:user) }
let!(:project1) { create(:project) } let!(:project1) { create(:project) }
let!(:project2) { create(:project, forked_from_project: project3) } let!(:project2) { fork_project(project3) }
let!(:project3) { create(:project) } let!(:project3) { create(:project) }
let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) } let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) }
let!(:push_event) { create(:push_event, project: project1, author: subject) } let!(:push_event) { create(:push_event, project: project1, author: subject) }
......
require "spec_helper" require "spec_helper"
describe API::MergeRequests do describe API::MergeRequests do
include ProjectForksHelper
let(:base_time) { Time.now } let(:base_time) { Time.now }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
...@@ -616,17 +618,17 @@ describe API::MergeRequests do ...@@ -616,17 +618,17 @@ describe API::MergeRequests do
context 'forked projects' do context 'forked projects' do
let!(:user2) { create(:user) } let!(:user2) { create(:user) }
let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) } let!(:forked_project) { fork_project(project, user2) }
let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) } let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) }
before do before do
fork_project.add_reporter(user2) forked_project.add_reporter(user2)
allow_any_instance_of(MergeRequest).to receive(:write_ref) allow_any_instance_of(MergeRequest).to receive(:write_ref)
end end
it "returns merge_request" do it "returns merge_request" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
...@@ -635,10 +637,10 @@ describe API::MergeRequests do ...@@ -635,10 +637,10 @@ describe API::MergeRequests do
end end
it "does not return 422 when source_branch equals target_branch" do it "does not return 422 when source_branch equals target_branch" do
expect(project.id).not_to eq(fork_project.id) expect(project.id).not_to eq(forked_project.id)
expect(fork_project.forked?).to be_truthy expect(forked_project.forked?).to be_truthy
expect(fork_project.forked_from_project).to eq(project) expect(forked_project.forked_from_project).to eq(project)
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
...@@ -647,7 +649,7 @@ describe API::MergeRequests do ...@@ -647,7 +649,7 @@ describe API::MergeRequests do
it 'returns 422 when target project has disabled merge requests' do it 'returns 422 when target project has disabled merge requests' do
project.project_feature.update(merge_requests_access_level: 0) project.project_feature.update(merge_requests_access_level: 0)
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test', title: 'Test',
target_branch: 'master', target_branch: 'master',
source_branch: 'markdown', source_branch: 'markdown',
...@@ -658,26 +660,26 @@ describe API::MergeRequests do ...@@ -658,26 +660,26 @@ describe API::MergeRequests do
end end
it "returns 400 when source_branch is missing" do it "returns 400 when source_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when target_branch is missing" do it "returns 400 when target_branch is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when title is missing" do it "returns 400 when title is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
context 'when target_branch is specified' do context 'when target_branch is specified' do
it 'returns 422 if targeting a different fork' do it 'returns 422 if targeting a different fork' do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', title: 'Test merge_request',
target_branch: 'master', target_branch: 'master',
source_branch: 'markdown', source_branch: 'markdown',
...@@ -688,8 +690,8 @@ describe API::MergeRequests do ...@@ -688,8 +690,8 @@ describe API::MergeRequests do
end end
it "returns 201 when target_branch is specified and for the same project" do it "returns 201 when target_branch is specified and for the same project" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: forked_project.id
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
end end
end end
......
...@@ -64,9 +64,12 @@ describe API::Projects do ...@@ -64,9 +64,12 @@ describe API::Projects do
create(:project, :public) create(:project, :public)
end end
# TODO: We're currently querying to detect if a project is a fork
# in 2 ways. Lower this back to 8 when `ForkedProjectLink` relation is
# removed
expect do expect do
get api('/projects', current_user) get api('/projects', current_user)
end.not_to exceed_query_limit(control).with_threshold(8) end.not_to exceed_query_limit(control).with_threshold(9)
end end
end end
......
require "spec_helper" require "spec_helper"
describe API::MergeRequests do describe API::MergeRequests do
include ProjectForksHelper
let(:base_time) { Time.now } let(:base_time) { Time.now }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
...@@ -312,17 +314,17 @@ describe API::MergeRequests do ...@@ -312,17 +314,17 @@ describe API::MergeRequests do
context 'forked projects' do context 'forked projects' do
let!(:user2) { create(:user) } let!(:user2) { create(:user) }
let!(:fork_project) { create(:project, forked_from_project: project, namespace: user2.namespace, creator_id: user2.id) } let!(:forked_project) { fork_project(project, user2) }
let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) } let!(:unrelated_project) { create(:project, namespace: create(:user).namespace, creator_id: user2.id) }
before do before do
fork_project.add_reporter(user2) forked_project.add_reporter(user2)
allow_any_instance_of(MergeRequest).to receive(:write_ref) allow_any_instance_of(MergeRequest).to receive(:write_ref)
end end
it "returns merge_request" do it "returns merge_request" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master", title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
...@@ -331,10 +333,10 @@ describe API::MergeRequests do ...@@ -331,10 +333,10 @@ describe API::MergeRequests do
end end
it "does not return 422 when source_branch equals target_branch" do it "does not return 422 when source_branch equals target_branch" do
expect(project.id).not_to eq(fork_project.id) expect(project.id).not_to eq(forked_project.id)
expect(fork_project.forked?).to be_truthy expect(forked_project.forked?).to be_truthy
expect(fork_project.forked_from_project).to eq(project) expect(forked_project.forked_from_project).to eq(project)
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', source_branch: "master", target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
...@@ -343,7 +345,7 @@ describe API::MergeRequests do ...@@ -343,7 +345,7 @@ describe API::MergeRequests do
it "returns 422 when target project has disabled merge requests" do it "returns 422 when target project has disabled merge requests" do
project.project_feature.update(merge_requests_access_level: 0) project.project_feature.update(merge_requests_access_level: 0)
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test', title: 'Test',
target_branch: "master", target_branch: "master",
source_branch: 'markdown', source_branch: 'markdown',
...@@ -354,26 +356,26 @@ describe API::MergeRequests do ...@@ -354,26 +356,26 @@ describe API::MergeRequests do
end end
it "returns 400 when source_branch is missing" do it "returns 400 when source_branch is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when target_branch is missing" do it "returns 400 when target_branch is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id title: 'Test merge_request', target_branch: "master", author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
it "returns 400 when title is missing" do it "returns 400 when title is missing" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
context 'when target_branch is specified' do context 'when target_branch is specified' do
it 'returns 422 if targeting a different fork' do it 'returns 422 if targeting a different fork' do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', title: 'Test merge_request',
target_branch: 'master', target_branch: 'master',
source_branch: 'markdown', source_branch: 'markdown',
...@@ -384,8 +386,8 @@ describe API::MergeRequests do ...@@ -384,8 +386,8 @@ describe API::MergeRequests do
end end
it "returns 201 when target_branch is specified and for the same project" do it "returns 201 when target_branch is specified and for the same project" do
post v3_api("/projects/#{fork_project.id}/merge_requests", user2), post v3_api("/projects/#{forked_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: forked_project.id
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
end end
end end
......
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Git LFS API and storage' do describe 'Git LFS API and storage' do
include WorkhorseHelpers include WorkhorseHelpers
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:lfs_object) { create(:lfs_object, :with_file) } let!(:lfs_object) { create(:lfs_object, :with_file) }
...@@ -1173,11 +1174,6 @@ describe 'Git LFS API and storage' do ...@@ -1173,11 +1174,6 @@ describe 'Git LFS API and storage' do
ActionController::HttpAuthentication::Basic.encode_credentials(user.username, Gitlab::LfsToken.new(user).token) ActionController::HttpAuthentication::Basic.encode_credentials(user.username, Gitlab::LfsToken.new(user).token)
end end
def fork_project(project, user, object = nil)
allow(RepositoryForkWorker).to receive(:perform_async).and_return(true)
Projects::ForkService.new(project, user, {}).execute
end
def post_lfs_json(url, body = nil, headers = nil) def post_lfs_json(url, body = nil, headers = nil)
post(url, body.try(:to_json), (headers || {}).merge('Content-Type' => 'application/vnd.git-lfs+json')) post(url, body.try(:to_json), (headers || {}).merge('Content-Type' => 'application/vnd.git-lfs+json'))
end end
......
require 'spec_helper' require 'spec_helper'
describe BuildDetailsEntity do describe BuildDetailsEntity do
include ProjectForksHelper
set(:user) { create(:admin) } set(:user) { create(:admin) }
it 'inherits from JobEntity' do it 'inherits from JobEntity' do
...@@ -56,18 +58,16 @@ describe BuildDetailsEntity do ...@@ -56,18 +58,16 @@ describe BuildDetailsEntity do
end end
context 'when merge request is from a fork' do context 'when merge request is from a fork' do
let(:fork_project) do let(:forked_project) { fork_project(project) }
create(:project, forked_from_project: project)
end
let(:pipeline) { create(:ci_pipeline, project: fork_project) } let(:pipeline) { create(:ci_pipeline, project: forked_project) }
before do before do
allow(build).to receive(:merge_request).and_return(merge_request) allow(build).to receive(:merge_request).and_return(merge_request)
end end
let(:merge_request) do let(:merge_request) do
create(:merge_request, source_project: fork_project, create(:merge_request, source_project: forked_project,
target_project: project, target_project: project,
source_branch: build.ref) source_branch: build.ref)
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::CreatePipelineService do describe Ci::CreatePipelineService do
include ProjectForksHelper
set(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
let(:user) { create(:admin) } let(:user) { create(:admin) }
let(:ref_name) { 'refs/heads/master' } let(:ref_name) { 'refs/heads/master' }
...@@ -82,13 +84,9 @@ describe Ci::CreatePipelineService do ...@@ -82,13 +84,9 @@ describe Ci::CreatePipelineService do
end end
context 'when merge request target project is different from source project' do context 'when merge request target project is different from source project' do
let!(:project) { fork_project(target_project, nil, repository: true) }
let!(:target_project) { create(:project, :repository) } let!(:target_project) { create(:project, :repository) }
let!(:forked_project_link) do
create(:forked_project_link, forked_to_project: project,
forked_from_project: target_project)
end
it 'updates head pipeline for merge request' do it 'updates head pipeline for merge request' do
merge_request = create(:merge_request, source_branch: 'master', merge_request = create(:merge_request, source_branch: 'master',
target_branch: "branch_1", target_branch: "branch_1",
......
require 'spec_helper' require 'spec_helper'
describe DeleteMergedBranchesService do describe DeleteMergedBranchesService do
include ProjectForksHelper
subject(:service) { described_class.new(project, project.owner) } subject(:service) { described_class.new(project, project.owner) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
...@@ -50,9 +52,9 @@ describe DeleteMergedBranchesService do ...@@ -50,9 +52,9 @@ describe DeleteMergedBranchesService do
context 'open merge requests' do context 'open merge requests' do
it 'does not delete branches from open merge requests' do it 'does not delete branches from open merge requests' do
fork_link = create(:forked_project_link, forked_from_project: project) forked_project = fork_project(project)
create(:merge_request, :opened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master') create(:merge_request, :opened, source_project: project, target_project: project, source_branch: 'branch-merged', target_branch: 'master')
create(:merge_request, :opened, source_project: fork_link.forked_to_project, target_project: project, target_branch: 'improve/awesome', source_branch: 'master') create(:merge_request, :opened, source_project: forked_project, target_project: project, target_branch: 'improve/awesome', source_branch: 'master')
service.execute service.execute
......
require 'spec_helper' require 'spec_helper'
describe MergeRequests::Conflicts::ResolveService do describe MergeRequests::Conflicts::ResolveService do
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :public, :repository) }
let(:fork_project) do let(:forked_project) do
create(:forked_project_with_submodules) do |fork_project| forked_project = fork_project(project, user)
fork_project.build_forked_project_link(forked_to_project_id: fork_project.id, forked_from_project_id: project.id) TestEnv.copy_repo(forked_project,
fork_project.save bare_repo: TestEnv.forked_repo_path_bare,
end refs: TestEnv::FORKED_BRANCH_SHA)
forked_project
end end
let(:merge_request) do let(:merge_request) do
...@@ -19,7 +21,7 @@ describe MergeRequests::Conflicts::ResolveService do ...@@ -19,7 +21,7 @@ describe MergeRequests::Conflicts::ResolveService do
let(:merge_request_from_fork) do let(:merge_request_from_fork) do
create(:merge_request, create(:merge_request,
source_branch: 'conflict-resolvable-fork', source_project: fork_project, source_branch: 'conflict-resolvable-fork', source_project: forked_project,
target_branch: 'conflict-start', target_project: project) target_branch: 'conflict-start', target_project: project)
end end
...@@ -114,7 +116,7 @@ describe MergeRequests::Conflicts::ResolveService do ...@@ -114,7 +116,7 @@ describe MergeRequests::Conflicts::ResolveService do
end end
it 'gets conflicts from the source project' do it 'gets conflicts from the source project' do
expect(fork_project.repository.rugged).to receive(:merge_commits).and_call_original expect(forked_project.repository.rugged).to receive(:merge_commits).and_call_original
expect(project.repository.rugged).not_to receive(:merge_commits) expect(project.repository.rugged).not_to receive(:merge_commits)
resolve_conflicts resolve_conflicts
......
require "spec_helper" require "spec_helper"
describe MergeRequests::GetUrlsService do describe MergeRequests::GetUrlsService do
include ProjectForksHelper
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:service) { described_class.new(project) } let(:service) { described_class.new(project) }
let(:source_branch) { "merge-test" } let(:source_branch) { "merge-test" }
...@@ -85,7 +87,7 @@ describe MergeRequests::GetUrlsService do ...@@ -85,7 +87,7 @@ describe MergeRequests::GetUrlsService do
context 'pushing to existing branch from forked project' do context 'pushing to existing branch from forked project' do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:forked_project) { Projects::ForkService.new(project, user).execute } let!(:forked_project) { fork_project(project, user, repository: true) }
let!(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project, source_branch: source_branch) } let!(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project, source_branch: source_branch) }
let(:changes) { existing_branch_changes } let(:changes) { existing_branch_changes }
# Source project is now the forked one # Source project is now the forked one
......
require 'spec_helper' require 'spec_helper'
describe MergeRequests::RefreshService do describe MergeRequests::RefreshService do
include ProjectForksHelper
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:service) { described_class } let(:service) { described_class }
...@@ -12,7 +14,8 @@ describe MergeRequests::RefreshService do ...@@ -12,7 +14,8 @@ describe MergeRequests::RefreshService do
group.add_owner(@user) group.add_owner(@user)
@project = create(:project, :repository, namespace: group) @project = create(:project, :repository, namespace: group)
@fork_project = Projects::ForkService.new(@project, @user).execute @fork_project = fork_project(@project, @user, repository: true)
@merge_request = create(:merge_request, @merge_request = create(:merge_request,
source_project: @project, source_project: @project,
source_branch: 'master', source_branch: 'master',
...@@ -311,8 +314,7 @@ describe MergeRequests::RefreshService do ...@@ -311,8 +314,7 @@ describe MergeRequests::RefreshService do
context 'when the merge request is sourced from a different project' do context 'when the merge request is sourced from a different project' do
it 'creates a `MergeRequestsClosingIssues` record for each issue closed by a commit' do it 'creates a `MergeRequestsClosingIssues` record for each issue closed by a commit' do
forked_project = create(:project, :repository) forked_project = fork_project(@project, @user, repository: true)
create(:forked_project_link, forked_to_project: forked_project, forked_from_project: @project)
merge_request = create(:merge_request, merge_request = create(:merge_request,
target_branch: 'master', target_branch: 'master',
......
require 'spec_helper' require 'spec_helper'
describe Projects::ForkService do describe Projects::ForkService do
include ProjectForksHelper
let(:gitlab_shell) { Gitlab::Shell.new } let(:gitlab_shell) { Gitlab::Shell.new }
describe 'fork by user' do describe 'fork by user' do
...@@ -33,7 +34,7 @@ describe Projects::ForkService do ...@@ -33,7 +34,7 @@ describe Projects::ForkService do
end end
describe "successfully creates project in the user namespace" do describe "successfully creates project in the user namespace" do
let(:to_project) { fork_project(@from_project, @to_user) } let(:to_project) { fork_project(@from_project, @to_user, namespace: @to_user.namespace) }
it { expect(to_project).to be_persisted } it { expect(to_project).to be_persisted }
it { expect(to_project.errors).to be_empty } it { expect(to_project.errors).to be_empty }
...@@ -93,7 +94,7 @@ describe Projects::ForkService do ...@@ -93,7 +94,7 @@ describe Projects::ForkService do
context 'project already exists' do context 'project already exists' do
it "fails due to validation, not transaction failure" do it "fails due to validation, not transaction failure" do
@existing_project = create(:project, :repository, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace) @existing_project = create(:project, :repository, creator_id: @to_user.id, name: @from_project.name, namespace: @to_namespace)
@to_project = fork_project(@from_project, @to_user) @to_project = fork_project(@from_project, @to_user, namespace: @to_namespace)
expect(@existing_project).to be_persisted expect(@existing_project).to be_persisted
expect(@to_project).not_to be_persisted expect(@to_project).not_to be_persisted
...@@ -115,7 +116,7 @@ describe Projects::ForkService do ...@@ -115,7 +116,7 @@ describe Projects::ForkService do
end end
it 'does not allow creation' do it 'does not allow creation' do
to_project = fork_project(@from_project, @to_user) to_project = fork_project(@from_project, @to_user, namespace: @to_user.namespace)
expect(to_project).not_to be_persisted expect(to_project).not_to be_persisted
expect(to_project.errors.messages).to have_key(:base) expect(to_project.errors.messages).to have_key(:base)
...@@ -209,9 +210,4 @@ describe Projects::ForkService do ...@@ -209,9 +210,4 @@ describe Projects::ForkService do
end end
end end
end end
def fork_project(from_project, user, params = {})
allow(RepositoryForkWorker).to receive(:perform_async).and_return(true)
Projects::ForkService.new(from_project, user, params).execute
end
end end
require 'spec_helper' require 'spec_helper'
describe Projects::UpdateService, '#execute' do describe Projects::UpdateService, '#execute' do
include ProjectForksHelper
let(:gitlab_shell) { Gitlab::Shell.new } let(:gitlab_shell) { Gitlab::Shell.new }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
...@@ -76,13 +78,7 @@ describe Projects::UpdateService, '#execute' do ...@@ -76,13 +78,7 @@ describe Projects::UpdateService, '#execute' do
describe 'when updating project that has forks' do describe 'when updating project that has forks' do
let(:project) { create(:project, :internal) } let(:project) { create(:project, :internal) }
let(:forked_project) { create(:forked_project_with_submodules, :internal) } let(:forked_project) { fork_project(project) }
before do
forked_project.build_forked_project_link(forked_to_project_id: forked_project.id,
forked_from_project_id: project.id)
forked_project.save
end
it 'updates forks visibility level when parent set to more restrictive' do it 'updates forks visibility level when parent set to more restrictive' do
opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE } opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE }
......
module ProjectForksHelper
def fork_project(project, user = nil, params = {})
# Load the `fork_network` for the project to fork as there might be one that
# wasn't loaded yet.
project.reload unless project.fork_network
unless user
user = create(:user)
project.add_developer(user)
end
unless params[:namespace] || params[:namespace_id]
params[:namespace] = create(:group)
params[:namespace].add_owner(user)
end
service = Projects::ForkService.new(project, user, params)
create_repository = params.delete(:repository)
# Avoid creating a repository
unless create_repository
allow(RepositoryForkWorker).to receive(:perform_async).and_return(true)
shell = double('gitlab_shell', fork_repository: true)
allow(service).to receive(:gitlab_shell).and_return(shell)
end
forked_project = service.execute
# Reload the both projects so they know about their newly created fork_network
if forked_project.persisted?
project.reload
forked_project.reload
end
if create_repository
# The call to project.repository.after_import in RepositoryForkWorker does
# not reset the @exists variable of this forked_project.repository
# so we have to explicitely call this method to clear the @exists variable.
# of the instance we're returning here.
forked_project.repository.after_import
# We can't leave the hooks in place after a fork, as those would fail in tests
# The "internal" API is not available
FileUtils.rm_rf("#{forked_project.repository.path}/hooks")
end
forked_project
end
def fork_project_with_submodules(project, user = nil, params = {})
forked_project = fork_project(project, user, params)
TestEnv.copy_repo(forked_project,
bare_repo: TestEnv.forked_repo_path_bare,
refs: TestEnv::FORKED_BRANCH_SHA)
forked_project
end
end
...@@ -2,10 +2,11 @@ require 'spec_helper' ...@@ -2,10 +2,11 @@ require 'spec_helper'
describe 'projects/merge_requests/_commits.html.haml' do describe 'projects/merge_requests/_commits.html.haml' do
include Devise::Test::ControllerHelpers include Devise::Test::ControllerHelpers
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:target_project) { create(:project, :repository) } let(:target_project) { create(:project, :public, :repository) }
let(:source_project) { create(:project, :repository, forked_from_project: target_project) } let(:source_project) { fork_project(target_project, user, repository: true) }
let(:merge_request) do let(:merge_request) do
create(:merge_request, :simple, create(:merge_request, :simple,
......
...@@ -2,16 +2,19 @@ require 'spec_helper' ...@@ -2,16 +2,19 @@ require 'spec_helper'
describe 'projects/merge_requests/edit.html.haml' do describe 'projects/merge_requests/edit.html.haml' do
include Devise::Test::ControllerHelpers include Devise::Test::ControllerHelpers
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) } let(:forked_project) { fork_project(project, user, repository: true) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) } let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
let(:milestone) { create(:milestone, project: project) } let(:milestone) { create(:milestone, project: project) }
let(:closed_merge_request) do let(:closed_merge_request) do
project.add_developer(user)
create(:closed_merge_request, create(:closed_merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project, target_project: project,
author: user, author: user,
assignee: user, assignee: user,
......
...@@ -2,16 +2,17 @@ require 'spec_helper' ...@@ -2,16 +2,17 @@ require 'spec_helper'
describe 'projects/merge_requests/show.html.haml' do describe 'projects/merge_requests/show.html.haml' do
include Devise::Test::ControllerHelpers include Devise::Test::ControllerHelpers
include ProjectForksHelper
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :public, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) } let(:forked_project) { fork_project(project, user, repository: true) }
let(:unlink_project) { Projects::UnlinkForkService.new(fork_project, user) } let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
let(:note) { create(:note_on_merge_request, project: project, noteable: closed_merge_request) } let(:note) { create(:note_on_merge_request, project: project, noteable: closed_merge_request) }
let(:closed_merge_request) do let(:closed_merge_request) do
create(:closed_merge_request, create(:closed_merge_request,
source_project: fork_project, source_project: forked_project,
target_project: project, target_project: project,
author: user) author: user)
end end
...@@ -52,7 +53,7 @@ describe 'projects/merge_requests/show.html.haml' do ...@@ -52,7 +53,7 @@ describe 'projects/merge_requests/show.html.haml' do
context 'when the merge request is open' do context 'when the merge request is open' do
it 'closes the merge request if the source project does not exist' do it 'closes the merge request if the source project does not exist' do
closed_merge_request.update_attributes(state: 'open') closed_merge_request.update_attributes(state: 'open')
fork_project.destroy forked_project.destroy
render render
......
require 'spec_helper' require 'spec_helper'
describe NamespacelessProjectDestroyWorker do describe NamespacelessProjectDestroyWorker do
include ProjectForksHelper
subject { described_class.new } subject { described_class.new }
before do before do
...@@ -55,9 +57,11 @@ describe NamespacelessProjectDestroyWorker do ...@@ -55,9 +57,11 @@ describe NamespacelessProjectDestroyWorker do
context 'project forked from another' do context 'project forked from another' do
let!(:parent_project) { create(:project) } let!(:parent_project) { create(:project) }
let(:project) do
before do namespaceless_project = fork_project(parent_project)
create(:forked_project_link, forked_to_project: project, forked_from_project: parent_project) namespaceless_project.namespace_id = nil
namespaceless_project.save(validate: false)
namespaceless_project
end end
it 'closes open merge requests' do it 'closes open merge requests' do
......
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