Commit 105ed5f4 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-show-geo-node-creation-errors' into 'master'

Properly report errors when GeoNode fails to create

Closes #3948

See merge request gitlab-org/gitlab-ee!3300
parents 747646b7 5701f415
...@@ -8,7 +8,7 @@ module Geo ...@@ -8,7 +8,7 @@ module Geo
end end
def execute def execute
GeoNode.create(params).persisted? GeoNode.create(params)
end end
end end
end end
...@@ -14,12 +14,12 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -14,12 +14,12 @@ class Admin::GeoNodesController < Admin::ApplicationController
end end
def create def create
if Geo::NodeCreateService.new(geo_node_params).execute @node = Geo::NodeCreateService.new(geo_node_params).execute
if @node.persisted?
redirect_to admin_geo_nodes_path, notice: 'Node was successfully created.' redirect_to admin_geo_nodes_path, notice: 'Node was successfully created.'
else else
@nodes = GeoNode.all @nodes = GeoNode.all
@node = GeoNode.new(geo_node_params)
flash.now[:alert] = 'Failed to create new node'
render :index render :index
end end
......
...@@ -26,7 +26,6 @@ RSpec.describe 'admin Geo Nodes', type: :feature do ...@@ -26,7 +26,6 @@ RSpec.describe 'admin Geo Nodes', type: :feature do
it 'creates a new Geo Node' do it 'creates a new Geo Node' do
check 'This is a primary node' check 'This is a primary node'
fill_in 'geo_node_url', with: 'https://test.gitlab.com' fill_in 'geo_node_url', with: 'https://test.gitlab.com'
fill_in 'geo_node_geo_node_key_attributes_key', with: new_ssh_key
click_button 'Add Node' click_button 'Add Node'
expect(current_path).to eq admin_geo_nodes_path expect(current_path).to eq admin_geo_nodes_path
...@@ -35,6 +34,20 @@ RSpec.describe 'admin Geo Nodes', type: :feature do ...@@ -35,6 +34,20 @@ RSpec.describe 'admin Geo Nodes', type: :feature do
expect(page).to have_content(geo_node.url) expect(page).to have_content(geo_node.url)
end end
end end
it 'returns an error message when a duplicate primary is added' do
check 'This is a primary node'
fill_in 'geo_node_url', with: 'https://test.example.com'
click_button 'Add Node'
check 'This is a primary node'
fill_in 'geo_node_url', with: 'https://secondary.example.com'
click_button 'Add Node'
expect(current_path).to eq admin_geo_nodes_path
expect(page).to have_content('Primary node already exists')
end
end end
describe 'update an existing Geo Node' do describe 'update an existing Geo Node' do
......
...@@ -17,13 +17,13 @@ describe Geo::NodeCreateService do ...@@ -17,13 +17,13 @@ describe Geo::NodeCreateService do
it 'returns true when creation succeeds' do it 'returns true when creation succeeds' do
service = described_class.new(url: 'http://example.com') service = described_class.new(url: 'http://example.com')
expect(service.execute).to eq true expect(service.execute.persisted?).to eq true
end end
it 'returns false when creation fails' do it 'returns false when creation fails' do
service = described_class.new(url: 'ftp://example.com') service = described_class.new(url: 'ftp://example.com')
expect(service.execute).to eq false expect(service.execute.persisted?).to eq false
end end
it 'parses the namespace_ids when node have namespace restrictions' do it 'parses the namespace_ids when node have namespace restrictions' do
......
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