2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-04 08:08:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe CommitEntity do
|
2016-11-04 08:08:58 -04:00
|
|
|
let(:entity) do
|
|
|
|
described_class.new(commit, request: request)
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2016-11-04 08:08:58 -04:00
|
|
|
let(:request) { double('request') }
|
2017-03-27 15:44:13 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-11-04 08:08:58 -04:00
|
|
|
let(:commit) { project.commit }
|
|
|
|
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(request).to receive(:project).and_return(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit author is a user' do
|
|
|
|
before do
|
|
|
|
create(:user, email: commit.author_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains information about user' do
|
|
|
|
expect(subject.fetch(:author)).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit author is not a user' do
|
|
|
|
it 'does not contain author details' do
|
|
|
|
expect(subject.fetch(:author)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-17 10:08:05 -05:00
|
|
|
it 'contains path to commit' do
|
|
|
|
expect(subject).to include(:commit_path)
|
2017-01-13 07:07:32 -05:00
|
|
|
expect(subject[:commit_path]).to include "commit/#{commit.id}"
|
2016-11-04 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 16:31:26 -05:00
|
|
|
it 'contains URL to commit' do
|
2016-11-04 08:08:58 -04:00
|
|
|
expect(subject).to include(:commit_url)
|
2017-01-13 07:07:32 -05:00
|
|
|
expect(subject[:commit_path]).to include "commit/#{commit.id}"
|
2016-11-04 08:08:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'needs to receive project in the request' do
|
|
|
|
expect(request).to receive(:project)
|
|
|
|
.and_return(project)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2016-11-12 04:53:03 -05:00
|
|
|
|
|
|
|
it 'exposes gravatar url that belongs to author' do
|
|
|
|
expect(subject.fetch(:author_gravatar_url)).to match /gravatar/
|
|
|
|
end
|
2018-09-26 04:28:50 -04:00
|
|
|
|
|
|
|
context 'when type is not set' do
|
|
|
|
it 'does not expose extra properties' do
|
|
|
|
expect(subject).not_to include(:description_html)
|
|
|
|
expect(subject).not_to include(:title_html)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when type is "full"' do
|
|
|
|
let(:entity) do
|
2018-10-03 05:08:00 -04:00
|
|
|
described_class.new(commit, request: request, type: :full, pipeline_ref: project.default_branch, pipeline_project: project)
|
2018-09-26 04:28:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes extra properties' do
|
|
|
|
expect(subject).to include(:description_html)
|
|
|
|
expect(subject).to include(:title_html)
|
|
|
|
expect(subject.fetch(:description_html)).not_to be_nil
|
|
|
|
expect(subject.fetch(:title_html)).not_to be_nil
|
|
|
|
end
|
2018-10-03 02:44:18 -04:00
|
|
|
|
|
|
|
context 'when commit has signature' do
|
|
|
|
let(:commit) { project.commit(TestEnv::BRANCH_SHA['signed-commits']) }
|
|
|
|
|
|
|
|
it 'exposes "signature_html"' do
|
2022-04-18 23:09:43 -04:00
|
|
|
expect(subject.fetch(:signature_html)).not_to be_nil
|
2018-10-03 02:44:18 -04:00
|
|
|
end
|
|
|
|
end
|
2018-10-03 05:08:00 -04:00
|
|
|
|
|
|
|
context 'when commit has pipeline' do
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, project: project, sha: commit.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes "pipeline_status_path"' do
|
|
|
|
expect(subject.fetch(:pipeline_status_path)).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-09-26 04:28:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when commit_url_params is set' do
|
|
|
|
let(:entity) do
|
|
|
|
params = { merge_request_iid: 3 }
|
|
|
|
|
|
|
|
described_class.new(commit, request: request, commit_url_params: params)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds commit_url_params to url and path' do
|
|
|
|
expect(subject[:commit_path]).to include "?merge_request_iid=3"
|
|
|
|
expect(subject[:commit_url]).to include "?merge_request_iid=3"
|
|
|
|
end
|
|
|
|
end
|
2016-11-04 08:08:58 -04:00
|
|
|
end
|