summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorPierre de La Morinerie <kemenaran@gmail.com>2016-03-09 07:51:52 +0100
committerPierre de La Morinerie <kemenaran@gmail.com>2016-03-16 13:56:47 +0100
commit7cbf8fd0d089264f863dc01217514d7e2c40e056 (patch)
treee1597b0f1e8015bdad13323dfb8b215e873b08e2 /spec/models
parenta34021cd182af49fc732c4ad58f7594f73c46f01 (diff)
downloadgitlab-ce-7cbf8fd0d089264f863dc01217514d7e2c40e056.tar.gz
Add tests for MergeRequest#source_sha
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/merge_request_spec.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 8bf68013fd2..aceb2406eb3 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -86,6 +86,24 @@ describe MergeRequest, models: true do
end
end
+ describe '#source_sha' do
+ let(:last_branch_commit) { subject.source_project.repository.commit(subject.source_branch) }
+
+ context 'with diffs' do
+ subject { create(:merge_request, :with_diffs) }
+ it 'returns the sha of the source branch last commit' do
+ expect(subject.source_sha).to eq(last_branch_commit.sha)
+ end
+ end
+
+ context 'when the merge request is being created' do
+ subject { build(:merge_request, source_branch: nil, compare_commits: []) }
+ it 'returns nil' do
+ expect(subject.source_sha).to be_nil
+ end
+ end
+ end
+
describe '#to_reference' do
it 'returns a String reference to the object' do
expect(subject.to_reference).to eq "!#{subject.iid}"