Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move organisation policy listing onto a separate page

  • Loading branch information...
commit d3e1f8c34d7c3789fec33c98de4423dad1accafc 2 parents 1fdecb6 + c9c93bb
@tomstuart tomstuart authored
View
8 app/controllers/organisations_controller.rb
@@ -1,6 +1,6 @@
class OrganisationsController < PublicFacingController
before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :consultations,
- :ministers, :board_members]
+ :ministers, :board_members, :policies]
def index
@organisations_by_type = Organisation.in_listing_order.group_by(&:organisation_type)
@@ -11,7 +11,7 @@ def alphabetical
end
def show
- @policies = Policy.published.in_organisation(@organisation)
+ @policies = Policy.published.in_organisation(@organisation).by_published_at.limit(3)
@publications = Publication.published.in_organisation(@organisation)
@news_articles = NewsArticle.published.in_organisation(@organisation)
@consultations = Consultation.published.by_published_at.in_organisation(@organisation).limit(3)
@@ -40,6 +40,10 @@ def ministers
def board_members
end
+ def policies
+ @policies = Policy.published.in_organisation(@organisation)
+ end
+
private
def load_organisation
View
3  app/views/documents/_policies.html.erb
@@ -7,6 +7,9 @@
<%= link_to policy.title, public_document_path(policy), title: "View #{policy.title}", class: "title" %>
<% end %>
<% end %>
+ <% if local_assigns.has_key?(:more) %>
+ <li><%= more %></li>
+ <% end %>
</ul>
</section>
<% end %>
View
1  app/views/organisations/_navigation.html.erb
@@ -6,4 +6,5 @@
<%= organisation_navigation_link_to 'Contact Details', contact_details_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Ministers', ministers_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Board Members', board_members_organisation_path(organisation) %>
+ <%= organisation_navigation_link_to 'Policies', policies_organisation_path(organisation) %>
</nav>
View
18 app/views/organisations/policies.html.erb
@@ -0,0 +1,18 @@
+<% page_title "#{@organisation.name} Policies" %>
+<div class="g3f organisation">
+ <%= render 'header', organisation: @organisation, title: "#{@organisation.name} Policies" %>
+
+ <div class="g3 page_detail">
+ <% if @policies.any? %>
+ <section id="policies">
+ <ul>
+ <% @policies.each do |policy| %>
+ <%= content_tag_for :li, policy do %>
+ <h3><%= link_to policy.title, policy %></h3>
+ <% end %>
+ <% end %>
+ </ul>
+ </section>
+ <% end %>
+ </div>
+</div>
View
2  app/views/organisations/show.html.erb
@@ -58,7 +58,7 @@
</section>
<div class="g1 related_documents"><%= render partial: "documents/policy_areas", object: @organisation.policy_areas %></div>
- <div class="g1 related_documents"><%= render partial: "documents/policies", object: @policies %></div>
+ <div class="g1 related_documents"><%= render partial: "documents/policies", object: @policies, locals: { more: safe_join(['View all', @organisation.name, link_to('policies', policies_organisation_path(@organisation))], ' ') } %></div>
<div class="g1 related_documents"><%= render partial: "documents/publications", object: @publications %></div>
<div class="g1 related_documents"><%= render partial: "corporate_publications", object: @corporate_publications %></div>
<div class="g1 related_documents"><%= render partial: "documents/speeches", object: @speeches %></div>
View
1  config/routes.rb
@@ -46,6 +46,7 @@ def redirect(path)
get :contact_details, path: 'contact-details'
get :ministers
get :board_members, path: 'board-members'
+ get :policies
end
end
resources :ministerial_roles, path: 'ministers', only: [:index, :show]
View
11 features/step_definitions/organisation_steps.rb
@@ -81,7 +81,7 @@
end
end
-When /^I navigate to the "([^"]*)" organisation's (about|news|home) page$/ do |organisation_name, page_name|
+When /^I navigate to the "([^"]*)" organisation's (.*) page$/ do |organisation_name, page_name|
navigate_to_organisation(page_name)
end
@@ -143,12 +143,13 @@
assert page.has_css?('.organisation nav')
end
-Then /^I should see the "([^"]*)" organisation's (about|news|home) page$/ do |organisation_name, page_name|
+Then /^I should see the "([^"]*)" organisation's (.*) page$/ do |organisation_name, page_name|
title =
case page_name
- when 'about' then "About #{organisation_name}"
- when 'news' then "#{organisation_name} News"
- when 'home' then organisation_name
+ when 'about' then "About #{organisation_name}"
+ when 'news' then "#{organisation_name} News"
+ when 'home' then organisation_name
+ when 'policies' then "#{organisation_name} Policies"
end
assert page.has_css?('title', text: title)
View
3  features/viewing-organisations.feature
@@ -51,5 +51,8 @@ Scenario: Navigating between pages for an organisation
When I navigate to the "Cabinet Office" organisation's news page
Then I should see the "Cabinet Office" organisation's news page
And I should see the organisation navigation
+ When I navigate to the "Cabinet Office" organisation's policies page
+ Then I should see the "Cabinet Office" organisation's policies page
+ And I should see the organisation navigation
When I navigate to the "Cabinet Office" organisation's home page
Then I should see the "Cabinet Office" organisation's home page
View
34 test/functional/organisations_controller_test.rb
@@ -13,13 +13,22 @@ class OrganisationsControllerTest < ActionController::TestCase
assert_select ".description", text: "organisation-description"
end
- test "shows only published policies associated with organisation" do
- published_document = create(:published_policy)
- draft_document = create(:draft_policy)
- organisation = create(:organisation, documents: [published_document, draft_document])
+ test "shows 3 most recent published policies associated with organisation" do
+ policies = (0..3).map { |n| create(:published_policy, published_at: n.days.ago) }
+ draft_policy = create(:draft_policy)
+ organisation = create(:organisation, documents: policies)
get :show, id: organisation
- assert_select_object(published_document)
- refute_select_object(draft_document)
+ policies[0..2].each do |policy|
+ assert_select_object(policy)
+ end
+ refute_select_object(policies[3])
+ refute_select_object(draft_policy)
+ end
+
+ test "links to dedicated policies page" do
+ organisation = create(:organisation, documents: [create(:published_policy)])
+ get :show, id: organisation
+ assert_select '#policies a[href=?]', policies_organisation_path(organisation)
end
test "shows only published publications associated with organisation" do
@@ -357,6 +366,19 @@ class OrganisationsControllerTest < ActionController::TestCase
refute_select "#other_board_members"
end
+ test "shows only published policies associated with organisation on policies page" do
+ published_policy = create(:published_policy)
+ draft_policy = create(:draft_policy)
+ unrelated_policy = create(:published_policy)
+ organisation = create(:organisation, documents: [published_policy, draft_policy])
+
+ get :policies, id: organisation
+
+ assert_select_object(published_policy)
+ refute_select_object(draft_policy)
+ refute_select_object(unrelated_policy)
+ end
+
test "should display a list of organisations" do
organisation_1 = create(:organisation)
organisation_2 = create(:organisation)
Please sign in to comment.
Something went wrong with that request. Please try again.