Skip to content
This repository has been archived by the owner on Oct 11, 2018. It is now read-only.

Commit

Permalink
Merge pull request #9 from alphagov/programmes
Browse files Browse the repository at this point in the history
Programmes
  • Loading branch information
edds committed Feb 11, 2015
2 parents 5b5c4b1 + fb58d48 commit 953bfc3
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 9 deletions.
8 changes: 3 additions & 5 deletions README.md
@@ -1,14 +1,12 @@
# Policy publisher

The policy publisher exists to create and manage policies and policy programmes
The policy publisher exists to create and manage policy areas and policy programmes
through the Publishing 2.0 pipeline.

## Nomenclature

- **Policy**: An abstract guide describing the actions a government is taking
regarding a specific subject.
- **Programme**: A concrete activity or activities the government is taking to
implement a policy or policies.
- **Policy area**: a broad overview of an area of government activity eg [domestic energy](https://www.gov.uk/government/policies/helping-households-to-cut-their-energy-bills).
- **Programme**: specific activities the government is taking to support its objectives eg [Green Deal](https://www.gov.uk/government/policies/helping-households-to-cut-their-energy-bills/supporting-pages/green-deal).

## Technical documentation

Expand Down
35 changes: 35 additions & 0 deletions app/controllers/programmes_controller.rb
@@ -0,0 +1,35 @@
class ProgrammesController < ApplicationController
expose(:programme, attributes: :programme_params)
expose(:programmes)

def index; end

def new; end

def create
if programme.save
redirect_to programmes_path
else
render :new
end
end

def edit; end

def update
if programme.save
redirect_to programmes_path
else
render :new
end
end

private

def programme_params
params.require(:programme).permit(
:name,
:description
)
end
end
12 changes: 12 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,14 @@
module ApplicationHelper
def nav_link(text, link)
recognized = Rails.application.routes.recognize_path(link)
if recognized[:controller] == params[:controller] && recognized[:action] == params[:action]
content_tag(:li, :class => "active") do
link_to( text, link)
end
else
content_tag(:li) do
link_to( text, link)
end
end
end
end
8 changes: 8 additions & 0 deletions app/models/programme.rb
@@ -0,0 +1,8 @@
class Programme < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
validates :slug, presence: true, uniqueness: true

before_validation on: :create do |programme|
programme.slug = programme.name.to_s.parameterize
end
end
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -6,6 +6,11 @@
<%= stylesheet_link_tag 'application', media: 'all' %>
<% end %>
<% content_for :navbar_items do %>
<%= nav_link 'Policy areas', policy_areas_path %>
<%= nav_link 'Programmes', programmes_path %>
<% end %>
<% if user_signed_in? %>
<% content_for :navbar_right do %>
<%= link_to current_user.name, Plek.current.find('signon') %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/policy_areas/edit.html.erb
@@ -1,5 +1,5 @@
<%= content_for :page_title, "Edit a policy_area" %>
<%= content_for :page_title, "Edit a policy area" %>

<h1>Edit a policy_area</h1>
<h1>Edit a policy area</h1>

<%= render "form" %>
2 changes: 1 addition & 1 deletion app/views/policy_areas/index.html.erb
@@ -1,6 +1,6 @@
<%= content_for :page_title, "Policy areas" %>

<h1>Policies</h1>
<h1>Policy areas</h1>

<p>
<%= link_to "Create a policy area", new_policy_area_path %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/programmes/_form.html.erb
@@ -0,0 +1,6 @@
<%= form_for programme do |f| %>
<%= f.text_field :name %>
<%= f.text_area :description %>
<%= f.buttons(cancel_link: programmes_path) %>
<% end %>
5 changes: 5 additions & 0 deletions app/views/programmes/edit.html.erb
@@ -0,0 +1,5 @@
<%= content_for :page_title, "Edit a programme" %>

<h1>Edit a programme</h1>

<%= render "form" %>
33 changes: 33 additions & 0 deletions app/views/programmes/index.html.erb
@@ -0,0 +1,33 @@
<%= content_for :page_title, "Programmes" %>

<h1>Programmes</h1>

<p>
<%= link_to "Create a programme", new_programme_path %>
</p>

<table class="table table-striped table-bordered" data-module="filterable-table">
<thead>
<tr class="table-header">
<th>Name</th>
<th>Last updated</th>
</tr>
<tr class="if-no-js-hide table-header-secondary">
<td colspan="4">
<form>
<label for="table-filter" class="rm">Filter programmes</label>
<input id="table-filter" type="text" class="form-control normal js-filter-table-input" placeholder="Filter programmes">
</form>
</td>
</tr>
</thead>

<tbody>
<% programmes.each do |programme| %>
<tr>
<td><%= link_to programme.name, edit_programme_path(programme) %></td>
<td><%= programme.updated_at.to_s(:govuk_date) %></td>
</tr>
<% end %>
</tbody>
</table>
5 changes: 5 additions & 0 deletions app/views/programmes/new.html.erb
@@ -0,0 +1,5 @@
<%= content_for :page_title, "Create a programme" %>

<h1>Create a programme</h1>

<%= render "form" %>
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,5 +1,6 @@
Rails.application.routes.draw do
resources :policy_areas
resources :programmes

get "/healthcheck" => Proc.new { [200, {}, ["OK"]] }

Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20150211151548_create_programme.rb
@@ -0,0 +1,14 @@
class CreateProgramme < ActiveRecord::Migration
def change
create_table :programmes do |t|
t.string "slug"
t.string "name"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "programmes", ["name"], unique: true
add_index "programmes", ["slug"], unique: true
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150211134305) do
ActiveRecord::Schema.define(version: 20150211151548) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -27,6 +27,17 @@
add_index "policy_areas", ["name"], name: "index_policy_areas_on_name", unique: true, using: :btree
add_index "policy_areas", ["slug"], name: "index_policy_areas_on_slug", unique: true, using: :btree

create_table "programmes", force: :cascade do |t|
t.string "slug"
t.string "name"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "programmes", ["name"], name: "index_programmes_on_name", unique: true, using: :btree
add_index "programmes", ["slug"], name: "index_programmes_on_slug", unique: true, using: :btree

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
Expand Down
14 changes: 14 additions & 0 deletions features/programmes.feature
@@ -0,0 +1,14 @@
Feature: Programme creation

As a content editor
I need to be able to create and edit programmes
In order to inform the nation about our government's concrete actions for a topic.

Scenario: Creating a programme
When I create a programme called "CO2 reduction"
Then there should be a programme called "CO2 reduction"

Scenario: Editing a programme
Given a programme exists called "CO2 reduction"
When I change the title of programme "CO2 reduction" to "Carbon credits"
Then there should be a programme called "Carbon credits"
17 changes: 17 additions & 0 deletions features/step_definitions/programme_steps.rb
@@ -0,0 +1,17 @@
Given(/^a programme exists called "(.*?)"$/) do |programme_name|
FactoryGirl.create(:programme, name: programme_name)
end

When(/^I change the title of programme "(.*?)" to "(.*?)"$/) do |old_name, new_name|
edit_programme(name: old_name, attributes: {
name: new_name
})
end

When(/^I create a programme called "(.*?)"$/) do |programme_name|
create_programme(name: programme_name)
end

Then(/^there should be a programme called "(.*?)"$/) do |programme_name|
check_for_programme(name: programme_name)
end
29 changes: 29 additions & 0 deletions features/support/programme_helpers.rb
@@ -0,0 +1,29 @@
module ProgrammeHelpers
def create_programme(name:, description: "A programme description")
visit programmes_path
click_on "Create a programme"

fill_in "Name", with: name
fill_in "Description", with: description

click_on "Save"
end

def edit_programme(name:, attributes:)
visit programmes_path
click_on name

attributes.each do |attribute, value|
fill_in attribute.to_s.humanize, with: value
end

click_on "Save"
end

def check_for_programme(name:)
visit programmes_path
expect(page).to have_content(name)
end
end

World(ProgrammeHelpers)
4 changes: 4 additions & 0 deletions spec/factories.rb
Expand Up @@ -6,4 +6,8 @@
factory :policy_area do
sequence(:name) {|n| "Policy area #{n}" }
end

factory :programme do
sequence(:name) {|n| "Programme #{n}" }
end
end

0 comments on commit 953bfc3

Please sign in to comment.