Skip to content

Commit

Permalink
Limit the number of publications on organisation home page.
Browse files Browse the repository at this point in the history
* 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
chrisroos committed Feb 2, 2012
1 parent 910df9e commit b304418
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/organisations_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
class OrganisationsController < PublicFacingController class OrganisationsController < PublicFacingController
before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :consultations, before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :consultations,
:ministers, :board_members, :policies] :ministers, :board_members, :policies, :publications]


def index def index
@organisations_by_type = Organisation.in_listing_order.group_by(&:organisation_type) @organisations_by_type = Organisation.in_listing_order.group_by(&:organisation_type)
Expand All @@ -12,7 +12,7 @@ def alphabetical


def show def show
@policies = Policy.published.in_organisation(@organisation).by_published_at.limit(3) @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) @news_articles = NewsArticle.published.in_organisation(@organisation)
@consultations = Consultation.published.by_published_at.in_organisation(@organisation).limit(3) @consultations = Consultation.published.by_published_at.in_organisation(@organisation).limit(3)
@speeches = @organisation.ministerial_roles.map { |mr| mr.speeches.published }.flatten.uniq @speeches = @organisation.ministerial_roles.map { |mr| mr.speeches.published }.flatten.uniq
Expand All @@ -37,6 +37,10 @@ def consultations
def ministers def ministers
end end


def publications
@publications = Publication.published.in_organisation(@organisation).order("publication_date DESC")
end

def board_members def board_members
end end


Expand Down
3 changes: 3 additions & 0 deletions app/views/documents/_publications.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<%= link_to publication.title, public_document_path(publication), title: "View #{publication.title}" %> <%= link_to publication.title, public_document_path(publication), title: "View #{publication.title}" %>
<% end %> <% end %>
<% end %> <% end %>
<% if local_assigns.has_key?(:more) %>
<li><%= more %></li>
<% end %>
</ul> </ul>
</section> </section>
<% end %> <% end %>
1 change: 1 addition & 0 deletions app/views/organisations/_navigation.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<%= organisation_navigation_link_to 'Ministers', ministers_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 'Board Members', board_members_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Policies', policies_organisation_path(organisation) %> <%= organisation_navigation_link_to 'Policies', policies_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Publications', publications_organisation_path(organisation) %>
</nav> </nav>
8 changes: 8 additions & 0 deletions app/views/organisations/publications.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion app/views/organisations/show.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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/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/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: "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/speeches", object: @speeches %></div>
<div class="g1 related_documents"><%= render partial: "documents/consultations", object: @consultations, locals: { more: organisation_view_all_tag(@organisation, :consultations) } %></div> <div class="g1 related_documents"><%= render partial: "documents/consultations", object: @consultations, locals: { more: organisation_view_all_tag(@organisation, :consultations) } %></div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def redirect(path)
get :ministers get :ministers
get :board_members, path: 'board-members' get :board_members, path: 'board-members'
get :policies get :policies
get :publications
end end
end end
resources :ministerial_roles, path: 'ministers', only: [:index, :show] resources :ministerial_roles, path: 'ministers', only: [:index, :show]
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/organisation_steps.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
when 'news' then "#{organisation_name} News" when 'news' then "#{organisation_name} News"
when 'home' then organisation_name when 'home' then organisation_name
when 'policies' then "#{organisation_name} Policies" when 'policies' then "#{organisation_name} Policies"
when 'publications' then "#{organisation_name} Publications"
end end


assert page.has_css?('title', text: title) assert page.has_css?('title', text: title)
Expand Down
3 changes: 3 additions & 0 deletions features/viewing-organisations.feature
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ Scenario: Navigating between pages for an organisation
When I navigate to the "Cabinet Office" organisation's policies page When I navigate to the "Cabinet Office" organisation's policies page
Then I should see 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 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 When I navigate to the "Cabinet Office" organisation's home page
Then I should see the "Cabinet Office" organisation's home page Then I should see the "Cabinet Office" organisation's home page
44 changes: 44 additions & 0 deletions test/functional/organisations_controller_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ class OrganisationsControllerTest < ActionController::TestCase
refute_select_object(draft_corporate_publication) refute_select_object(draft_corporate_publication)
end 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 test "shows only published consultations associated with organisation" do
published_document = create(:published_consultation) published_document = create(:published_consultation)
draft_document = create(:draft_consultation) draft_document = create(:draft_consultation)
Expand Down Expand Up @@ -254,6 +276,28 @@ class OrganisationsControllerTest < ActionController::TestCase
assert_equal [later_consultation, earlier_consultation], assigns(:consultations) assert_equal [later_consultation, earlier_consultation], assigns(:consultations)
end 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 test "should display an about-us page for the organisation" do
organisation = create(:organisation, organisation = create(:organisation,
name: "organisation-name", name: "organisation-name",
Expand Down

0 comments on commit b304418

Please sign in to comment.