Commit 1337a014 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix ClustersController specs

parent b2b4f262
...@@ -16,14 +16,12 @@ describe Projects::ClustersController do ...@@ -16,14 +16,12 @@ describe Projects::ClustersController do
end end
context 'when project has a cluster' do context 'when project has a cluster' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
it { expect(go).to redirect_to(project_cluster_path(project, project.cluster)) } it { expect(go).to redirect_to(project_cluster_path(project, project.cluster)) }
end end
context 'when project does not have a cluster' do context 'when project does not have a cluster' do
let(:cluster) { create(:cluster, :provided_by_gcp) }
it { expect(go).to redirect_to(new_project_cluster_path(project)) } it { expect(go).to redirect_to(new_project_cluster_path(project)) }
end end
end end
...@@ -124,8 +122,6 @@ describe Projects::ClustersController do ...@@ -124,8 +122,6 @@ describe Projects::ClustersController do
describe 'PUT update' do describe 'PUT update' do
context 'Managed' do context 'Managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
describe 'functionality' do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
...@@ -133,10 +129,16 @@ describe Projects::ClustersController do ...@@ -133,10 +129,16 @@ describe Projects::ClustersController do
sign_in(user) sign_in(user)
end end
context 'when update enabled' do context 'when changing parameters' do
let(:params) do let(:params) do
{ {
cluster: { enabled: false } cluster: {
enabled: false,
name: 'my-new-cluster-name',
platform_kubernetes_attributes: {
namespace: 'my-namespace'
}
}
} }
end end
...@@ -162,7 +164,6 @@ describe Projects::ClustersController do ...@@ -162,7 +164,6 @@ describe Projects::ClustersController do
end end
end end
end end
end
context 'User' do context 'User' do
let(:cluster) { create(:cluster, :provided_by_user, projects: [project]) } let(:cluster) { create(:cluster, :provided_by_user, projects: [project]) }
...@@ -177,10 +178,11 @@ describe Projects::ClustersController do ...@@ -177,10 +178,11 @@ describe Projects::ClustersController do
let(:params) do let(:params) do
{ {
cluster: { cluster: {
enabled: false, name: 'my-new-cluster-name', enabled: false,
platform_kubernetes_attributes: [ name: 'my-new-cluster-name',
platform_kubernetes_attributes: {
namespace: 'my-namespace' namespace: 'my-namespace'
] }
} }
} }
end end
...@@ -211,10 +213,10 @@ describe Projects::ClustersController do ...@@ -211,10 +213,10 @@ describe Projects::ClustersController do
end end
describe 'security' do describe 'security' do
set(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }
let(:params) do let(:params) do
{ { cluster: { enabled: false } }
cluster: { enabled: false }
}
end end
it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:admin) }
...@@ -228,15 +230,14 @@ describe Projects::ClustersController do ...@@ -228,15 +230,14 @@ describe Projects::ClustersController do
end end
def go def go
put :update, params.merge(namespace_id: project.namespace, put :update, params.merge(
namespace_id: project.namespace,
project_id: project, project_id: project,
id: cluster) id: cluster)
end end
end end
describe 'delete update' do describe 'DELETE destroy' do
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
describe 'functionality' do describe 'functionality' do
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -245,6 +246,10 @@ describe Projects::ClustersController do ...@@ -245,6 +246,10 @@ describe Projects::ClustersController do
sign_in(user) sign_in(user)
end end
context 'GCP' do
context 'when cluster is created' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
it "destroys and redirects back to clusters list" do it "destroys and redirects back to clusters list" do
expect { go } expect { go }
.to change { Clusters::Cluster.count }.by(-1) .to change { Clusters::Cluster.count }.by(-1)
...@@ -254,9 +259,10 @@ describe Projects::ClustersController do ...@@ -254,9 +259,10 @@ describe Projects::ClustersController do
expect(response).to redirect_to(project_clusters_path(project)) expect(response).to redirect_to(project_clusters_path(project))
expect(flash[:notice]).to eq('Cluster integration was successfully removed.') expect(flash[:notice]).to eq('Cluster integration was successfully removed.')
end end
end
context 'when cluster is being created' do context 'when cluster is being created' do
let(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) } let!(:cluster) { create(:cluster, :providing_by_gcp, projects: [project]) }
it "destroys and redirects back to clusters list" do it "destroys and redirects back to clusters list" do
expect { go } expect { go }
...@@ -267,9 +273,11 @@ describe Projects::ClustersController do ...@@ -267,9 +273,11 @@ describe Projects::ClustersController do
expect(flash[:notice]).to eq('Cluster integration was successfully removed.') expect(flash[:notice]).to eq('Cluster integration was successfully removed.')
end end
end end
end
context 'User' do
context 'when provider is user' do context 'when provider is user' do
let(:cluster) { create(:cluster, :provided_by_user, projects: [project]) } let!(:cluster) { create(:cluster, :provided_by_user, projects: [project]) }
it "destroys and redirects back to clusters list" do it "destroys and redirects back to clusters list" do
expect { go } expect { go }
...@@ -282,8 +290,11 @@ describe Projects::ClustersController do ...@@ -282,8 +290,11 @@ describe Projects::ClustersController do
end end
end end
end end
end
describe 'security' do describe 'security' do
set(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
it { expect { go }.to be_allowed_for(:admin) } it { expect { go }.to be_allowed_for(:admin) }
it { expect { go }.to be_allowed_for(:owner).of(project) } it { expect { go }.to be_allowed_for(:owner).of(project) }
it { expect { go }.to be_allowed_for(:master).of(project) } it { expect { go }.to be_allowed_for(:master).of(project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment