diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb
new file mode 100644
index 0000000..61e7742
--- /dev/null
+++ b/app/controllers/schedules_controller.rb
@@ -0,0 +1,34 @@
+class SchedulesController < ApplicationController
+ def new
+ @schedule = Schedule.new
+ end
+
+ def show
+ end
+
+ def edit
+ end
+
+ def update
+ end
+
+ def create
+ @schedule = Schedule.new(fetch_params)
+ @schedule.runtime = params[:schedule][:runtime] if params[:schedule][:runtime]
+
+ if @schedule.save
+ redirect_to root_path
+ else
+ render :new
+ end
+ end
+
+ def destroy
+ end
+
+ private
+
+ def fetch_params
+ params.require(:schedule).permit(:name)
+ end
+end
diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb
index 83f1467..5a655be 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| %>
<% 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/schedules/_form.html.erb b/app/views/schedules/_form.html.erb
new file mode 100644
index 0000000..12b0836
--- /dev/null
+++ b/app/views/schedules/_form.html.erb
@@ -0,0 +1,26 @@
+<%= bootstrap_form_for(@schedule, layout: :horizontal,
+ label_col: 'col-xs-3', control_col: 'col-xs-8') do |f| %>
+ <% if @schedule.errors.any? %>
+
+
<%= pluralize(@schedule.errors.count, "error") %> prohibited this schedule from being saved:
+
+
+ <% @schedule.errors.full_messages.each do |message| %>
+ - <%= message %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= f.text_field :name %>
+ <%= f.time_field :runtime, placeholder: 'HH:MM' %>
+
+
+
+
+<% end %>
diff --git a/app/views/schedules/new.html.erb b/app/views/schedules/new.html.erb
new file mode 100644
index 0000000..6e9bfd9
--- /dev/null
+++ b/app/views/schedules/new.html.erb
@@ -0,0 +1,5 @@
+New Schedule
+
+
+ <%= render 'form' %>
+
diff --git a/config/routes.rb b/config/routes.rb
index 1f871a7..9efa18a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,10 @@
Rails.application.routes.draw do
resources :clients, only: [:index, :show]
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy]
end
+ resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
+
root 'clients#index'
end
diff --git a/spec/controllers/schedules_controller_spec.rb b/spec/controllers/schedules_controller_spec.rb
new file mode 100644
index 0000000..ec56863
--- /dev/null
+++ b/spec/controllers/schedules_controller_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe SchedulesController do
+ describe 'GET #new' do
+ before { get :new }
+
+ it 'initializes a schedule' do
+ expect(assigns(:schedule)).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
+ {
+ schedule: { name: FactoryGirl.build(:schedule).name, runtime: '19:17' }
+ }
+ end
+
+ it 'creates the schedule' do
+ expect { post :create, params }.
+ to change { Schedule.count }.by(1)
+ end
+
+ it 'redirects to root' do
+ post :create, params
+ expect(response).to redirect_to(root_path)
+ end
+ end
+
+ context 'with invalid params' do
+ let(:params) { { schedule: { invalide: :foo } } }
+
+ it 'initializes a schedule with errors' do
+ post :create, params
+ expect(assigns(:schedule)).to be
+ end
+
+ it 'does not create the schedule' do
+ expect { post :create, params }.
+ to_not change { Schedule.count }
+ end
+
+ it 'renders :new' do
+ post :create, params
+ expect(response).to render_template(:new)
+ end
+ end
+ end
+end
diff --git a/spec/routing/schedule_routing_spec.rb b/spec/routing/schedule_routing_spec.rb
new file mode 100644
index 0000000..af03985
--- /dev/null
+++ b/spec/routing/schedule_routing_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe SchedulesController do
+ it 'routes GET /schedules/new' do
+ expect(get('/schedules/new')).to route_to( { controller: 'schedules', action: 'new'})
+ end
+
+ it 'routes POST /schedules' do
+ expect(post('/schedules')).to route_to( { controller: 'schedules', action: 'create'})
+ end
+
+ it 'routes GET /schedules/1' do
+ expect(get('/schedules/1')).to route_to( { controller: 'schedules', action: 'show', id: '1' })
+ end
+
+ it 'routes GET /schedules/1/edit' do
+ expect(get('/schedules/1/edit')).to route_to( { controller: 'schedules', action: 'edit', id: '1' })
+ end
+
+ it 'routes PUT /schedules/1' do
+ expect(put('/schedules/1')).to route_to( { controller: 'schedules', action: 'update', id: '1' })
+ end
+
+ it 'routes DELETE /schedules/1' do
+ expect(delete('/schedules/1')).to route_to( { controller: 'schedules', action: 'destroy', id: '1' })
+ end
+end