From 550fcdb6d4fd7205286c1a34176e7226983527ae Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 20 Jul 2016 13:54:24 +0100 Subject: [PATCH 1/3] Add index page listing all flows Previously when you run the app on its own (e.g. in development or as a Heroku app for fact-checking), there was no way to navigate to the landing pages for individual flows. This commit introduces a basic list of links to the landing pages. This page will not be visible in production, because it is not registered with Panopticon and therefore the GOV.UK Router will not send any requests to it. --- app/controllers/smart_answers_controller.rb | 6 ++++- app/views/smart_answers/index.html.erb | 7 +++++ config/routes.rb | 2 ++ test/functional/routing_test.rb | 4 +++ .../smart_answers_controller_test.rb | 26 +++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/views/smart_answers/index.html.erb diff --git a/app/controllers/smart_answers_controller.rb b/app/controllers/smart_answers_controller.rb index 27d66633283..bbb4f4c5264 100644 --- a/app/controllers/smart_answers_controller.rb +++ b/app/controllers/smart_answers_controller.rb @@ -1,11 +1,15 @@ class SmartAnswersController < ApplicationController - before_action :find_smart_answer + before_action :find_smart_answer, except: %w(index) before_action :redirect_response_to_canonical_url, only: %w{show} before_action :set_header_footer_only, only: %w{visualise} rescue_from SmartAnswer::FlowRegistry::NotFound, with: :error_404 rescue_from SmartAnswer::InvalidNode, with: :error_404 + def index + @flows = flow_registry.flows.sort_by(&:name) + end + def show set_slimmer_artefact(@presenter.artefact) respond_to do |format| diff --git a/app/views/smart_answers/index.html.erb b/app/views/smart_answers/index.html.erb new file mode 100644 index 00000000000..c55791b8d86 --- /dev/null +++ b/app/views/smart_answers/index.html.erb @@ -0,0 +1,7 @@ +

Smart Answers

+ + diff --git a/config/routes.rb b/config/routes.rb index c85906c34e5..39a3020a83d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ SmartAnswers::Application.routes.draw do + root to: 'smart_answers#index' + get 'healthcheck', to: proc { [200, {}, ['']] } constraints id: /[a-z0-9-]+/i do diff --git a/test/functional/routing_test.rb b/test/functional/routing_test.rb index 13650619b65..1ef91bef69d 100644 --- a/test/functional/routing_test.rb +++ b/test/functional/routing_test.rb @@ -8,4 +8,8 @@ class RoutingTest < ActionDispatch::IntegrationTest get "/non-gb-driving-licence%E2%EF%BF%BD%EF%BF%BD" end end + + should "route root path to smart answers controller index action" do + assert_routing "/", controller: "smart_answers", action: "index" + end end diff --git a/test/functional/smart_answers_controller_test.rb b/test/functional/smart_answers_controller_test.rb index 475eec26886..ac0b5cb21da 100644 --- a/test/functional/smart_answers_controller_test.rb +++ b/test/functional/smart_answers_controller_test.rb @@ -18,6 +18,32 @@ def teardown teardown_fixture_flows end + context "GET /" do + setup do + @flow_a = stub("flow", name: "flow-a") + @flow_b = stub("flow", name: "flow-b") + registry = stub("Flow registry") + registry.stubs(:flows).returns([@flow_b, @flow_a]) + @controller.stubs(:flow_registry).returns(registry) + end + + should "assign flows sorted alphabetically by name" do + get :index + assert_equal [@flow_a, @flow_b], assigns(:flows) + end + + should "render index template" do + get :index + assert_template "index" + end + + should "render list of links to flows" do + get :index + assert_select "ul li a[href='/flow-a']", text: "flow-a" + assert_select "ul li a[href='/flow-b']", text: "flow-b" + end + end + context "GET /" do should "respond with 404 if not found" do @registry = stub("Flow registry") From f4cfd40bdf29a1a4122930f7963cee1553059aa6 Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Sun, 15 May 2016 23:18:10 +1200 Subject: [PATCH 2/3] Add basic app.json for Heroku deployments The environment variable values are taken from the `startup_heroku.sh` script. --- app.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app.json diff --git a/app.json b/app.json new file mode 100644 index 00000000000..b5297086c4d --- /dev/null +++ b/app.json @@ -0,0 +1,16 @@ +{ + "name": "Smart Answers", + "website": "https://www.gov.uk/", + "repository": "https://github.com/alphagov/smart-answers", + "success_url": "/", + "env": { + "GOVUK_APP_DOMAIN": "integration.publishing.service.gov.uk", + "PLEK_SERVICE_CONTENTAPI_URI": "https://www.gov.uk/api", + "PLEK_SERVICE_STATIC_URI": "https://assets-origin.integration.publishing.service.gov.uk/", + "RUNNING_ON_HEROKU": "true", + "EXPOSE_GOVSPEAK": "true", + "ERRBIT_ENV": "integration" + }, + "image": "heroku/ruby", + "buildpacks": [ { "url": "heroku/ruby" } ] +} From 62e502f98e19fc0b10550ff4c397781835ec64ea Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 20 Jul 2016 14:12:24 +0100 Subject: [PATCH 3/3] Add a "Deploy to Heroku" button to the README The URL for this button does not explicitly specify a template to use. This means Heroku will use the `Referer` HTTP header to determine the fork and branch to deploy. The idea being that the button should work on the README page of *any* fork and/or branch of the repo. See this Heroku documentation [1] for more info. [1]: https://devcenter.heroku.com/articles/heroku-button --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6af08970dee..92d86600f6f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Read more in [Lisa Scott's GDS blog post](https://gds.blog.gov.uk/2012/02/16/smart-answers-are-smart/). +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + ## Screenshots ![Student Finance Forms screenshot](./doc/assets/govuk-student-finance-forms.png)