summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-12-10 00:40:23 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-12-10 00:40:23 +0800
commitbb9d30590d4ca5b25d5020234916ce961acf15b6 (patch)
tree22eb73a17b42b86fbe2cc24f1429a4a8af2f76f1 /spec/models
parent5a115671b9d7c22daf8160d7284786d0f8b216cb (diff)
downloadgitlab-ce-bb9d30590d4ca5b25d5020234916ce961acf15b6.tar.gz
Pass source_commit so that we save a few lookups
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/repository_spec.rb28
1 files changed, 23 insertions, 5 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 9cc13a9a25b..a61d7f0c76d 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -257,6 +257,24 @@ describe Repository, models: true do
expect(newdir.path).to eq('newdir')
end
+ context "when committing to another project" do
+ let(:forked_project) { create(:project) }
+
+ it "creates a fork and commit to the forked project" do
+ expect do
+ repository.commit_dir(user, 'newdir',
+ message: 'Create newdir', branch_name: 'patch',
+ source_branch_name: 'master', source_project: forked_project)
+ end.to change { repository.commits('master').count }.by(0)
+
+ expect(repository.branch_exists?('patch')).to be_truthy
+ expect(forked_project.repository.branch_exists?('patch')).to be_falsy
+
+ newdir = repository.tree('patch', 'newdir')
+ expect(newdir.path).to eq('newdir')
+ end
+ end
+
context "when an author is specified" do
it "uses the given email/name to set the commit's author" do
expect do
@@ -758,9 +776,9 @@ describe Repository, models: true do
end
context 'when the update adds more than one commit' do
- it 'runs without errors' do
- old_rev = '33f3729a45c02fc67d00adb1b8bca394b0e761d9'
+ let(:old_rev) { '33f3729a45c02fc67d00adb1b8bca394b0e761d9' }
+ it 'runs without errors' do
# old_rev is an ancestor of new_rev
expect(repository.rugged.merge_base(old_rev, new_rev)).to eq(old_rev)
@@ -779,10 +797,10 @@ describe Repository, models: true do
end
context 'when the update would remove commits from the target branch' do
- it 'raises an exception' do
- branch = 'master'
- old_rev = repository.find_branch(branch).dereferenced_target.sha
+ let(:branch) { 'master' }
+ let(:old_rev) { repository.find_branch(branch).dereferenced_target.sha }
+ it 'raises an exception' do
# The 'master' branch is NOT an ancestor of new_rev.
expect(repository.rugged.merge_base(old_rev, new_rev)).not_to eq(old_rev)