Check if node was successfully enabled or disabled

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