Commit 872b3b61 authored by Abhishek Kumar's avatar Abhishek Kumar

Added spec for context_commits_diff model and entity

parent f9643949
......@@ -32,8 +32,8 @@ class ContextCommitsDiff
def diff_refs
Gitlab::Diff::DiffRefs.new(
base_sha: commits.last.diff_refs.base_sha,
head_sha: commits.first.diff_refs.head_sha
base_sha: commits.last&.diff_refs&.base_sha,
head_sha: commits.first&.diff_refs&.head_sha
)
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ContextCommitsDiff do
let(:merge_request_context_commit_diff_file) { create(:merge_request_context_commit_diff_file) }
let(:merge_request) { merge_request_context_commit_diff_file.merge_request_context_commit.merge_request }
let(:context_commits_diff) { merge_request.context_commits_diff }
subject { context_commits_diff }
describe '.commits_count' do
it 'reports commits count' do
expect(subject.commits_count).to be(1)
end
end
describe '.raw_diffs' do
it 'returns instance of Gitlab::Git::DiffCollection' do
expect(subject.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ContextCommitsDiffEntity do
let(:merge_request_context_commit_diff_file) { create(:merge_request_context_commit_diff_file) }
let(:merge_request) { merge_request_context_commit_diff_file.merge_request_context_commit.merge_request }
let(:context_commits_diff) { merge_request.context_commits_diff }
context 'as json' do
describe '.diff_files' do
it 'returns diff files metadata' do
payload = ContextCommitsDiffEntity.represent(context_commits_diff).as_json
expect(payload[:commits_count]).to eq(1)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment