This repository has been archived by the owner on Oct 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from alphagov/programmes
Programmes
- Loading branch information
Showing
18 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= form_for programme do |f| %> | ||
<%= f.text_field :name %> | ||
<%= f.text_area :description %> | ||
<%= f.buttons(cancel_link: programmes_path) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= content_for :page_title, "Edit a programme" %> | ||
|
||
<h1>Edit a programme</h1> | ||
|
||
<%= render "form" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= content_for :page_title, "Create a programme" %> | ||
|
||
<h1>Create a programme</h1> | ||
|
||
<%= render "form" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters