Check if node was successfully enabled or disabled

parent ee36ef1d
...@@ -44,10 +44,13 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -44,10 +44,13 @@ class Admin::GeoNodesController < Admin::ApplicationController
if @node.primary? if @node.primary?
flash[:alert] = "Primary node can't be disabled." flash[:alert] = "Primary node can't be disabled."
else else
@node.toggle!(:enabled) if @node.toggle!(:enabled)
new_status = @node.enabled? ? 'enabled' : 'disabled'
new_status = @node.enabled? ? 'enabled' : 'disabled' flash[:notice] = "Node #{@node.url} was successfully #{new_status}."
flash[:notice] = "Node #{@node.url} was successfully #{new_status}." else
action = @node.enabled? ? 'disabling' : 'enabling'
flash[:alert] = "There was a problem #{action} node #{@node.url}."
end
end end
redirect_to admin_geo_nodes_path redirect_to admin_geo_nodes_path
......
...@@ -131,10 +131,13 @@ describe Admin::GeoNodesController do ...@@ -131,10 +131,13 @@ describe Admin::GeoNodesController do
context 'with add-on license' do context 'with add-on license' do
before do before do
allow(Gitlab::Geo).to receive(:license_allows?).and_return(true) allow(Gitlab::Geo).to receive(:license_allows?).and_return(true)
post :toggle, id: geo_node
end end
context 'with a primary node' do context 'with a primary node' do
before do
post :toggle, id: geo_node
end
let(:geo_node) { create(:geo_node, :primary, enabled: true) } let(:geo_node) { create(:geo_node, :primary, enabled: true) }
it 'does not disable the node' do it 'does not disable the node' do
...@@ -153,16 +156,41 @@ describe Admin::GeoNodesController do ...@@ -153,16 +156,41 @@ describe Admin::GeoNodesController do
context 'with a secondary node' do context 'with a secondary node' do
let(:geo_node) { create(:geo_node, host: 'example.com', port: 80, enabled: true) } let(:geo_node) { create(:geo_node, host: 'example.com', port: 80, enabled: true) }
it 'disables the node' do context 'when succeed' do
expect(geo_node.reload).not_to be_enabled before do
end post :toggle, id: geo_node
end
it 'displays a flash message' do it 'disables the node' do
expect(controller).to set_flash.now[:notice].to('Node http://example.com/ was successfully disabled.') expect(geo_node.reload).not_to be_enabled
end
it 'displays a flash message' do
expect(controller).to set_flash.now[:notice].to('Node http://example.com/ was successfully disabled.')
end
it 'redirects to the geo nodes page' do
expect(response).to redirect_to(admin_geo_nodes_path)
end
end end
it 'redirects to the geo nodes page' do context 'when fail' do
expect(response).to redirect_to(admin_geo_nodes_path) before do
allow_any_instance_of(GeoNode).to receive(:toggle!).and_return(false)
post :toggle, id: geo_node
end
it 'does not disable the node' do
expect(geo_node.reload).to be_enabled
end
it 'displays a flash message' do
expect(controller).to set_flash.now[:alert].to('There was a problem disabling node http://example.com/.')
end
it 'redirects to the geo nodes page' do
expect(response).to redirect_to(admin_geo_nodes_path)
end
end end
end end
end end
......
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