Refactor disabled cluster testing to use trait
This commit is contained in:
parent
f6057437dc
commit
5fb8b2f757
3 changed files with 14 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -35,5 +35,9 @@ FactoryGirl.define do
|
|||
create(:cluster_provider_gcp, :creating)
|
||||
end
|
||||
end
|
||||
|
||||
trait :disabled do
|
||||
enabled false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue