debian-mirror-gitlab/spec/serializers/commit_entity_spec.rb

114 lines
3.1 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe CommitEntity do
2020-06-23 00:09:42 +05:30
let(:signature_html) { 'TEST' }
2018-12-05 23:21:45 +05:30
2017-08-17 22:00:37 +05:30
let(:entity) do
described_class.new(commit, request: request)
end
let(:request) { double('request') }
let(:project) { create(:project, :repository) }
let(:commit) { project.commit }
subject { entity.as_json }
before do
2018-12-05 23:21:45 +05:30
render = double('render')
2020-06-23 00:09:42 +05:30
allow(render).to receive(:call).and_return(signature_html)
2018-12-05 23:21:45 +05:30
2017-08-17 22:00:37 +05:30
allow(request).to receive(:project).and_return(project)
2018-12-05 23:21:45 +05:30
allow(request).to receive(:render).and_return(render)
2017-08-17 22:00:37 +05:30
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
it 'contains path to commit' do
expect(subject).to include(:commit_path)
expect(subject[:commit_path]).to include "commit/#{commit.id}"
end
it 'contains URL to commit' do
expect(subject).to include(:commit_url)
expect(subject[:commit_path]).to include "commit/#{commit.id}"
end
it 'needs to receive project in the request' do
expect(request).to receive(:project)
.and_return(project)
subject
end
it 'exposes gravatar url that belongs to author' do
expect(subject.fetch(:author_gravatar_url)).to match /gravatar/
end
2018-12-05 23:21:45 +05:30
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
described_class.new(commit, request: request, type: :full, pipeline_ref: project.default_branch, pipeline_project: project)
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
context 'when commit has signature' do
let(:commit) { project.commit(TestEnv::BRANCH_SHA['signed-commits']) }
it 'exposes "signature_html"' do
expect(request.render).to receive(:call)
2020-06-23 00:09:42 +05:30
expect(subject.fetch(:signature_html)).to be signature_html
2018-12-05 23:21:45 +05:30
end
end
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
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
2017-08-17 22:00:37 +05:30
end