From dde9735d265e6c1c04ecc0d7d2ffb6202e9fb528 Mon Sep 17 00:00:00 2001 From: Elliot Crosby-McCullough Date: Wed, 11 Feb 2015 15:13:11 +0000 Subject: [PATCH 1/4] More policy renaming. --- app/views/policy_areas/edit.html.erb | 4 ++-- app/views/policy_areas/index.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/policy_areas/edit.html.erb b/app/views/policy_areas/edit.html.erb index 2e78838..9bef74b 100644 --- a/app/views/policy_areas/edit.html.erb +++ b/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" %> -

Edit a policy_area

+

Edit a policy area

<%= render "form" %> diff --git a/app/views/policy_areas/index.html.erb b/app/views/policy_areas/index.html.erb index 22456af..8e3ad8b 100644 --- a/app/views/policy_areas/index.html.erb +++ b/app/views/policy_areas/index.html.erb @@ -1,6 +1,6 @@ <%= content_for :page_title, "Policy areas" %> -

Policies

+

Policy areas

<%= link_to "Create a policy area", new_policy_area_path %> From aca8602e80a971e2c33d6bbf9b9bdc0f04c855e1 Mon Sep 17 00:00:00 2001 From: Elliot Crosby-McCullough Date: Wed, 11 Feb 2015 15:20:16 +0000 Subject: [PATCH 2/4] Allow creation and editing of programmes. These are currently very similar to policy areas, but they will have significant diversion as features are added. --- app/controllers/programmes_controller.rb | 35 +++++++++++++++++++ app/models/programme.rb | 8 +++++ app/views/programmes/_form.html.erb | 6 ++++ app/views/programmes/edit.html.erb | 5 +++ app/views/programmes/index.html.erb | 33 +++++++++++++++++ app/views/programmes/new.html.erb | 5 +++ config/routes.rb | 1 + db/migrate/20150211151548_create_programme.rb | 14 ++++++++ db/schema.rb | 13 ++++++- features/programmes.feature | 14 ++++++++ features/step_definitions/programme_steps.rb | 17 +++++++++ features/support/programme_helpers.rb | 29 +++++++++++++++ spec/factories.rb | 4 +++ 13 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 app/controllers/programmes_controller.rb create mode 100644 app/models/programme.rb create mode 100644 app/views/programmes/_form.html.erb create mode 100644 app/views/programmes/edit.html.erb create mode 100644 app/views/programmes/index.html.erb create mode 100644 app/views/programmes/new.html.erb create mode 100644 db/migrate/20150211151548_create_programme.rb create mode 100644 features/programmes.feature create mode 100644 features/step_definitions/programme_steps.rb create mode 100644 features/support/programme_helpers.rb diff --git a/app/controllers/programmes_controller.rb b/app/controllers/programmes_controller.rb new file mode 100644 index 0000000..26a3242 --- /dev/null +++ b/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 diff --git a/app/models/programme.rb b/app/models/programme.rb new file mode 100644 index 0000000..7b0736b --- /dev/null +++ b/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 diff --git a/app/views/programmes/_form.html.erb b/app/views/programmes/_form.html.erb new file mode 100644 index 0000000..421aac2 --- /dev/null +++ b/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 %> diff --git a/app/views/programmes/edit.html.erb b/app/views/programmes/edit.html.erb new file mode 100644 index 0000000..1815964 --- /dev/null +++ b/app/views/programmes/edit.html.erb @@ -0,0 +1,5 @@ +<%= content_for :page_title, "Edit a programme" %> + +

Edit a programme

+ +<%= render "form" %> diff --git a/app/views/programmes/index.html.erb b/app/views/programmes/index.html.erb new file mode 100644 index 0000000..dd252e8 --- /dev/null +++ b/app/views/programmes/index.html.erb @@ -0,0 +1,33 @@ +<%= content_for :page_title, "Programmes" %> + +

Programmes

+ +

+ <%= link_to "Create a programme", new_programme_path %> +

+ + + + + + + + + + + + + + <% programmes.each do |programme| %> + + + + + <% end %> + +
NameLast updated
+
+ + +
+
<%= link_to programme.name, edit_programme_path(programme) %><%= programme.updated_at.to_s(:govuk_date) %>
diff --git a/app/views/programmes/new.html.erb b/app/views/programmes/new.html.erb new file mode 100644 index 0000000..a8927e4 --- /dev/null +++ b/app/views/programmes/new.html.erb @@ -0,0 +1,5 @@ +<%= content_for :page_title, "Create a programme" %> + +

Create a programme

+ +<%= render "form" %> diff --git a/config/routes.rb b/config/routes.rb index aa90426..62c2eaa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do resources :policy_areas + resources :programmes get "/healthcheck" => Proc.new { [200, {}, ["OK"]] } diff --git a/db/migrate/20150211151548_create_programme.rb b/db/migrate/20150211151548_create_programme.rb new file mode 100644 index 0000000..e1a21ff --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index fd28685..ed5602f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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" diff --git a/features/programmes.feature b/features/programmes.feature new file mode 100644 index 0000000..2a8401e --- /dev/null +++ b/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" diff --git a/features/step_definitions/programme_steps.rb b/features/step_definitions/programme_steps.rb new file mode 100644 index 0000000..a5852d7 --- /dev/null +++ b/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 diff --git a/features/support/programme_helpers.rb b/features/support/programme_helpers.rb new file mode 100644 index 0000000..ffec633 --- /dev/null +++ b/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) diff --git a/spec/factories.rb b/spec/factories.rb index cfe3a4a..1ad78a7 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 From 54af2bb0a8ca05ea411ed4e3920f7cc2937fcd98 Mon Sep 17 00:00:00 2001 From: Elliot Crosby-McCullough Date: Wed, 11 Feb 2015 15:28:04 +0000 Subject: [PATCH 3/4] Add navigation for policy areas and programmes. --- app/helpers/application_helper.rb | 12 ++++++++++++ app/views/layouts/application.html.erb | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..72af044 100644 --- a/app/helpers/application_helper.rb +++ b/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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a23ba29..7f7b4fc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -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') %> From fb58d48bfef6e0bde609bf6a031b982dcd571ef5 Mon Sep 17 00:00:00 2001 From: Elliot Crosby-McCullough Date: Wed, 11 Feb 2015 16:04:00 +0000 Subject: [PATCH 4/4] Update the README with policy renaming & programmes. --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c52fa8..a838cee 100644 --- a/README.md +++ b/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