diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-04-03 17:22:18 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-04-03 17:22:18 +0100 |
commit | 1b85c5a73fb4e7b466d3d871be7d7eb4b889b3ce (patch) | |
tree | 7fd8628974752a279cbe27c61983f8755d92cc51 /spec/serializers | |
parent | 16cca3a0ea7f4b95e99d7b3e8d4953334fa7bec7 (diff) | |
parent | b2700e64cce7c9b258e117a995eda8de00a8a988 (diff) | |
download | gitlab-ce-1b85c5a73fb4e7b466d3d871be7d7eb4b889b3ce.tar.gz |
Merge branch 'master' into tc-fix-unplayable-build-action-404
* master: (525 commits)
Introduce "polling_interval_multiplier" as application setting
fix spelling CI_REPOSITORY_URL (line:355) gitab-ci-token to gitlab-ci-token.
Pass Gitaly Repository messages to workhorse
Use gitaly 0.5.0
Fix specs
Improve specs examples
Minor refactor
Fix BrachFormatter for removed users
Changelog
Fix specs
One more change to the branch names to preserve metadata
Prefixes source branch name with short SHA to avoid collision
Fix GitHub importer for PRs of deleted forked repositories
Change order of specs
Clean history after every test that changes history
Clean history state after each test
Fixes method not replacing URL parameters correctly
Fix a transient failure caused by FFaker
Remove unnecessary ORDER BY clause when updating todos
Add a wait_for_ajax call to ensure Todos page cleans up properly
...
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_entity_spec.rb | 13 | ||||
-rw-r--r-- | spec/serializers/build_serializer_spec.rb | 45 | ||||
-rw-r--r-- | spec/serializers/commit_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/deployment_entity_spec.rb | 9 | ||||
-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_entity_spec.rb | 2 | ||||
-rw-r--r-- | spec/serializers/pipeline_serializer_spec.rb | 16 | ||||
-rw-r--r-- | spec/serializers/status_entity_spec.rb | 2 |
11 files changed, 113 insertions, 15 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_entity_spec.rb b/spec/serializers/build_entity_spec.rb index eed957fa5ef..f76a5cf72d1 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 } @@ -26,6 +32,11 @@ describe BuildEntity do expect(subject).to include(:created_at, :updated_at) end + it 'contains details' do + expect(subject).to include :status + expect(subject[: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..3cc791bca50 --- /dev/null +++ b/spec/serializers/build_serializer_spec.rb @@ -0,0 +1,45 @@ +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 a single object is being serialized' do + let(:resource) { create(:ci_build) } + + it 'serializers the pipeline object' do + expect(subject[:id]).to eq resource.id + end + end + + context 'when multiple objects are being serialized' do + let(:resource) { create_list(:ci_build, 2) } + + it 'serializers the array of pipelines' do + expect(subject).not_to be_empty + end + end + end + + describe '#represent_status' do + context 'when represents only status' do + let(:resource) { create(:ci_build) } + let(:status) { resource.detailed_status(double('user')) } + + subject { serializer.represent_status(resource) } + + it 'serializes only status' 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) + end + 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/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index ea87771e2a2..95eca5463eb 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -1,8 +1,15 @@ require 'spec_helper' describe DeploymentEntity do + let(:user) { create(:user) } + let(:request) { double('request') } + + before do + allow(request).to receive(:user).and_return(user) + end + let(:entity) do - described_class.new(deployment, request: double) + described_class.new(deployment, request: request) end let(:deployment) { create(:deployment) } 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_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..8642b803844 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -94,4 +94,20 @@ describe PipelineSerializer do end end end + + describe '#represent_status' do + context 'when represents only status' do + let(:resource) { create(:ci_pipeline) } + let(:status) { resource.detailed_status(double('user')) } + + subject { serializer.represent_status(resource) } + + it 'serializes only status' 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) + 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 |