diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index 9d05729..40afa01 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -1,46 +1,52 @@
class JobsController < ApplicationController
before_action :fetch_job, only: [:show, :edit, :update, :destroy]
- before_action :fetch_host, only: [:new, :create]
+ before_action :fetch_host, only: [:new, :edit, :show, :create, :update]
# GET /jobs
def new
@job = @host.job_templates.new
end
# POST /jobs
def create
@job = @host.job_templates.new(fetch_params)
if @job.save
redirect_to host_path(@host)
else
render :new
end
end
# GET /jobs/1
def show; end
# GET /jobs/1/edit
def edit;end
# PUT /jobs/1
- def update;end
+ def update
+ if @job.update_attributes(fetch_params)
+ redirect_to host_job_path(@host, @job)
+ else
+ render :edit
+ end
+ end
# DELETE /jobs/1
def destroy
end
private
def fetch_job
@job = JobTemplate.find(params[:id])
end
def fetch_host
@host = Host.find(params[:host_id])
end
def fetch_params
params.require(:job_template).permit(:name, :job_type, :fileset_id, :schedule_id)
end
end
diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb
index 5a655be..dc0e1e3 100644
--- a/app/views/jobs/_form.html.erb
+++ b/app/views/jobs/_form.html.erb
@@ -1,56 +1,56 @@
-<%= bootstrap_form_for(@job, url: host_jobs_path, layout: :horizontal, label_col: 'col-xs-4', control_col: 'col-xs-6') do |f| %>
+<%= bootstrap_form_for(@job, url: @job.new_record? ? host_jobs_path : host_job_path(@host, @job), layout: :horizontal, label_col: 'col-xs-4', control_col: 'col-xs-6') do |f| %>
<% if @job.errors.any? %>
<%= pluralize(@job.errors.count, "error") %>
prohibited this host from being saved:
<% @job.errors.full_messages.each do |message| %>
- <%= message %>
<% end %>
<% end %>
<%= f.text_field :name %>
<%= f.select :job_type, options_for_select(JobTemplate.job_types.keys) %>
<% end %>
diff --git a/app/views/jobs/_job_details.html.erb b/app/views/jobs/_job_details.html.erb
new file mode 100644
index 0000000..2732358
--- /dev/null
+++ b/app/views/jobs/_job_details.html.erb
@@ -0,0 +1,31 @@
+
+
+
+
+ Name |
+ <%= @job.name %> |
+
+
+ Type |
+ <%= @job.job_type %> |
+
+
+ Host |
+ <%= @host.name %> |
+
+
+ Fileset |
+ <%= @job.fileset.name %> |
+
+
+ Schedule |
+ <%= @job.schedule.name %> days |
+
+
+ Created |
+ <%= I18n.l(@job.created_at, format: :long) %> |
+
+
+
+ <%= link_to 'Edit', edit_host_job_path(@host, @job), class: "btn btn-primary", role: "button" %>
+
diff --git a/app/views/jobs/edit.html.erb b/app/views/jobs/edit.html.erb
new file mode 100644
index 0000000..f40874d
--- /dev/null
+++ b/app/views/jobs/edit.html.erb
@@ -0,0 +1,18 @@
+Edit Job Template <%= @job.name %>
+
+
+
+
+
Job Attributes
+ <%= render 'form' %>
+
+
+
+
+
+
+
+
+ <%= link_to 'Cancel', host_job_path(@host, @job), class: 'btn btn-danger', role: 'button' %>
+
+
diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb
new file mode 100644
index 0000000..79c6ecd
--- /dev/null
+++ b/app/views/jobs/show.html.erb
@@ -0,0 +1,11 @@
+"<%= @job.name %>" Job Template
+
+
+
+
+ <%= render partial: 'job_details' %>
+
diff --git a/spec/controllers/jobs_controller_spec.rb b/spec/controllers/jobs_controller_spec.rb
index 152cdd6..aec26e8 100644
--- a/spec/controllers/jobs_controller_spec.rb
+++ b/spec/controllers/jobs_controller_spec.rb
@@ -1,64 +1,64 @@
require 'spec_helper'
describe JobsController do
let!(:host) { FactoryGirl.create(:host) }
describe 'GET #new' do
before { get :new, host_id: host.id }
it 'initializes a job' do
expect(assigns(:job)).to be
end
it 'renders' do
expect(response).to render_template(:new)
end
end
describe 'POST #create' do
context 'with valid params' do
let(:params) do
{
host_id: host.id,
job_template: FactoryGirl.build(:job_template).attributes.symbolize_keys.
slice(:name, :schedule_id, :fileset_id).merge(job_type: :backup)
}
end
it 'creates the job' do
expect { post :create, params }.
to change { JobTemplate.count }.by(1)
end
- it 'redirects to root' do
+ it 'redirects to host' do
post :create, params
expect(response).to redirect_to(host_path(host))
end
end
context 'with invalid params' do
let(:params) do
{
host_id: host.id,
job_template: FactoryGirl.build(:job_template).attributes.symbolize_keys.
slice(:name, :fileset_id)
}
end
it 'initializes a job with errors' do
post :create, params
expect(assigns(:job)).to be
end
it 'does not create the job' do
expect { post :create, params }.
to_not change { JobTemplate.count }
end
it 'renders :new' do
post :create, params
expect(response).to render_template(:new)
end
end
end
end