diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb
index 9e80c8e..e908f99 100644
--- a/app/controllers/hosts_controller.rb
+++ b/app/controllers/hosts_controller.rb
@@ -1,51 +1,57 @@
class HostsController < ApplicationController
- before_action :fetch_host, only: [:show, :edit, :update, :destroy]
+ before_action :fetch_host, only: [:show, :edit, :update, :destroy, :submit_config]
# GET /hosts
def new
@host = Host.new
end
# POST /hosts
def create
@host = Host.new(fetch_params)
if @host.save
redirect_to host_path @host
else
render :new
end
end
# GET /hosts/1
def show; end
# GET /hosts/1/edit
def edit; end
# PATCH /hosts/1
def update
updates = fetch_params.slice(:port, :password)
if updates.present? && @host.update_attributes(updates)
@host.recalculate
redirect_to host_path @host
else
render :edit
end
end
# DELETE /hosts/1
def destroy
@host.destroy
redirect_to root_path
end
+ # POST /hosts/1/submit_config
+ def submit_config
+ @host.dispatch_to_bacula
+ redirect_to host_path(@host)
+ end
+
private
def fetch_host
@host = Host.includes(job_templates: [:fileset, :schedule]).find(params[:id])
end
def fetch_params
params.require(:host).permit(:fqdn, :port, :password)
end
end
diff --git a/app/views/hosts/_host_details.html.erb b/app/views/hosts/_host_details.html.erb
index 42408d2..46e9add 100644
--- a/app/views/hosts/_host_details.html.erb
+++ b/app/views/hosts/_host_details.html.erb
@@ -1,39 +1,50 @@
-
+
Name |
<%= @host.name %> |
FQDN |
<%= @host.fqdn %> |
FDPort |
<%= @host.port %> |
Password |
<%= @host.password %> |
File Retention |
<%= @host.file_retention %> days |
Job Retention |
<%= @host.job_retention %> days |
Auto Prune |
<%= @host.auto_prune_human %> |
Created |
<%= I18n.l(@host.created_at, format: :long) %> |
- <%= link_to 'Edit', edit_host_path(@host), class: "btn btn-primary", role: "button" %>
+
+
+
+ <%= link_to 'Edit', edit_host_path(@host), class: "btn btn-primary", role: "button" %>
+
+ <% if @host.ready? %>
+
+ <%= link_to 'Send to Bacula', submit_config_host_path(@host), method: :post,
+ class: 'btn btn-success', role: 'button' %>
+
+ <% end %>
+
diff --git a/config/routes.rb b/config/routes.rb
index 17793cf..855b79c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,16 +1,20 @@
Rails.application.routes.draw do
resources :clients, only: [:index, :show]
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
+ member do
+ post :submit_config
+ end
+
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
root 'clients#index'
end
diff --git a/spec/controllers/hosts_controller_spec.rb b/spec/controllers/hosts_controller_spec.rb
index aa72b3f..d738736 100644
--- a/spec/controllers/hosts_controller_spec.rb
+++ b/spec/controllers/hosts_controller_spec.rb
@@ -1,98 +1,113 @@
require 'spec_helper'
describe HostsController do
describe 'GET #new' do
before { get :new }
it 'initializes a host' do
expect(assigns(:host)).to be
end
it 'renders' do
expect(response).to render_template(:new)
end
end
describe 'PATCH #update' do
let!(:host) { FactoryGirl.create(:host) }
context 'with valid params' do
let(:params) do
{
id: host.id,
host: { port: 9999, password: 'wrong_pass' }
}
end
it 'updates the host' do
expect { patch :update, params }.
to change { [host.reload.port, host.reload.password] }.
to([9999, 'wrong_pass'])
end
it 'redirects to host_show' do
patch :update, params
expect(response).to redirect_to(host_path(host))
end
end
context 'with fqdn in params' do
let(:params) do
{
id: host.id,
host: { fqdn: 'another.host.gr' }
}
end
it 'does not update the host' do
expect { patch :update, params }.
to_not change { host.reload.fqdn }
end
it 'renders the edit page' do
patch :update, params
expect(response).to render_template(:edit)
end
end
end
describe 'POST #create' do
context 'with valid params' do
let(:params) do
{
host: FactoryGirl.build(:host).attributes.symbolize_keys.
slice(:password, :fqdn, :port)
}
end
it 'creates the host' do
expect { post :create, params }.
to change { Host.count }.by(1)
end
it 'redirects to root' do
post :create, params
expect(response).to redirect_to(host_path(Host.last))
end
end
context 'with invalid params' do
let(:params) do
{
host: FactoryGirl.build(:host).attributes.symbolize_keys.
slice(:fqdn, :port)
}
end
before { post :create, params }
it 'initializes a host with errors' do
expect(assigns(:host)).to be
end
it 'renders :new' do
expect(response).to render_template(:new)
end
end
end
+
+ describe 'POST #submit_config' do
+ let(:host) { FactoryGirl.create(:host, :configured) }
+ let(:params) { { id: host.id } }
+
+ it 'redirects to root' do
+ post :submit_config, params
+ expect(response).to redirect_to(host_path(host))
+ end
+
+ it 'calls submit_config_to_bacula on host' do
+ Host.any_instance.should_receive(:dispatch_to_bacula)
+ post :submit_config, params
+ end
+ end
end
diff --git a/spec/routing/host_routing_spec.rb b/spec/routing/host_routing_spec.rb
index 34e2f29..371105e 100644
--- a/spec/routing/host_routing_spec.rb
+++ b/spec/routing/host_routing_spec.rb
@@ -1,27 +1,32 @@
require 'spec_helper'
describe HostsController do
it 'routes GET /hosts/new' do
expect(get('/hosts/new')).to route_to(controller: 'hosts', action: 'new')
end
it 'routes POST /hosts' do
expect(post('/hosts')).to route_to(controller: 'hosts', action: 'create')
end
it 'routes GET /hosts/1' do
expect(get('/hosts/1')).to route_to(controller: 'hosts', action: 'show', id: '1')
end
it 'routes GET /hosts/1/edit' do
expect(get('/hosts/1/edit')).to route_to(controller: 'hosts', action: 'edit', id: '1')
end
it 'routes PUT /hosts/1' do
expect(put('/hosts/1')).to route_to(controller: 'hosts', action: 'update', id: '1')
end
it 'routes DELETE /hosts/1' do
expect(delete('/hosts/1')).to route_to(controller: 'hosts', action: 'destroy', id: '1')
end
+
+ it 'routes POST /hosts/1/submit_config' do
+ expect(post('/hosts/1/submit_config')).
+ to route_to(controller: 'hosts', action: 'submit_config', id: '1')
+ end
end