Commit 5dab4ac8 authored by Abhishek Kumar's avatar Abhishek Kumar

Improve test coverage

parent 872b3b61
......@@ -3,21 +3,62 @@
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 }
let(:sha1) { "33f3729a45c02fc67d00adb1b8bca394b0e761d9" }
let(:sha2) { "ae73cb07c9eeaf35924a10f713b364d32b2dd34f" }
let(:sha3) { "0b4bc9a49b562e85de7cc9e834518ea6828729b9" }
subject { context_commits_diff }
let(:merge_request) do
create(:merge_request) do |merge_request|
project = merge_request.project
mrcc1 = create(:merge_request_context_commit, sha: sha1, committed_date: project.commit_by(oid: sha1).committed_date)
mrcc2 = create(:merge_request_context_commit, sha: sha2, committed_date: project.commit_by(oid: sha2).committed_date)
mrcc3 = create(:merge_request_context_commit, sha: sha3, committed_date: project.commit_by(oid: sha3).committed_date)
merge_request.merge_request_context_commits << [mrcc1, mrcc2, mrcc3]
end
end
subject { merge_request.context_commits_diff }
describe ".empty?" do
it 'checks if empty' do
expect(subject.empty?).to be(false)
end
end
describe '.commits_count' do
it 'reports commits count' do
expect(subject.commits_count).to be(1)
expect(subject.commits_count).to be(3)
end
end
describe '.diffs' do
it 'returns instance of Gitlab::Diff::FileCollection::Compare' do
expect(subject.diffs).to be_a(Gitlab::Diff::FileCollection::Compare)
end
it 'returns all diffs between first and last commits' do
expect(subject.diffs.diff_files.size).to be(5)
end
end
describe '.raw_diffs' do
before do
allow(subject).to receive(:paths).and_return(["Gemfile.zip", "files/images/6049019_460s.jpg", "files/ruby/feature.rb"])
end
it 'returns instance of Gitlab::Git::DiffCollection' do
expect(subject.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
end
it 'returns only diff for files changed in the context commits' do
expect(subject.raw_diffs.size).to be(3)
end
end
describe '.diff_refs' do
it 'returns correct sha' do
expect(subject.diff_refs.head_sha).to eq(sha3)
expect(subject.diff_refs.base_sha).to eq("913c66a37b4a45b9769037c55c2d238bd0942d2e")
end
end
end
......@@ -3,17 +3,23 @@
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 }
let(:mrcc1) { create(:merge_request_context_commit, sha: "cfe32cf61b73a0d5e9f13e774abde7ff789b1660") }
let(:mrcc2) { create(:merge_request_context_commit, sha: "ae73cb07c9eeaf35924a10f713b364d32b2dd34f") }
let(:merge_request) { create(:merge_request) { |merge_request| merge_request.merge_request_context_commits << [mrcc1, mrcc2] } }
context 'as json' do
describe '.diff_files' do
it 'returns diff files metadata' do
payload = ContextCommitsDiffEntity.represent(context_commits_diff).as_json
subject { ContextCommitsDiffEntity.represent(merge_request.context_commits_diff).as_json }
expect(payload[:commits_count]).to eq(1)
end
it 'exposes commits_count' do
expect(subject[:commits_count]).to eq(2)
end
it 'exposes showing_context_commits_diff' do
expect(subject).to have_key(:showing_context_commits_diff)
end
it 'exposes diffs_path' do
expect(subject[:diffs_path]).to match(/\/-\/merge_requests\/\d\/diffs\?only_context_commits=true$/)
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