Permalink
Browse files

Limit the number of publications on organisation home page.

* We now display the three most recent publications (both corporate and
non-corporate) on the organisation homepage, and link to a separate page
of all organisation publications.
* I've changed the ordering of publications so that they're displayed by
publication date.
* Corporate publications are still displayed separately on the
organisation homepage. I've chatted to Pete and this is OK as they'll
eventually move into the "about us" section.
  • Loading branch information...
1 parent 910df9e commit b304418d90b0a7319ca211a33b6c163e2374ed3f @chrisroos chrisroos committed Feb 2, 2012
@@ -1,6 +1,6 @@
class OrganisationsController < PublicFacingController
before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :consultations,
- :ministers, :board_members, :policies]
+ :ministers, :board_members, :policies, :publications]
def index
@organisations_by_type = Organisation.in_listing_order.group_by(&:organisation_type)
@@ -12,7 +12,7 @@ def alphabetical
def show
@policies = Policy.published.in_organisation(@organisation).by_published_at.limit(3)
- @publications = Publication.published.in_organisation(@organisation)
+ @publications = Publication.published.in_organisation(@organisation).order("publication_date DESC").limit(3)
@news_articles = NewsArticle.published.in_organisation(@organisation)
@consultations = Consultation.published.by_published_at.in_organisation(@organisation).limit(3)
@speeches = @organisation.ministerial_roles.map { |mr| mr.speeches.published }.flatten.uniq
@@ -37,6 +37,10 @@ def consultations
def ministers
end
+ def publications
+ @publications = Publication.published.in_organisation(@organisation).order("publication_date DESC")
+ end
+
def board_members
end
@@ -7,6 +7,9 @@
<%= link_to publication.title, public_document_path(publication), title: "View #{publication.title}" %>
<% end %>
<% end %>
+ <% if local_assigns.has_key?(:more) %>
+ <li><%= more %></li>
+ <% end %>
</ul>
</section>
<% end %>
@@ -7,4 +7,5 @@
<%= 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) %>
+ <%= organisation_navigation_link_to 'Publications', publications_organisation_path(organisation) %>
</nav>
@@ -0,0 +1,8 @@
+<% page_title "#{@organisation.name} Publications" %>
+<div class="g3f organisation">
+ <%= render 'header', organisation: @organisation, title: "#{@organisation.name} Publications" %>
+
+ <div class="g3 page_detail">
+ <%= render partial: "documents/publications", object: @publications %>
+ </div>
+</div>
@@ -59,7 +59,7 @@
<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, locals: { more: organisation_view_all_tag(@organisation, :policies) } %></div>
- <div class="g1 related_documents"><%= render partial: "documents/publications", object: @publications %></div>
+ <div class="g1 related_documents"><%= render partial: "documents/publications", object: @publications, locals: { more: organisation_view_all_tag(@organisation, :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>
<div class="g1 related_documents"><%= render partial: "documents/consultations", object: @consultations, locals: { more: organisation_view_all_tag(@organisation, :consultations) } %></div>
View
@@ -47,6 +47,7 @@ def redirect(path)
get :ministers
get :board_members, path: 'board-members'
get :policies
+ get :publications
end
end
resources :ministerial_roles, path: 'ministers', only: [:index, :show]
@@ -150,6 +150,7 @@
when 'news' then "#{organisation_name} News"
when 'home' then organisation_name
when 'policies' then "#{organisation_name} Policies"
+ when 'publications' then "#{organisation_name} Publications"
end
assert page.has_css?('title', text: title)
@@ -54,5 +54,8 @@ Scenario: Navigating between pages for an organisation
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 publications page
+ Then I should see the "Cabinet Office" organisation's publications 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
@@ -52,6 +52,28 @@ class OrganisationsControllerTest < ActionController::TestCase
refute_select_object(draft_corporate_publication)
end
+ test "should only display the 3 most recent non-corporate publications ordered by publication date" do
+ organisation = create(:organisation)
+ older_publication = create(:published_publication, title: "older", publication_date: 3.days.ago, organisations: [organisation])
+ newest_publication = create(:published_publication, title: "newest", publication_date: 1.day.ago, organisations: [organisation])
+ oldest_publication = create(:published_publication, title: "oldest", publication_date: 4.days.ago, organisations: [organisation])
+ newer_publication = create(:published_publication, title: "newer", publication_date: 2.days.ago, organisations: [organisation])
+
+ get :show, id: organisation
+
+ assert_select "#publications .publication", count: 3
+ assert_select "#publications #{record_css_selector(newest_publication)} + #{record_css_selector(newer_publication)} + #{record_css_selector(older_publication)}"
+ end
+
+ test "should link to the organisation's publications page" do
+ organisation = create(:organisation)
+ publication = create(:published_publication, organisations: [organisation])
+
+ get :show, id: organisation
+
+ assert_select "#publications a[href=#{publications_organisation_path(organisation)}]"
+ end
+
test "shows only published consultations associated with organisation" do
published_document = create(:published_consultation)
draft_document = create(:draft_consultation)
@@ -254,6 +276,28 @@ class OrganisationsControllerTest < ActionController::TestCase
assert_equal [later_consultation, earlier_consultation], assigns(:consultations)
end
+ test "should display all published corporate and non-corporate publications for the organisation" do
+ organisation = create(:organisation)
+ published_publication = create(:published_publication, organisations: [organisation])
+ draft_publication = create(:draft_publication, organisations: [organisation])
+ published_corporate_publication = create(:published_corporate_publication, organisations: [organisation])
+
+ get :publications, id: organisation
+
+ assert_equal [published_publication, published_corporate_publication].to_set, assigns(:publications).to_set
+ end
+
+ test "should order publications by publication date" do
+ organisation = create(:organisation)
+ older_publication = create(:published_publication, title: "older", publication_date: 3.days.ago, organisations: [organisation])
+ newest_publication = create(:published_publication, title: "newest", publication_date: 1.day.ago, organisations: [organisation])
+ oldest_publication = create(:published_publication, title: "oldest", publication_date: 4.days.ago, organisations: [organisation])
+
+ get :publications, id: organisation
+
+ assert_select "#{record_css_selector(newest_publication)} + #{record_css_selector(older_publication)} + #{record_css_selector(oldest_publication)}"
+ end
+
test "should display an about-us page for the organisation" do
organisation = create(:organisation,
name: "organisation-name",

0 comments on commit b304418

Please sign in to comment.