diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-04 13:08:58 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-11-04 13:08:58 +0100 |
commit | 3968b07d7ea1fd2ca07e427a487ea94ca0c6081d (patch) | |
tree | fedd5455aab03f821ae44373a994b2bf06f12d9c /spec/serializers/commit_entity_spec.rb | |
parent | c315332b8a90d26197ad93a6e982888aa575e2d4 (diff) | |
download | gitlab-ce-3968b07d7ea1fd2ca07e427a487ea94ca0c6081d.tar.gz |
Add tests for serialization entities, add user entity
Diffstat (limited to 'spec/serializers/commit_entity_spec.rb')
-rw-r--r-- | spec/serializers/commit_entity_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb new file mode 100644 index 00000000000..628e35c9a28 --- /dev/null +++ b/spec/serializers/commit_entity_spec.rb @@ -0,0 +1,44 @@ +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 + + it 'contains commit URL' do + expect(subject).to include(:commit_url) + end + + it 'needs to receive project in the request' do + expect(request).to receive(:project) + .and_return(project) + + subject + end +end |