diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-09-28 16:38:12 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-07 11:46:23 +0200 |
commit | d328007214786c7137c31d2c73e9ee76b025e6ed (patch) | |
tree | fe4ec118148b7397890f86c6b2982ce667086c38 /spec/models | |
parent | 20727db1702849b78e6714197f16f602f68cecf8 (diff) | |
download | gitlab-ce-d328007214786c7137c31d2c73e9ee76b025e6ed.tar.gz |
Create a fork network when forking a project
When no fork network exists for the source projects, we create a new
one with the correct source
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/fork_network_member_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/fork_network_spec.rb | 43 |
2 files changed, 48 insertions, 3 deletions
diff --git a/spec/models/fork_network_member_spec.rb b/spec/models/fork_network_member_spec.rb new file mode 100644 index 00000000000..532ca1fca8c --- /dev/null +++ b/spec/models/fork_network_member_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe ForkNetworkMember do + describe 'validations' do + it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:fork_network) } + end +end diff --git a/spec/models/fork_network_spec.rb b/spec/models/fork_network_spec.rb index b7758a0fbb5..4781a959846 100644 --- a/spec/models/fork_network_spec.rb +++ b/spec/models/fork_network_spec.rb @@ -1,5 +1,42 @@ -require 'rails_helper' +require 'spec_helper' -RSpec.describe ForkNetwork, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +describe ForkNetwork do + include ProjectForksHelper + + describe '#add_root_as_member' do + it 'adds the root project as a member when creating a new root network' do + project = create(:project) + fork_network = described_class.create(root_project: project) + + expect(fork_network.projects).to include(project) + end + end + + context 'for a deleted project' do + it 'keeps the fork network' do + project = create(:project, :public) + forked = fork_project(project) + project.destroy! + + fork_network = forked.reload.fork_network + + expect(fork_network.projects).to contain_exactly(forked) + expect(fork_network.root_project).to be_nil + end + + it 'allows multiple fork networks where the root project is deleted' do + first_project = create(:project) + second_project = create(:project) + first_fork = fork_project(first_project) + second_fork = fork_project(second_project) + + first_project.destroy + second_project.destroy + + expect(first_fork.fork_network).not_to be_nil + expect(first_fork.fork_network.root_project).to be_nil + expect(second_fork.fork_network).not_to be_nil + expect(second_fork.fork_network.root_project).to be_nil + end + end end |