summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2018-10-09 18:17:40 +0200
committerAlessio Caiazza <acaiazza@gitlab.com>2018-10-18 16:12:16 +0200
commit4a9efc606f5cdd9cf3aa34991543eb2f77555914 (patch)
tree29bfd4a795c5a2f77f6b8d46804f2fc7e8a83bc6 /spec/serializers
parentc09de611ea9d8cbff7a1696ee63262ef65972daa (diff)
downloadgitlab-ce-4a9efc606f5cdd9cf3aa34991543eb2f77555914.tar.gz
Move ci_environments_status to a model
GET :namespace/merge_requests/:id/ci_environments_status complexity already reached a limit for a direct serialization from an hash computed at within the controller function. Here we introduce a virtual model EnvironmentStatus and its serializer.
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/environment_status_entity_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/serializers/environment_status_entity_spec.rb b/spec/serializers/environment_status_entity_spec.rb
new file mode 100644
index 00000000000..867ebecc77d
--- /dev/null
+++ b/spec/serializers/environment_status_entity_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe EnvironmentStatusEntity do
+ let(:user) { create(:user) }
+ let(:request) { double('request') }
+
+ let(:deployment) { create(:deployment, :review_app) }
+ let(:environment) { deployment.environment}
+ let(:project) { deployment.project }
+ let(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) }
+
+ let(:environment_status) { EnvironmentStatus.new(environment, merge_request) }
+ let(:entity) { described_class.new(environment_status, request: request) }
+
+ subject { entity.as_json }
+
+ before do
+ allow(request).to receive(:current_user).and_return(user)
+ end
+
+ it { is_expected.to include(:id) }
+ it { is_expected.to include(:name) }
+ it { is_expected.to include(:url) }
+ it { is_expected.to include(:external_url) }
+ it { is_expected.to include(:external_url_formatted) }
+ it { is_expected.to include(:deployed_at) }
+ it { is_expected.to include(:deployed_at_formatted) }
+
+ it { is_expected.not_to include(:stop_url) }
+ it { is_expected.not_to include(:metrics_url) }
+ it { is_expected.not_to include(:metrics_monitoring_url) }
+
+ context 'when the user is project maintainer' do
+ before do
+ project.add_maintainer(user)
+ end
+
+ it { is_expected.to include(:stop_url) }
+ end
+end