2016-11-04 08:08:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CommitEntity do
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(commit, request: request)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:request) { double('request') }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
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
|
2016-11-04 08:08:58 -04:00
|
|
|
end
|