Commit abffc0a4 authored by Stan Hu's avatar Stan Hu

Address review comments with GeoNode edit support

parent cc77c0e6
class Admin::GeoNodesController < Admin::ApplicationController class Admin::GeoNodesController < Admin::ApplicationController
before_action :check_license, except: [:index, :destroy] before_action :check_license, except: [:index, :destroy]
before_action :load_node, only: [:destroy, :edit, :update, :repair, :toggle, :status] before_action :load_node, only: [:edit, :update, :destroy, :repair, :toggle, :status]
def index def index
@nodes = GeoNode.all.order(:id) @nodes = GeoNode.all.order(:id)
...@@ -24,8 +24,7 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -24,8 +24,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
def update def update
if @node.update_attributes(geo_node_params.except(:geo_node_key_attributes)) if @node.update_attributes(geo_node_params.except(:geo_node_key_attributes))
flash[:notice] = 'GeoNode was successfully updated.' redirect_to admin_geo_nodes_path, notice: 'Geo Node was successfully updated.'
redirect_to admin_geo_nodes_path
else else
render 'edit' render 'edit'
end end
......
- disable_key_edit = defined?(edit) && edit - disable_key_edit = local_assigns.fetch(:disable_key_edit, false)
- if geo_node.errors.any? = form_errors(geo_node)
.alert.alert-danger
- geo_node.errors.full_messages.each do |msg|
%p= msg
.form-group .form-group
.col-sm-offset-2.col-sm-10 .col-sm-offset-2.col-sm-10
.checkbox .checkbox
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Edit Geo Node Edit Geo Node
= form_for [:admin, @node], html: { class: 'form-horizontal' } do |f| = form_for [:admin, @node], html: { class: 'form-horizontal' } do |f|
= render partial: 'form', locals: { form: f, geo_node: @node, edit: true } = render partial: 'form', locals: { form: f, geo_node: @node, disable_key_edit: true }
.form-actions .form-actions
= f.submit 'Save changes', class: 'btn btn-create' = f.submit 'Save changes', class: 'btn btn-create'
= link_to 'Cancel', admin_geo_nodes_path, class: 'btn btn-cancel' = link_to 'Cancel', admin_geo_nodes_path, class: 'btn btn-cancel'
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- if Gitlab::Geo.license_allows? - if Gitlab::Geo.license_allows?
= form_for [:admin, @node], as: :geo_node, url: admin_geo_nodes_path, html: { class: 'form-horizontal' } do |f| = form_for [:admin, @node], as: :geo_node, url: admin_geo_nodes_path, html: { class: 'form-horizontal' } do |f|
= render partial: 'form', locals: { form: f, geo_node: @node, add_key: true } = render partial: 'form', locals: { form: f, geo_node: @node }
.form-actions .form-actions
= f.submit 'Add Node', class: 'btn btn-create' = f.submit 'Add Node', class: 'btn btn-create'
......
...@@ -20,7 +20,10 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -20,7 +20,10 @@ describe Admin::GeoNodesController, :postgresql do
describe '#index' do describe '#index' do
render_views render_views
subject { get :index }
def go
get :index
end
context 'with add-on license available' do context 'with add-on license available' do
before do before do
...@@ -28,7 +31,7 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -28,7 +31,7 @@ describe Admin::GeoNodesController, :postgresql do
end end
it 'renders creation form' do it 'renders creation form' do
expect(subject).to render_template(partial: 'admin/geo_nodes/_form') expect(go).to render_template(partial: 'admin/geo_nodes/_form')
end end
end end
...@@ -38,16 +41,16 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -38,16 +41,16 @@ describe Admin::GeoNodesController, :postgresql do
end end
it 'does not render the creation form' do it 'does not render the creation form' do
expect(subject).not_to render_template(partial: 'admin/geo_nodes/_form') expect(go).not_to render_template(partial: 'admin/geo_nodes/_form')
end end
it 'displays a flash message' do it 'displays a flash message' do
subject go
expect(controller).to set_flash.now[:alert].to('You need a different license to enable Geo replication') expect(controller).to set_flash.now[:alert].to('You need a different license to enable Geo replication')
end end
it 'does not redirects to the license page' do it 'does not redirects to the license page' do
subject go
expect(response).not_to redirect_to(admin_license_path) expect(response).not_to redirect_to(admin_license_path)
end end
end end
...@@ -55,7 +58,8 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -55,7 +58,8 @@ describe Admin::GeoNodesController, :postgresql do
describe '#destroy' do describe '#destroy' do
let!(:geo_node) { create(:geo_node) } let!(:geo_node) { create(:geo_node) }
subject do
def go
delete(:destroy, id: geo_node) delete(:destroy, id: geo_node)
end end
...@@ -65,7 +69,7 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -65,7 +69,7 @@ describe Admin::GeoNodesController, :postgresql do
end end
it 'deletes the node' do it 'deletes the node' do
expect { subject }.to change { GeoNode.count }.by(-1) expect { go }.to change { GeoNode.count }.by(-1)
end end
end end
...@@ -75,19 +79,22 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -75,19 +79,22 @@ describe Admin::GeoNodesController, :postgresql do
end end
it 'deletes the node' do it 'deletes the node' do
expect { subject }.to change { GeoNode.count }.by(-1) expect { go }.to change { GeoNode.count }.by(-1)
end end
end end
end end
describe '#create' do describe '#create' do
let(:geo_node_attributes) { { url: 'http://example.com', geo_node_key_attributes: { key: SSHKeygen.generate } } } let(:geo_node_attributes) { { url: 'http://example.com', geo_node_key_attributes: { key: SSHKeygen.generate } } }
subject { post :create, geo_node: geo_node_attributes }
def go
post :create, geo_node: geo_node_attributes
end
context 'without add-on license' do context 'without add-on license' do
before do before do
allow(Gitlab::Geo).to receive(:license_allows?) { false } allow(Gitlab::Geo).to receive(:license_allows?) { false }
subject go
end end
it_behaves_like 'unlicensed geo action' it_behaves_like 'unlicensed geo action'
...@@ -99,21 +106,24 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -99,21 +106,24 @@ describe Admin::GeoNodesController, :postgresql do
end end
it 'creates the node' do it 'creates the node' do
expect { subject }.to change { GeoNode.count }.by(1) expect { go }.to change { GeoNode.count }.by(1)
end end
end end
end end
describe '#update' do describe '#update' do
let(:geo_node_attributes) { { url: 'http://example.com', geo_node_key_attributes: { key: SSHKeygen.generate } } } let(:geo_node_attributes) { { url: 'http://example.com', geo_node_key_attributes: attributes_for(:key) } }
let(:geo_node) { create(:geo_node) } let(:geo_node) { create(:geo_node) }
let!(:original_fingerprint) { geo_node.geo_node_key.fingerprint }
subject { post :update, id: geo_node, geo_node: geo_node_attributes } def go
post :update, id: geo_node, geo_node: geo_node_attributes
end
context 'without add-on license' do context 'without add-on license' do
before do before do
allow(Gitlab::Geo).to receive(:license_allows?) { false } allow(Gitlab::Geo).to receive(:license_allows?) { false }
subject go
end end
it_behaves_like 'unlicensed geo action' it_behaves_like 'unlicensed geo action'
...@@ -122,11 +132,10 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -122,11 +132,10 @@ describe Admin::GeoNodesController, :postgresql 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)
subject go
end end
it 'updates the node without changing the key' do it 'updates the node without changing the key' do
original_fingerprint = geo_node.geo_node_key.fingerprint
geo_node.reload geo_node.reload
expect(geo_node.url.chomp('/')).to eq(geo_node_attributes[:url]) expect(geo_node.url.chomp('/')).to eq(geo_node_attributes[:url])
...@@ -137,11 +146,13 @@ describe Admin::GeoNodesController, :postgresql do ...@@ -137,11 +146,13 @@ describe Admin::GeoNodesController, :postgresql do
describe '#repair' do describe '#repair' do
let(:geo_node) { create(:geo_node) } let(:geo_node) { create(:geo_node) }
subject { post :repair, id: geo_node } def go
post :repair, id: geo_node
end
before do before do
allow(Gitlab::Geo).to receive(:license_allows?) { false } allow(Gitlab::Geo).to receive(:license_allows?) { false }
subject go
end end
it_behaves_like 'unlicensed geo action' it_behaves_like 'unlicensed geo action'
......
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