diff options
Diffstat (limited to 'spec/models/merge_request_diff_spec.rb')
-rw-r--r-- | spec/models/merge_request_diff_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index bf9af73fe1b..806ce3f21b5 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -51,6 +51,7 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do it { expect(subject.head_commit_sha).to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0') } it { expect(subject.base_commit_sha).to eq('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') } it { expect(subject.start_commit_sha).to eq('0b4bc9a49b562e85de7cc9e834518ea6828729b9') } + it { expect(subject.patch_id_sha).to eq('1e05e04d4c2a6414d9d4ab38208511a3bbe715f2') } context 'when diff_type is merge_head' do let_it_be(:merge_request) { create(:merge_request) } @@ -703,6 +704,39 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do end end + describe "#set_patch_id_sha" do + let(:mr_diff) { create(:merge_request).merge_request_diff } + + it "sets the patch_id_sha attribute" do + expect(mr_diff.set_patch_id_sha).not_to be_nil + end + + context "when base_commit_sha is nil" do + it "records patch_id_sha as nil" do + expect(mr_diff).to receive(:base_commit_sha).and_return(nil) + + expect(mr_diff.set_patch_id_sha).to be_nil + end + end + + context "when head_commit_sha is nil" do + it "records patch_id_sha as nil" do + expect(mr_diff).to receive(:head_commit_sha).and_return(nil) + + expect(mr_diff.set_patch_id_sha).to be_nil + end + end + + context "when head_commit_sha and base_commit_sha match" do + it "records patch_id_sha as nil" do + expect(mr_diff).to receive(:base_commit_sha).at_least(:once).and_return("abc123") + expect(mr_diff).to receive(:head_commit_sha).at_least(:once).and_return("abc123") + + expect(mr_diff.set_patch_id_sha).to be_nil + end + end + end + describe '#save_diffs' do it 'saves collected state' do mr_diff = create(:merge_request).merge_request_diff |