Skip to content

Instantly share code, notes, and snippets.

@issyl0
Created May 13, 2016 10:46
Show Gist options
  • Save issyl0/845f08493670ed5eb2f6ba98a6c81375 to your computer and use it in GitHub Desktop.
Save issyl0/845f08493670ed5eb2f6ba98a6c81375 to your computer and use it in GitHub Desktop.
commit e688df89f169cd3bb3d8b77ada26b2eaf6d2409d
Author: Isabell Long <isabell@issyl0.co.uk>
Date: Tue May 3 14:43:39 2016 +0100
Add a UI for links to services and interactions
- This means routes of the form
`/local_authorities/aberdeen/services/16-to-19-bursary-fund/interactions`,
using slugs as IDs to appear more nicely to users, and hence with
nesting of services under local authorities, and interactions under
services.
- The interactions list only shows the applicable ones for the selected
service. These aren't links yet - that's a separate story.
- Also a separate story is scoping the services list based on the ones
that the Local Authority provides - now it just shows all 900.
diff --git a/app/controllers/interactions_controller.rb b/app/controllers/interactions_controller.rb
new file mode 100644
index 0000000..8b20224
--- /dev/null
+++ b/app/controllers/interactions_controller.rb
@@ -0,0 +1,9 @@
+class InteractionsController < ApplicationController
+ def index
+ # We parameterized this label to make it look like a slug for
+ # the URL, so now we need to turn it back into a string so that
+ # the service can be found from it. There's probably a better way.
+ @service = Service.find_by_label(params[:service_label].downcase.gsub("-"," "))
+ @interactions = Interaction.joins(:service_interactions).where('service_interactions.service_id': @service.id)
+ end
+end
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
new file mode 100644
index 0000000..29de50b
--- /dev/null
+++ b/app/controllers/services_controller.rb
@@ -0,0 +1,6 @@
+class ServicesController < ApplicationController
+ def index
+ @authority = LocalAuthority.find_by_slug(params[:local_authority_slug])
+ @services = Service.all
+ end
+end
diff --git a/app/views/interactions/index.html.erb b/app/views/interactions/index.html.erb
new file mode 100644
index 0000000..b2c6e9e
--- /dev/null
+++ b/app/views/interactions/index.html.erb
@@ -0,0 +1,32 @@
+<% content_for :page_title, @service.label %>
+<div class="page-title">
+ <h1><%= @service.label %></h1>
+</div>
+
+<% if @interactions.any? %>
+ <table class="table table-striped table-hover table-bordered contacts-table" data-module="filterable-table">
+ <thead>
+ <tr class="table-header">
+ <th>Local Government Interactions (<%= @interactions.count %>)</th>
+ <th>LGIL Code</th>
+ </tr>
+ <%= render partial: "govuk_admin_template/table_filter",
+ locals: {placeholder: "Filter list of local interactions"} %>
+ </thead>
+ <tbody>
+ <% @interactions.each do |interaction| %>
+ <tr>
+ <td class="name">
+ <%= interaction.label %>
+ </td>
+ <td class="lgil_code">
+ <%= interaction.lgil_code %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+
+<% else %>
+ <h4>No local interactions found</h4>
+<% end %>
diff --git a/app/views/local_authorities/index.html.erb b/app/views/local_authorities/index.html.erb
index 92885fa..dd299aa 100644
--- a/app/views/local_authorities/index.html.erb
+++ b/app/views/local_authorities/index.html.erb
@@ -13,7 +13,13 @@
locals: {placeholder: "Filter list of local authorities"} %>
</thead>
<tbody>
- <%= render @authorities %>
+ <% @authorities.each do |authority| %>
+ <tr>
+ <td class="name">
+ <%= link_to authority.name, local_authority_services_path(authority.slug), class: 'js-open-on-submit' %>
+ </td>
+ </tr>
+ <% end %>
</tbody>
</table>
diff --git a/app/views/services/index.html.erb b/app/views/services/index.html.erb
new file mode 100644
index 0000000..32cc301
--- /dev/null
+++ b/app/views/services/index.html.erb
@@ -0,0 +1,32 @@
+<% content_for :page_title, @authority.name %>
+<div class="page-title">
+ <h1><%= @authority.name %></h1>
+</div>
+
+<% if @services.any? %>
+ <table class="table table-striped table-hover table-bordered contacts-table" data-module="filterable-table">
+ <thead>
+ <tr class="table-header">
+ <th>Local Government Services (<%= @services.count %>)</th>
+ <th>LGSL Code</th>
+ </tr>
+ <%= render partial: "govuk_admin_template/table_filter",
+ locals: {placeholder: "Filter list of local services"} %>
+ </thead>
+ <tbody>
+ <% @services.each do |service| %>
+ <tr>
+ <td class="name">
+ <%= link_to service.label, local_authority_service_interactions_path(service_label: service.label.parameterize), class: 'js-open-on-submit' %>
+ </td>
+ <td class="lgsl_code">
+ <%= service.lgsl_code %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+
+<% else %>
+ <h4>No local services found</h4>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index bdd27f8..9ea5488 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,15 @@
+# http://local-links-manager.dev.gov.uk/local_authorities/aberdeen/services/name/interactions
Rails.application.routes.draw do
root to: 'local_authorities#index'
get '/healthcheck', to: proc { [200, {}, ['OK']] }
+ resources "local_authorities", only: [:index], param: :slug do
+ resources "services", only: [:index], param: :label do
+ resources "interactions", only: [:index]
+ end
+ end
+
if Rails.env.development?
mount GovukAdminTemplate::Engine, at: "/style-guide"
end
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
new file mode 100644
index 0000000..002a3be
--- /dev/null
+++ b/spec/controllers/services_controller_spec.rb
@@ -0,0 +1,15 @@
+require 'rails_helper'
+
+RSpec.describe ServicesController, type: :controller do
+ before do
+ @service = FactoryGirl.create(:service, label: "Service 1", lgsl_code: 1)
+ end
+
+ describe "GET #show" do
+ it "returns http success" do
+ login_as_stub_user
+ get :show, id: @service.id
+ expect(response).to have_http_status(:success)
+ end
+ end
+end
diff --git a/spec/features/local_authorities/local_authority_index_spec.rb b/spec/features/local_authorities/local_authority_index_spec.rb
index fda6fcb..ca4f0df 100644
--- a/spec/features/local_authorities/local_authority_index_spec.rb
+++ b/spec/features/local_authorities/local_authority_index_spec.rb
@@ -1,22 +1,34 @@
describe "The local authority index page", type: :feature do
- before :each do
+ before do
User.create(email: 'user@example.com', name: 'Test User', permissions: ['signin'])
+ visit root_path
end
- it "shows a message if no local authorities are present" do
- visit '/'
-
- expect(page).to have_content 'No local authorities found'
+ describe "with no local authorities present" do
+ it "shows a message if no local authorities are present" do
+ expect(page).to have_content 'No local authorities found'
+ end
end
- it "shows the available local authorities" do
- FactoryGirl.create(:local_authority, name: "Angus")
- FactoryGirl.create(:local_authority, name: "Zorro Council", gss: "XXXXXXXXX", snac: "ZZZZ")
+ describe "with local authorities present" do
+ before do
+ @angus = FactoryGirl.create(:local_authority, name: "Angus")
+ @zorro = FactoryGirl.create(:local_authority, name: "Zorro Council", slug: "zorro", gss: "XXXXXXXXX", snac: "ZZZZ")
+ visit root_path
+ end
- visit '/'
+ it "shows the available local authorities with links to their respective pages" do
+ expect(page).to have_content 'Local Authorities (2)'
+ expect(page).to have_link('Angus', href: local_authority_path(@angus.slug))
+ expect(page).to have_link('Zorro Council', href: local_authority_path(@zorro.slug))
+ end
- expect(page).to have_content 'Local Authorities (2)'
- expect(page).to have_content 'Angus'
- expect(page).to have_content 'Zorro Council'
+ describe "clicking on the LA name on the index page" do
+ it "takes you to the show page for that LA" do
+ click_link('Angus')
+ expect(current_path).to eq(local_authority_path(@angus.slug))
+ # See the `local_authority_show_spec.rb` file for more on the show page.
+ end
+ end
end
end
diff --git a/spec/features/local_authorities/local_authority_show_spec.rb b/spec/features/local_authorities/local_authority_show_spec.rb
new file mode 100644
index 0000000..b287b7e
--- /dev/null
+++ b/spec/features/local_authorities/local_authority_show_spec.rb
@@ -0,0 +1,33 @@
+feature "The local authority show page", type: :feature do
+ before do
+ User.create(email: 'user@example.com', name: 'Test User', permissions: ['signin'])
+ @local_authority = FactoryGirl.create(:local_authority, name: "Angus", slug: 'angus')
+ visit local_authority_path(@local_authority.slug)
+ end
+
+ describe "with no services present" do
+ it "shows a message that no services are present" do
+ expect(page).to have_content 'No local services found'
+ end
+ end
+
+ describe "with services present" do
+ before do
+ @service_1 = FactoryGirl.create(:service, label: 'Service 1', lgsl_code: 1)
+ @service_2 = FactoryGirl.create(:service, label: 'Service 2', lgsl_code: 2)
+ visit local_authority_path(@local_authority.slug)
+ end
+
+ it "shows the available services with links to their individual pages" do
+ expect(page).to have_content 'Local Government Services (2)'
+ expect(page).to have_link('Service 1', href: service_path(@service_1))
+ expect(page).to have_link('Service 2', href: service_path(@service_2))
+ end
+
+ it "shows each service's LGSL codes in the table" do
+ expect(page).to have_content 'LGSL Code'
+ expect(page).to have_css('td.lgsl_code', text: 1)
+ expect(page).to have_css('td.lgsl_code', text: 2)
+ end
+ end
+end
diff --git a/spec/features/services/services_show_spec.rb b/spec/features/services/services_show_spec.rb
new file mode 100644
index 0000000..51b63c6
--- /dev/null
+++ b/spec/features/services/services_show_spec.rb
@@ -0,0 +1,35 @@
+describe "The services show page", type: :feature do
+ before do
+ User.create(email: 'user@example.com', name: 'Test User', permissions: ['signin'])
+ @service_1 = FactoryGirl.create(:service, label: 'Service 1', lgsl_code: 1)
+ visit service_path(@service_1.id)
+ end
+
+ describe "with no interactions present" do
+ it "shows a message that no interactions are present" do
+ expect(page).to have_content("No local interactions found")
+ end
+ end
+
+ describe "with interactions present" do
+ before do
+ @interaction_1 = FactoryGirl.create(:interaction, label: 'Interaction 1', lgil_code: 3)
+ @interaction_2 = FactoryGirl.create(:interaction, label: 'Interaction 2', lgil_code: 4)
+ FactoryGirl.create(:service_interaction, service_id: @service_1.id, interaction_id: @interaction_1.id)
+ visit service_path(@service_1.id)
+ end
+
+ it "shows the available interactions for the service" do
+ expect(page).to have_content('Local Government Interactions (1)')
+ expect(page).to have_content('Interaction 1')
+ # Interaction 2 does not belong to service 1, so don't display it.
+ expect(page).not_to have_content('Interaction 2')
+ end
+
+ it "shows each service interaction's LGIL code" do
+ expect(page).to have_content 'LGIL Code'
+ expect(page).to have_css('td.lgil_code', text: 3)
+ expect(page).not_to have_css('td.lgil_code', text: 4)
+ end
+ end
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment