Browse files

Show full list of an organisation's consultations on a dedicated page.

The main consultation page should only show 3 consultations at most.
  • Loading branch information...
1 parent a02bfa2 commit 5a82ed5164eefc70e07c549f624f9c13259027f1 @tomafro tomafro committed Feb 2, 2012
View
4 app/controllers/consultations_controller.rb
@@ -23,6 +23,10 @@ def show
private
+ def base_scope
+ Consultation
+ end
+
def load_consultations_from_scope(scope)
@consultations = scope.published.by_published_at.includes(:document_identity, :organisations, :published_related_policies, ministerial_roles: [:current_people, :organisations])
end
View
9 app/controllers/organisations_controller.rb
@@ -1,6 +1,5 @@
class OrganisationsController < PublicFacingController
-
- before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :ministers]
+ before_filter :load_organisation, only: [:show, :about, :contact_details, :news, :consultations, :ministers]
def index
@organisations_by_type = Organisation.in_listing_order.group_by(&:organisation_type)
@@ -14,7 +13,7 @@ def show
@policies = Policy.published.in_organisation(@organisation)
@publications = Publication.published.in_organisation(@organisation)
@news_articles = NewsArticle.published.in_organisation(@organisation)
- @consultations = Consultation.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
@corporate_publications = @organisation.corporate_publications.published
@featured_news_articles = @organisation.featured_news_articles
@@ -30,6 +29,10 @@ def news
@news_articles = NewsArticle.in_organisation(@organisation).published.by_published_at
end
+ def consultations
+ @consultations = Consultation.in_organisation(@organisation).published.by_published_at
+ end
+
def ministers
end
View
1 app/views/organisations/_navigation.html.erb
@@ -2,6 +2,7 @@
<%= organisation_navigation_link_to 'Home', organisation_path(organisation) %>
<%= organisation_navigation_link_to 'About', about_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'News', news_organisation_path(organisation) %>
+ <%= organisation_navigation_link_to 'Consultations', consultations_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Contact Details', contact_details_organisation_path(organisation) %>
<%= organisation_navigation_link_to 'Ministers', ministers_organisation_path(organisation) %>
</nav>
View
14 app/views/organisations/consultations.html.erb
@@ -0,0 +1,14 @@
+<% page_title "#{@organisation.name} Consultations" %>
+<div class="g3f organisation">
+ <%= render 'header', organisation: @organisation, title: "#{@organisation.name} Consultations" %>
+
+ <div class="g3" style="margin-top: 1.5em">
+ <% if @consultations.any? %>
+ <% @consultations.each do |consultation| %>
+ <%= render partial: "consultations/consultation", locals: { consultation: consultation, display: "default" } %>
+ <% end %>
+ <% else %>
+ <p>There are no <%= @organisation.name %> consultations at present.</p>
+ <% end %>
+ </div>
+</div>
View
1 config/routes.rb
@@ -42,6 +42,7 @@ def redirect(path)
member do
get :about
get :news
+ get :consultations
get :contact_details, path: 'contact-details'
get :ministers
end
View
57 test/functional/organisations_controller_test.rb
@@ -43,6 +43,28 @@ class OrganisationsControllerTest < ActionController::TestCase
refute_select_object(draft_corporate_publication)
end
+ test "shows only published consultations associated with organisation" do
+ published_document = create(:published_consultation)
+ draft_document = create(:draft_consultation)
+ organisation = create(:organisation, documents: [published_document, draft_document])
+ get :show, id: organisation
+ assert_select '#consultations' do
+ assert_select_object(published_document)
+ refute_select_object(draft_document)
+ end
+ end
+
+ test "shows only 3 most recent consultations when more exist" do
+ consultations = 5.times.map do |n|
+ create(:published_consultation, published_at: n.days.ago)
+ end
+
+ organisation = create(:organisation, documents: consultations)
+ get :show, id: organisation
+ assert_equal 3, assigns[:consultations].size
+ assert_equal consultations.take(3), assigns[:consultations]
+ end
+
test "should not display an empty published policies section" do
organisation = create(:organisation)
get :show, id: organisation
@@ -55,6 +77,12 @@ class OrganisationsControllerTest < ActionController::TestCase
refute_select "#publications"
end
+ test "should not display an empty consultations section" do
+ organisation = create(:organisation)
+ get :show, id: organisation
+ refute_select "#consultations"
+ end
+
test "shows leading board members associated with organisation" do
permanent_secretary = create(:board_member_role, permanent_secretary: true)
organisation = create(:organisation, board_member_roles: [permanent_secretary])
@@ -225,6 +253,35 @@ class OrganisationsControllerTest < ActionController::TestCase
assert_equal [later_news_article, earlier_news_article], assigns(:news_articles)
end
+ test "should show published consultations associated with the organisation" do
+ published_consultation = create(:published_consultation)
+ draft_consultation = create(:draft_consultation)
+ organisation = create(:organisation, documents: [published_consultation, draft_consultation])
+
+ get :consultations, id: organisation
+
+ assert_select_object(published_consultation)
+ refute_select_object(draft_consultation)
+ end
+
+ test "should show explanatory text if the organisation has no consultations" do
+ organisation = create(:organisation, name: "Cabinet Office")
+
+ get :consultations, id: organisation
+
+ assert_select "p", "There are no Cabinet Office consultations at present."
+ end
+
+ test "should show consultations in order of publication date" do
+ earlier_consultation = create(:published_consultation, published_at: 2.days.ago)
+ later_consultation = create(:published_consultation, published_at: 1.days.ago)
+ organisation = create(:organisation, documents: [earlier_consultation, later_consultation])
+
+ get :consultations, id: organisation
+
+ assert_equal [later_consultation, earlier_consultation], assigns(:consultations)
+ end
+
test "should display an about-us page for the organisation" do
organisation = create(:organisation,
name: "organisation-name",

0 comments on commit 5a82ed5

Please sign in to comment.