summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-10 16:47:27 +1300
committerThong Kuah <tkuah@gitlab.com>2018-10-15 11:07:47 +1300
commitcc1ccbf83a4a20f367011a6aec3d158214cfeb34 (patch)
treee593c381c5df19daf43481011e0ad69ad0ceefa5 /spec/services
parentda4f77957ccff7cdf22110ef56a4286bbc5a7749 (diff)
downloadgitlab-ce-cc1ccbf83a4a20f367011a6aec3d158214cfeb34.tar.gz
Move non-controller code into dedicated service
This should help with code re-use when we create applications for group level cluster next. Change `find_or_initialize_by` to explicitly find or build the right association based on the application name. The benefit here is that we use the associations on @cluster rather than querying from the other side of the association.
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/clusters/applications/create_service_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb
new file mode 100644
index 00000000000..58d9682602a
--- /dev/null
+++ b/spec/services/clusters/applications/create_service_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Clusters::Applications::CreateService do
+ let(:cluster) { create(:cluster) }
+ let(:user) { create(:user) }
+ let(:params) { { application: 'helm' } }
+ let(:service) { described_class.new(cluster, user, params) }
+
+ let(:request) do
+ if Gitlab.rails5?
+ ActionController::TestRequest.new({ remote_ip: "127.0.0.1" }, ActionController::TestSession.new)
+ else
+ ActionController::TestRequest.new(remote_ip: "127.0.0.1")
+ end
+ end
+
+ describe '#execute' do
+ subject { service.execute(request) }
+
+ it 'creates an application' do
+ expect do
+ subject
+
+ cluster.reload
+ end.to change(cluster, :application_helm)
+ end
+
+ context 'jupyter application' do
+ let(:params) do
+ {
+ application: 'jupyter',
+ hostname: 'example.com'
+ }
+ end
+
+ it 'creates the application' do
+ expect do
+ subject
+
+ cluster.reload
+ end.to change(cluster, :application_jupyter)
+ end
+
+ it 'sets the hostname' do
+ expect(subject.hostname).to eq('example.com')
+ end
+
+ it 'sets the oauth_application' do
+ expect(subject.oauth_application).to be_present
+ end
+ end
+
+ context 'invalid application' do
+ let(:params) { { application: 'non-existent' } }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(Clusters::Applications::CreateService::InvalidApplicationError)
+ end
+ end
+ end
+end