diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2016-09-07 17:56:11 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2016-09-07 17:56:11 +0300 |
commit | 084bac8935f6532d28db71fbf14e68d9060337e8 (patch) | |
tree | 5ebca87f93b71c94359e199e33b1619a4a6c519e /spec/models/repository_spec.rb | |
parent | 0f08bb86d8731edd40f9348335987f55a4ba9f11 (diff) |
Express intentions as expectations
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r-- | spec/models/repository_spec.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index bc899027d6b..7624050878e 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -475,7 +475,14 @@ describe Repository, models: true do context 'when the update adds more than one commit' do it 'runs without errors' do - old_rev = '33f3729a45c02fc67d00adb1b8bca394b0e761d9' # ancestor of new_rev by more than one commit + old_rev = '33f3729a45c02fc67d00adb1b8bca394b0e761d9' + + # old_rev is an ancestor of new_rev + expect(repository.rugged.merge_base(old_rev, new_rev)).to eq(old_rev) + + # old_rev is not a direct ancestor (parent) of new_rev + expect(repository.rugged.lookup(new_rev).parent_ids).not_to include(old_rev) + branch = 'feature-ff-target' repository.add_branch(user, branch, old_rev) @@ -485,10 +492,17 @@ describe Repository, models: true do context 'when the update would remove commits from the target branch' do it 'raises an exception' do - # We use the fact that 'master' has diverged from 'feature' (new_rev): - # updating 'master' to new_rev would make us lose commits, which should - # not happen. - expect { repository.update_branch_with_hooks(user, 'master') { new_rev } }.to raise_error(Repository::CommitError) + branch = 'master' + old_rev = repository.find_branch(branch).target.sha + + # The 'master' branch is NOT an ancestor of new_rev. + expect(repository.rugged.merge_base(old_rev, new_rev)).not_to eq(old_rev) + + # Updating 'master' to new_rev would lose the commits on 'master' that + # are not contained in new_rev. This should not be allowed. + expect do + repository.update_branch_with_hooks(user, branch) { new_rev } + end.to raise_error(Repository::CommitError) end end |