Permalink
Browse files

Add country "About" pages, navigation and admin interface

  • Loading branch information...
2 parents 9ccea5f + cead3d3 commit ace9ab720465e363bed55a61bb78f8bdf5cf62fb @tomstuart tomstuart committed Feb 2, 2012
@@ -200,6 +200,20 @@
margin-bottom: 0.875em;
margin-left: 2%;
}
+
+ nav {
+ padding-left: 2%;
+ padding-bottom: 0.5em;
+ padding-top: 0.5em;
+ border-bottom: 1px solid #bbb;
+ background: #eee;
+ a {
+ float: left;
+ @include type-14;
+ margin-bottom: 0;
+ margin-right: 2%;
+ }
+ }
}
.lte-ie8 {
@@ -2,20 +2,6 @@
#content {
.organisation {
- nav {
- padding-left: 2%;
- padding-bottom: 0.5em;
- padding-top: 0.5em;
- border-bottom: 1px solid #bbb;
- background: #eee;
- a {
- float: left;
- @include type-14;
- margin-bottom: 0;
- margin-right: 2%;
- }
- }
-
.page_header {
h1.page_title {
padding-top: 0;
@@ -1,14 +1,24 @@
class CountriesController < PublicFacingController
+ before_filter :load_country, only: [:show, :about]
+
def index
@countries = Country.all
end
def show
- @country = Country.find(params[:id])
@international_priorities = InternationalPriority.published.in_country(@country).by_published_at
@news_articles = NewsArticle.published.in_country(@country).by_published_at
@policies = Policy.published.in_country(@country).by_published_at
@speeches = Speech.published.in_country(@country).by_published_at
@publications = Publication.published.in_country(@country).by_published_at
end
+
+ def about
+ end
+
+ private
+
+ def load_country
+ @country = Country.find(params[:id])
+ end
end
@@ -0,0 +1,9 @@
+module CountryHelper
+ def country_navigation_link_to(body, path)
+ link_to body, path, class: ('current' if current_country_navigation_path(params) == path)
+ end
+
+ def current_country_navigation_path(params)
+ url_for params.slice(:controller, :action, :id).merge(only_path: true)
+ end
+end
@@ -3,6 +3,10 @@
<section>
<h1>Edit country</h1>
<%= form_for([:admin, @country]) do |form| %>
+ <%= render partial: 'admin/documents/govspeak_help' %>
+ <fieldset>
+ <%= form.text_area :about, class: 'previewable', help: true %>
+ </fieldset>
<fieldset>
<legend>Embassy contact details</legend>
@@ -0,0 +1,4 @@
+<nav class="group">
+ <%= country_navigation_link_to 'Home', country_path(country) %>
+ <%= country_navigation_link_to 'About', about_country_path(country) %>
+</nav>
@@ -0,0 +1,19 @@
+<% page_title "About #{@country.name}" %>
+
+<div class="g3f country">
+ <section class="page_header countries">
+ <h1 class="country page_title"><%= @country.name %></h1>
+ </section>
+
+ <%= render 'navigation', country: @country %>
+
+ <div class="g3f document_page">
+ <div class="g2 document_view">
+ <article class="document">
+ <div class="body">
+ <%= govspeak_to_html @country.about %>
+ </div>
+ </article>
+ </div>
+ </div>
+</div>
@@ -4,6 +4,9 @@
<section class="page_header countries">
<h1 class="country page_title"><%= @country.name %></h1>
</section>
+
+ <%= render 'navigation', country: @country %>
+
<section class="page_detail">
<div class="g3">
<% if @country.embassy_address.present? %>
@@ -25,6 +28,12 @@
</section>
</div>
+<div class="g2">
+ <p class="about">
+ <%= link_to "Read more about #{@country.name}", about_country_path(@country), title: "Further information about #{@country.name}" %>
+ </p>
+</div>
+
<div class="g1 related_documents">
<%= render partial: "documents/international_priorities", object: @international_priorities %>
</div>
View
@@ -45,7 +45,11 @@ def redirect(path)
end
end
resources :ministerial_roles, path: 'ministers', only: [:index, :show]
- resources :countries, path: 'world', only: [:index, :show]
+ resources :countries, path: 'world', only: [:index, :show] do
+ member do
+ get :about
+ end
+ end
match "/search" => "search#index"
match "/autocomplete" => "search#autocomplete"
@@ -0,0 +1,5 @@
+class AddAboutToCountries < ActiveRecord::Migration
+ def change
+ add_column :countries, :about, :text
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120201142659) do
+ActiveRecord::Schema.define(:version => 20120201152319) do
create_table "attachments", :force => true do |t|
t.string "carrierwave_file"
@@ -49,6 +49,7 @@
t.string "embassy_telephone"
t.string "embassy_email"
t.string "slug"
+ t.text "about"
end
add_index "countries", ["slug"], :name => "index_countries_on_slug"
@@ -22,6 +22,16 @@
click_button "Save"
end
+When /^I navigate to the "([^"]*)" country's (about|home) page$/ do |country_name, page_name|
+ within('.country nav') do
+ click_link \
+ case page_name
+ when 'about' then 'About'
+ when 'home' then 'Home'
+ end
+ end
+end
+
Then /^I should see the country "([^"]*)"$/ do |name|
country = Country.find_by_name!(name)
assert page.has_css?(record_css_selector(country))
@@ -33,4 +43,18 @@
assert page.has_css?(".embassy_address", country.embassy_address)
assert page.has_css?(".embassy_telephone", country.embassy_telephone)
assert page.has_css?(".embassy_email", country.embassy_email)
-end
+end
+
+Then /^I should see the country navigation$/ do
+ assert page.has_css?('.country nav')
+end
+
+Then /^I should see the "([^"]*)" country's (about|home) page$/ do |country_name, page_name|
+ title =
+ case page_name
+ when 'about' then "About #{country_name}"
+ when 'home' then country_name
+ end
+
+ assert page.has_css?('title', text: title)
+end
@@ -29,4 +29,14 @@ Scenario: View priorities for a country
Given a country "British Antarctic Territory" exists
And a published international priority "Oil field exploitation" exists relating to the country "British Antarctic Territory"
When I view the country "British Antarctic Territory"
- Then I should see the international priority "Oil field exploitation"
+ Then I should see the international priority "Oil field exploitation"
+
+Scenario: Navigating between pages for a country
+Given a country "British Antarctic Territory" exists
+ When I view the country "British Antarctic Territory"
+ Then I should see the country navigation
+ When I navigate to the "British Antarctic Territory" country's about page
+ Then I should see the "British Antarctic Territory" country's about page
+ And I should see the country navigation
+ When I navigate to the "British Antarctic Territory" country's home page
+ Then I should see the "British Antarctic Territory" country's home page
@@ -1,5 +1,28 @@
require "test_helper"
class Admin::CountriesControllerTest < ActionController::TestCase
+ setup do
+ login_as :policy_writer
+ end
+
should_be_an_admin_controller
+
+ test 'should allow modification of existing country data' do
+ country = create(:country)
+
+ get :edit, id: country
+
+ assert_template 'countries/edit'
+ assert_select "textarea[name='country[about]'].previewable.govspeak"
+ assert_select '#govspeak_help'
+ end
+
+ test 'updating should modify the country' do
+ country = create(:country)
+
+ put :update, id: country, country: { about: 'country-about' }
+
+ country.reload
+ assert_equal 'country-about', country.about
+ end
end
@@ -19,4 +19,35 @@ class CountriesControllerTest < ActionController::TestCase
assert_select_object png
end
end
+
+ test "should display a link to the about page for the country" do
+ country = create(:country)
+ get :show, id: country
+ assert_select ".about a[href='#{about_country_path(country)}']"
+ end
+
+ test "should display an about page for the country" do
+ country = create(:country,
+ name: "country-name",
+ about: "country-about"
+ )
+
+ get :about, id: country
+
+ assert_select ".page_title", text: "country-name"
+ assert_select ".body", text: "country-about"
+ end
+
+ test "should render the about content using govspeak markup" do
+ country = create(:country,
+ name: "country-name",
+ about: "body-in-govspeak"
+ )
+
+ Govspeak::Document.stubs(:to_html).with("body-in-govspeak").returns("body-in-html")
+
+ get :about, id: country
+
+ assert_select ".body", text: "body-in-html"
+ end
end

0 comments on commit ace9ab7

Please sign in to comment.