From 5fb8b2f757e22437028436bb19af87d82c4f8c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 1 Dec 2017 16:27:53 +0100 Subject: [PATCH] Refactor disabled cluster testing to use trait --- .../projects/clusters_controller_spec.rb | 6 +++--- spec/factories/clusters/cluster.rb | 4 ++++ spec/finders/clusters_finder_spec.rb | 16 +++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 3d63d5c4394..72aade883f7 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -15,15 +15,15 @@ describe Projects::ClustersController do context 'when project has one or more clusters' do let(:project) { create(:project) } - let(:clusters) { create_list(:cluster, 2, :provided_by_gcp, projects: [project]) } - let(:inactive_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } + let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } + let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) } it 'lists available clusters' do go expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:index) - expect(assigns(:clusters)).to match_array(clusters) + expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster]) end it 'assigns counters to correct values' do diff --git a/spec/factories/clusters/cluster.rb b/spec/factories/clusters/cluster.rb index c4261178f2d..e80ecbc63eb 100644 --- a/spec/factories/clusters/cluster.rb +++ b/spec/factories/clusters/cluster.rb @@ -35,5 +35,9 @@ FactoryGirl.define do create(:cluster_provider_gcp, :creating) end end + + trait :disabled do + enabled false + end end end diff --git a/spec/finders/clusters_finder_spec.rb b/spec/finders/clusters_finder_spec.rb index 3e7bbbe39c4..c10efac2432 100644 --- a/spec/finders/clusters_finder_spec.rb +++ b/spec/finders/clusters_finder_spec.rb @@ -5,29 +5,27 @@ describe ClustersFinder do set(:user) { create(:user) } describe '#execute' do - before do - create_list(:cluster, 2, :provided_by_gcp, projects: [project]) - project.clusters.last.enabled = false - end + let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } + let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) } subject { described_class.new(project, user, scope).execute } context 'when scope is all' do let(:scope) { :all } - it { is_expected.to eq(project.clusters) } + it { is_expected.to match_array([enabled_cluster, disabled_cluster]) } end - context 'when scope is enabled' do + context 'when scope is active' do let(:scope) { :active } - it { is_expected.to eq(project.clusters.enabled) } + it { is_expected.to match_array([enabled_cluster]) } end - context 'when scope is disabled' do + context 'when scope is inactive' do let(:scope) { :inactive } - it { is_expected.to eq(project.clusters.disabled) } + it { is_expected.to match_array([disabled_cluster]) } end end end