summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-05-23 17:10:07 +0200
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-05-31 21:44:15 +0200
commit47a0276e53de4635df43124607ac1a101d6f1b70 (patch)
treee7c8d5644f9aceca23c00c280490c5bbad5b1607 /spec/serializers
parentf06daa26efc127565e4e68ca9d4ac62e5a1e3b36 (diff)
downloadgitlab-ce-47a0276e53de4635df43124607ac1a101d6f1b70.tar.gz
Initial implementation for real time job view
Added the needed keys and paths to a new entity, BuildDetailsEntity. Not renaming BuildEntity to BuildBasicEntity on explicit request. Most code now has test coverage, but not all. This will be added on later commits on this branch. Resolves gitlab-org/gitlab-ce#31397
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/build_details_entity_spec.rb39
-rw-r--r--spec/serializers/runner_entity_spec.rb14
2 files changed, 53 insertions, 0 deletions
diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb
new file mode 100644
index 00000000000..4b827a0994c
--- /dev/null
+++ b/spec/serializers/build_details_entity_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe BuildDetailsEntity do
+ it 'inherits from BuildEntity' do
+ expect(described_class).to be < BuildEntity
+ end
+
+ describe '#as_json' do
+ let(:project) { create(:project, :repository) }
+ let(:user) { create(:user) }
+ let!(:build) { create(:ci_build, :failed, project: project) }
+ let(:request) { double('request') }
+ let(:entity) { described_class.new(build, request: request, current_user: user, project: project) }
+ subject { entity.as_json }
+
+ before do
+ allow(request).to receive(:current_user).and_return(user)
+
+ project.add_master(user)
+ end
+
+ context 'when the user has access to issues and merge requests' do
+ let!(:merge_request) { create(:merge_request, source_project: project) }
+
+ it 'contains the needed key value pairs' do
+ expect(subject).to include(:coverage, :erased_at, :duration)
+ expect(subject).to include(:artifacts, :runner, :pipeline)
+ expect(subject).to include(:raw_path, :merge_request_path, :new_issue_path)
+ end
+ end
+
+ context 'when the user can only read the build' do
+ it "won't display the paths to issues and merge requests" do
+ expect(subject['new_issue_path']).to be_nil
+ expect(subject['merge_request_path']).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/serializers/runner_entity_spec.rb b/spec/serializers/runner_entity_spec.rb
new file mode 100644
index 00000000000..eb662a10b7e
--- /dev/null
+++ b/spec/serializers/runner_entity_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe RunnerEntity do
+ let(:runner) { build(:ci_runner) }
+ let(:entity) { described_class.represent(runner) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ it 'contains required fields' do
+ expect(subject).to include(:id, :name, :description)
+ end
+ end
+end