diff options
author | Nick Thomas <nick@gitlab.com> | 2017-07-04 13:48:25 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2017-07-04 14:02:29 +0300 |
commit | 1501a4f578fa947af66a981fd56885be8467d5b5 (patch) | |
tree | ea5a4a32beb4986105e13e03e09a0e2c6c28a710 /spec/models/forked_project_link_spec.rb | |
parent | 75ac425c94d1763088040ff526b590f5ffe03f85 (diff) |
Clean up the ForkedProjectLink specs
Diffstat (limited to 'spec/models/forked_project_link_spec.rb')
-rw-r--r-- | spec/models/forked_project_link_spec.rb | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 6e8d43f988c..4fd250bd4c6 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -2,53 +2,59 @@ require 'spec_helper' describe ForkedProjectLink, "add link on fork" do let(:project_from) { create(:project, :repository) } + let(:project_to) { fork_project(project_from, user) } let(:user) { create(:user) } let(:namespace) { user.namespace } before do - create(:project_member, :reporter, user: user, project: project_from) - @project_to = fork_project(project_from, user) + project_from.add_reporter(user) + end + + it 'project_from knows its forks' do + _ = project_to + + expect(project_from.forks.count).to eq(1) end it "project_to knows it is forked" do - expect(@project_to.forked?).to be_truthy + expect(project_to.forked?).to be_truthy end it "project knows who it is forked from" do - expect(@project_to.forked_from_project).to eq(project_from) + expect(project_to.forked_from_project).to eq(project_from) end -end -describe '#forked?' do - let(:forked_project_link) { build(:forked_project_link) } - let(:project_from) { create(:project, :repository) } - let(:project_to) { create(:project, forked_project_link: forked_project_link) } + describe '#forked?' do + let(:project_to) { create(:project, forked_project_link: forked_project_link) } + let(:forked_project_link) { build(:forked_project_link) } - before :each do - forked_project_link.forked_from_project = project_from - forked_project_link.forked_to_project = project_to - forked_project_link.save! - end + before do + forked_project_link.forked_from_project = project_from + forked_project_link.forked_to_project = project_to + forked_project_link.save! + end - it "project_to knows it is forked" do - expect(project_to.forked?).to be_truthy - end + it "project_to knows it is forked" do + expect(project_to.forked?).to be_truthy + end - it "project_from is not forked" do - expect(project_from.forked?).to be_falsey - end + it "project_from is not forked" do + expect(project_from.forked?).to be_falsey + end - it "project_to.destroy destroys fork_link" do - expect(forked_project_link).to receive(:destroy) - project_to.destroy + it "project_to.destroy destroys fork_link" do + expect(forked_project_link).to receive(:destroy) + + project_to.destroy + end end -end -def fork_project(from_project, user) - shell = double('gitlab_shell', fork_repository: true) + def fork_project(from_project, user) + service = Projects::ForkService.new(from_project, user) + shell = double('gitlab_shell', fork_repository: true) - service = Projects::ForkService.new(from_project, user) - allow(service).to receive(:gitlab_shell).and_return(shell) + allow(service).to receive(:gitlab_shell).and_return(shell) - service.execute + service.execute + end end |