diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-04-20 11:10:00 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-04-20 11:10:00 +0200 |
commit | 27cc95ab499c08b634990b4c9266bb5ac6b64734 (patch) | |
tree | 6a401b3d11fd6f7728253dca2e0c2e31548808ed /spec/serializers | |
parent | 5e2219db48719af5ca971f9222fffa7bd66cb6d8 (diff) | |
parent | 08b2e7cd8f69603075edcb93a6a66b6407beb700 (diff) | |
download | gitlab-ce-27cc95ab499c08b634990b4c9266bb5ac6b64734.tar.gz |
Merge remote-tracking branch 'upstream/master' into 26914-add_deploy_history_data_source
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/analytics_issue_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/analytics_merge_request_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/build_action_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/build_entity_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/build_serializer_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/commit_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/environment_entity_spec.rb | 20 | ||||
-rw-r--r-- | spec/serializers/environment_serializer_spec.rb | 15 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 40 |
9 files changed, 78 insertions, 13 deletions
diff --git a/spec/serializers/analytics_issue_serializer_spec.rb b/spec/serializers/analytics_issue_serializer_spec.rb index 2f08958a783..ba24cf8e481 100644 --- a/spec/serializers/analytics_issue_serializer_spec.rb +++ b/spec/serializers/analytics_issue_serializer_spec.rb @@ -8,7 +8,7 @@ describe AnalyticsIssueSerializer do end let(:user) { create(:user) } - let(:project) { create(:project) } + let(:project) { create(:empty_project) } let(:resource) do { total_time: "172802.724419", diff --git a/spec/serializers/analytics_merge_request_serializer_spec.rb b/spec/serializers/analytics_merge_request_serializer_spec.rb index 62067cc0ef2..56cb08acfc6 100644 --- a/spec/serializers/analytics_merge_request_serializer_spec.rb +++ b/spec/serializers/analytics_merge_request_serializer_spec.rb @@ -8,7 +8,7 @@ describe AnalyticsMergeRequestSerializer do end let(:user) { create(:user) } - let(:project) { create(:project) } + let(:project) { create(:empty_project) } let(:resource) do { total_time: "172802.724419", diff --git a/spec/serializers/build_action_entity_spec.rb b/spec/serializers/build_action_entity_spec.rb index 0f7be8b2c39..54ac17447b1 100644 --- a/spec/serializers/build_action_entity_spec.rb +++ b/spec/serializers/build_action_entity_spec.rb @@ -17,5 +17,9 @@ describe BuildActionEntity do it 'contains path to the action play' do expect(subject[:path]).to include "builds/#{build.id}/play" end + + it 'contains whether it is playable' do + expect(subject[:playable]).to eq build.playable? + end end end diff --git a/spec/serializers/build_entity_spec.rb b/spec/serializers/build_entity_spec.rb index 7dcdf54fd93..f76a5cf72d1 100644 --- a/spec/serializers/build_entity_spec.rb +++ b/spec/serializers/build_entity_spec.rb @@ -24,6 +24,10 @@ describe BuildEntity do expect(subject).not_to include(/variables/) end + it 'contains whether it is playable' do + expect(subject[:playable]).to eq build.playable? + end + it 'contains timestamps' do expect(subject).to include(:created_at, :updated_at) end diff --git a/spec/serializers/build_serializer_spec.rb b/spec/serializers/build_serializer_spec.rb index 3cc791bca50..7f1abecfafe 100644 --- a/spec/serializers/build_serializer_spec.rb +++ b/spec/serializers/build_serializer_spec.rb @@ -38,7 +38,7 @@ describe BuildSerializer do expect(subject[:text]).to eq(status.text) expect(subject[:label]).to eq(status.label) expect(subject[:icon]).to eq(status.icon) - expect(subject[:favicon]).to eq(status.favicon) + expect(subject[:favicon]).to eq("/assets/ci_favicons/#{status.favicon}.ico") end end end diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb index 0333d73b5b5..04247c78549 100644 --- a/spec/serializers/commit_entity_spec.rb +++ b/spec/serializers/commit_entity_spec.rb @@ -6,7 +6,7 @@ describe CommitEntity do end let(:request) { double('request') } - let(:project) { create(:project) } + let(:project) { create(:project, :repository) } let(:commit) { project.commit } subject { entity.as_json } diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 57728ce3181..979d9921941 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -15,4 +15,24 @@ describe EnvironmentEntity do it 'exposes core elements of environment' do expect(subject).to include(:id, :name, :state, :environment_path) end + + context 'metrics disabled' do + before do + allow(environment).to receive(:has_metrics?).and_return(false) + end + + it "doesn't expose metrics path" do + expect(subject).not_to include(:metrics_path) + end + end + + context 'metrics enabled' do + before do + allow(environment).to receive(:has_metrics?).and_return(true) + end + + it 'exposes metrics path' do + expect(subject).to include(:metrics_path) + end + end end diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 6a6df377b35..1909e6385b5 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe EnvironmentSerializer do let(:user) { create(:user) } - let(:project) { create(:project) } + let(:project) { create(:empty_project) } let(:json) do described_class @@ -11,21 +11,20 @@ describe EnvironmentSerializer do end context 'when there is a single object provided' do - before do - create(:ci_build, :manual, name: 'manual1', - pipeline: deployable.pipeline) - end - + let(:project) { create(:project, :repository) } + let(:deployable) { create(:ci_build) } let(:deployment) do create(:deployment, deployable: deployable, user: user, project: project, sha: project.commit.id) end - - let(:deployable) { create(:ci_build) } let(:resource) { deployment.environment } + before do + create(:ci_build, :manual, name: 'manual1', pipeline: deployable.pipeline) + end + it 'contains important elements of environment' do expect(json) .to include(:name, :external_url, :environment_path, :last_deployment) diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index 8642b803844..ecde45a6d44 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -93,6 +93,44 @@ describe PipelineSerializer do end end end + + context 'number of queries' do + let(:resource) { Ci::Pipeline.all } + let(:project) { create(:empty_project) } + + before do + Ci::Pipeline::AVAILABLE_STATUSES.each do |status| + create_pipeline(status) + end + + RequestStore.begin! + end + + after do + RequestStore.end! + RequestStore.clear! + end + + it "verifies number of queries" do + recorded = ActiveRecord::QueryRecorder.new { subject } + expect(recorded.count).to be_within(1).of(50) + expect(recorded.cached_count).to eq(0) + end + + def create_pipeline(status) + create(:ci_empty_pipeline, project: project, status: status).tap do |pipeline| + Ci::Build::AVAILABLE_STATUSES.each do |status| + create_build(pipeline, status, status) + end + end + end + + def create_build(pipeline, stage, status) + create(:ci_build, :tags, :triggered, :artifacts, + pipeline: pipeline, stage: stage, + name: stage, status: status) + end + end end describe '#represent_status' do @@ -106,7 +144,7 @@ describe PipelineSerializer do expect(subject[:text]).to eq(status.text) expect(subject[:label]).to eq(status.label) expect(subject[:icon]).to eq(status.icon) - expect(subject[:favicon]).to eq(status.favicon) + expect(subject[:favicon]).to eq("/assets/ci_favicons/#{status.favicon}.ico") end end end |