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
|
context 'when project has one or more clusters' do
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
let(:clusters) { create_list(:cluster, 2, :provided_by_gcp, projects: [project]) }
|
let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
||||||
let(:inactive_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) }
|
||||||
|
|
||||||
it 'lists available clusters' do
|
it 'lists available clusters' do
|
||||||
go
|
go
|
||||||
|
|
||||||
expect(response).to have_gitlab_http_status(:ok)
|
expect(response).to have_gitlab_http_status(:ok)
|
||||||
expect(response).to render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
expect(assigns(:clusters)).to match_array(clusters)
|
expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns counters to correct values' do
|
it 'assigns counters to correct values' do
|
||||||
|
|
|
@ -35,5 +35,9 @@ FactoryGirl.define do
|
||||||
create(:cluster_provider_gcp, :creating)
|
create(:cluster_provider_gcp, :creating)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :disabled do
|
||||||
|
enabled false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,29 +5,27 @@ describe ClustersFinder do
|
||||||
set(:user) { create(:user) }
|
set(:user) { create(:user) }
|
||||||
|
|
||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
before do
|
let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
|
||||||
create_list(:cluster, 2, :provided_by_gcp, projects: [project])
|
let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) }
|
||||||
project.clusters.last.enabled = false
|
|
||||||
end
|
|
||||||
|
|
||||||
subject { described_class.new(project, user, scope).execute }
|
subject { described_class.new(project, user, scope).execute }
|
||||||
|
|
||||||
context 'when scope is all' do
|
context 'when scope is all' do
|
||||||
let(:scope) { :all }
|
let(:scope) { :all }
|
||||||
|
|
||||||
it { is_expected.to eq(project.clusters) }
|
it { is_expected.to match_array([enabled_cluster, disabled_cluster]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when scope is enabled' do
|
context 'when scope is active' do
|
||||||
let(:scope) { :active }
|
let(:scope) { :active }
|
||||||
|
|
||||||
it { is_expected.to eq(project.clusters.enabled) }
|
it { is_expected.to match_array([enabled_cluster]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when scope is disabled' do
|
context 'when scope is inactive' do
|
||||||
let(:scope) { :inactive }
|
let(:scope) { :inactive }
|
||||||
|
|
||||||
it { is_expected.to eq(project.clusters.disabled) }
|
it { is_expected.to match_array([disabled_cluster]) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue