diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-03-07 00:09:48 +0900 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-03-23 17:11:49 +0900 |
commit | 617292046cf69ff4a41da875fe67f0ce7f612ea3 (patch) | |
tree | d03333f17a0050c5b804e47f55d42d24d18fd356 /spec/serializers | |
parent | 0191455471a977a9c7aac5de5574f6826c9bd2d1 (diff) | |
download | gitlab-ce-617292046cf69ff4a41da875fe67f0ce7f612ea3.tar.gz |
Add spec for entity and serializer
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/build_entity_spec.rb | 13 | ||||
-rw-r--r-- | spec/serializers/build_serializer_spec.rb | 26 | ||||
-rw-r--r-- | spec/serializers/pipeline_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 13 | ||||
-rw-r--r-- | spec/serializers/status_entity_spec.rb | 2 |
5 files changed, 53 insertions, 3 deletions
diff --git a/spec/serializers/build_entity_spec.rb b/spec/serializers/build_entity_spec.rb index 60c9642ee2c..cd30b00c711 100644 --- a/spec/serializers/build_entity_spec.rb +++ b/spec/serializers/build_entity_spec.rb @@ -1,10 +1,16 @@ require 'spec_helper' describe BuildEntity do + let(:user) { create(:user) } let(:build) { create(:ci_build) } + let(:request) { double('request') } + + before do + allow(request).to receive(:user).and_return(user) + end let(:entity) do - described_class.new(build, request: double) + described_class.new(build, request: request) end subject { entity.as_json } @@ -22,6 +28,11 @@ describe BuildEntity do expect(subject).to include(:created_at, :updated_at) end + it 'contains details' do + expect(subject).to include :details + expect(subject[:details][:status]).to include :icon, :favicon, :text, :label + end + context 'when build is a regular job' do it 'does not contain path to play action' do expect(subject).not_to include(:play_path) diff --git a/spec/serializers/build_serializer_spec.rb b/spec/serializers/build_serializer_spec.rb new file mode 100644 index 00000000000..ef75a2941c2 --- /dev/null +++ b/spec/serializers/build_serializer_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe BuildSerializer do + let(:user) { create(:user) } + + let(:serializer) do + described_class.new(user: user) + end + + subject { serializer.represent(resource) } + + describe '#represent' do + context 'when used with status' do + let(:serializer) do + described_class.new(user: user) + .with_status + end + let(:resource) { create(:ci_build) } + + it 'serializes only status' do + expect(subject[:details][:status]).not_to be_empty + expect(subject[:details].keys.count).to eq 1 + end + end + end +end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index ccb72973f9c..93d5a21419d 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -30,7 +30,7 @@ describe PipelineEntity do .to include :duration, :finished_at expect(subject[:details]) .to include :stages, :artifacts, :manual_actions - expect(subject[:details][:status]).to include :icon, :text, :label + expect(subject[:details][:status]).to include :icon, :favicon, :text, :label end it 'contains flags' do diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index 2aaef03cb93..3bf4a667853 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -93,5 +93,18 @@ describe PipelineSerializer do end end end + + context 'when used with status' do + let(:serializer) do + described_class.new(user: user) + .with_status + end + let(:resource) { create(:ci_empty_pipeline) } + + it 'serializes only status' do + expect(subject[:details][:status]).not_to be_empty + expect(subject[:details].keys.count).to eq 1 + end + end end end diff --git a/spec/serializers/status_entity_spec.rb b/spec/serializers/status_entity_spec.rb index 89428b4216e..c94902dbab8 100644 --- a/spec/serializers/status_entity_spec.rb +++ b/spec/serializers/status_entity_spec.rb @@ -16,7 +16,7 @@ describe StatusEntity do subject { entity.as_json } it 'contains status details' do - expect(subject).to include :text, :icon, :label, :group + expect(subject).to include :text, :icon, :favicon, :label, :group expect(subject).to include :has_details, :details_path end end |