Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #2169

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5c37d4e
Remove references to define_predicate from docs
chrisroos Nov 25, 2015
788c0a1
Fix broken links in README.md
chrisroos Nov 25, 2015
85ee873
Add documentation about creating a new Smart Answer
chrisroos Nov 25, 2015
3dd7981
Update "next node" section smart-answer-flows.md
chrisroos Nov 25, 2015
f9b689f
Add section about the `Flow` class to smart-answers-flows.md
chrisroos Nov 25, 2015
d67f290
Remove references to PhraseLists from docs
chrisroos Nov 27, 2015
1e8a9df
Add documentation about refactoring
chrisroos Nov 27, 2015
9740b45
Add information about common errors
chrisroos Nov 27, 2015
a78f2da
Add info about developing without the dev VM
chrisroos Nov 27, 2015
59361b8
Add information about Errbit
chrisroos Nov 27, 2015
8b9be79
Remove unnecessary full stop
chrisroos Nov 27, 2015
bafd1f9
Update README to link to Trello
chrisroos Nov 27, 2015
bd544ae
Add information about environments
chrisroos Nov 27, 2015
6bf4526
Update "File structure" section
chrisroos Nov 30, 2015
8fc28a9
Update "Next node rules" section
chrisroos Nov 30, 2015
e79eb63
Move "File structure" to its own document
chrisroos Nov 30, 2015
653b21e
Move "Flow definition" to its own document
chrisroos Nov 30, 2015
ba3f896
Move "Question types" to its own document
chrisroos Nov 30, 2015
105d7f3
Move "Next node rules" to its own document
chrisroos Nov 30, 2015
5470215
Move "Storing data" to its own document
chrisroos Nov 30, 2015
b534d02
Move "Outcome templates" to its own document
chrisroos Nov 30, 2015
21b0878
Remove "Executing tests" section
chrisroos Nov 30, 2015
e21ae1e
Move "Adding regression" tests section
chrisroos Nov 30, 2015
6029955
Move "Testing" section
chrisroos Nov 30, 2015
698921f
Remove smart-answer-flows.md
chrisroos Nov 30, 2015
42ee095
Update docs for Outcome templates
chrisroos Nov 30, 2015
b6d2a66
Add docs about Landing page templates
chrisroos Nov 30, 2015
525c00b
Add docs about Question templates
chrisroos Nov 30, 2015
68b4eb3
Add page about ERB templates
chrisroos Nov 30, 2015
8b34edb
Link to specific template docs
chrisroos Nov 30, 2015
c6bc545
Use correct heading in next-node-rules.md
chrisroos Nov 30, 2015
891d39e
Add "Errors" section to next-node-rules.md
chrisroos Nov 30, 2015
9556654
Consistently use fenced code blocks
chrisroos Nov 30, 2015
4ec19ae
Improve docs about Next node rules
chrisroos Nov 30, 2015
4649d7d
Improve "Storing data" docs
chrisroos Nov 30, 2015
750db02
Add docs about pull requests
chrisroos Nov 30, 2015
a747dac
Add docs about removing regression tests
chrisroos Dec 1, 2015
90454cb
Describe the 3 components of this application
chrisroos Dec 3, 2015
9b2e0b2
Update "Running the application" in README
chrisroos Dec 3, 2015
c4f9163
Fix link in developing-without-vm.md
chrisroos Dec 3, 2015
1abd023
Remove links from "Development" in README
chrisroos Dec 3, 2015
adb1bbb
Re-order links to other docs in README
chrisroos Dec 3, 2015
742f1a7
Expand on differences to Preview environment
chrisroos Dec 3, 2015
4cc755f
Add example URLs of pages rendered as Govspeak
chrisroos Dec 3, 2015
e3cf118
Use bullet points in refactoring.md
chrisroos Dec 3, 2015
8c79dd3
Add point about extracting magic numbers
chrisroos Dec 3, 2015
db52741
Add development-principles.md
chrisroos Dec 3, 2015
c616a90
Set language to ERB where appropriate
chrisroos Dec 3, 2015
d8c6e00
Add information about state variables to erb-templates.md
chrisroos Dec 8, 2015
81dd6dd
Add information about state variables to storing-data.md
chrisroos Dec 8, 2015
7f0c041
Update pull-requests.md
chrisroos Dec 8, 2015
943c994
Explain the lack of ActiveRecord Railtie in README.md
chrisroos Dec 8, 2015
403de0c
Use consistent language in dev VM README links
chrisroos Dec 8, 2015
f8ff663
Update development-principles.md
chrisroos Dec 8, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,63 @@ Read more in [Lisa Scott's GDS blog post](https://gds.blog.gov.uk/2012/02/16/sma

## Technical documentation

This is a Ruby on Rails application that both contains and serves the Smart Answers stored in this repository. Smart Answers are presented to public users.
This is a Ruby on Rails application that contains:

**NOTE.** This application doesn't use a database.
* A Rails application to serve Smart Answers
* A DSL for creating Smart Answers
* The Smart Answers that appear on GOV.UK

Read more about the [structure and syntax of Smart Answers](doc/smart-answers-flows.md).
**NOTE.** This application doesn't use a database and as such it [does not include the ActiveRecord Railtie in application.rb](https://github.com/alphagov/smart-answers/blob/4eb1b80a698e6835e745c4ad1954a3892e929b64/config/application.rb#L3).

### Dependencies

* [alphagov/static](https://github.com/alphagov/static): provides static assets (JS/CSS) and the GOV.UK templates.

### Running the application

See [development using the GDS development virtual machine](developing-using-vm.md).
See:

* [Developing with the GDS development VM](doc/developing-using-vm.md)
* [Developing without the GDS development VM](doc/developing-without-vm.md)

### Running the test suite

$ bundle exec rake

### Process
### Smart Answers

* [Archiving a Smart Answer](doc/archiving.md)
* [Continuous integration](doc/continuous-integration.md)
* [File structure](doc/file-structure.md)
* [Flow definition](doc/flow-definition.md)
* [Question types](doc/question-types.md)
* [Next node rules](doc/next-node-rules.md)
* [Storing data](doc/storing-data.md)
* [ERB templates](doc/erb-templates.md)
* [Landing page template](doc/landing-page-template.md)
* [Question templates](doc/question-templates.md)
* [Outcome templates](doc/outcome-templates.md)

### Smart Answer flow development

* [Development principles](doc/development-principles.md)
* [Deploying changes for Factcheck](doc/factcheck.md)
* [Deploying](doc/deploying.md)
* [Merging pull requests from the content team](doc/merging-content-prs.md)
* [Refactoring existing Smart Answers](doc/refactoring.md)
* Adding [content-ids](doc/content-ids.md) to Smart Answers
* [Creating a new Smart Answer](doc/creating-a-new-smart-answer.md)
* [Archiving a Smart Answer](doc/archiving.md)
* [Updating worldwide fixture data](doc/updating-worldwide-fixture-data.md)

### Development
### Smart Answers app development

* Adding [content-ids](doc/content-ids.md) to Smart Answers.
* [Developing using the VM](doc/developing-using-vm.md)
* [Issues and Todo](https://github.com/alphagov/smart-answers/issues)
* [Common errors you might run into during development](doc/common-errors.md)
* [Environments](doc/environments.md)
* [Continuous integration](doc/continuous-integration.md)
* [Describing pull requests](doc/pull-requests.md)
* [Deploying](doc/deploying.md)
* [Handling exceptions with Errbit](doc/errbit.md)
* [Rubocop](doc/rubocop.md)
* [Testing](doc/testing.md)
* [Updating worldwide fixture data](doc/updating-worldwide-fixture-data.md)
* [Issues and Todo](https://trello.com/b/7HgyU4hy/smart-answers-tasks)

### Debugging

Expand Down
48 changes: 29 additions & 19 deletions doc/adding-new-regression-tests.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Adding new regression tests

1. Update the flow to replace any single line conditionals around `Phraselist`s with multiple line conditionals. This is so that we get useful information from the running the coverage utility. Single line conditionals will show up as having been exercised irrespective of whether they caused something to be added to the `Phraselist`.
1. Update the flow to replace any single line conditionals with multiple line conditionals. This is so that we get useful information from running the coverage utility. Single line conditionals will show up as having been exercised irrespective of whether the code they were guarding was exercised.

# Replace single line conditional
phrases << :new_phrase if condition
```ruby
# Replace single line conditional
array << :value if condition

# With multiple line alternative
if condition
phrases << :new_phrase
end
# With multiple line alternative
if condition
array << :value
end
```

2. Generate a set of responses for the flow that you want to add regression tests to.

$ rails r script/generate-questions-and-responses-for-smart-answer.rb \
<name-of-smart-answer>
```bash
$ rails r script/generate-questions-and-responses-for-smart-answer.rb \
<name-of-smart-answer>
```

3. Commit the generated questions-and-responses.yml file (in test/data) to git.

Expand All @@ -29,18 +33,20 @@

6. Generate a set of input responses and expected results for the Smart Answer.

$ rm -rf coverage && \
TEST_COVERAGE=true \
rails r script/generate-responses-and-expected-results-for-smart-answer.rb \
<name-of-smart-answer>
```bash
$ rm -rf coverage && \
TEST_COVERAGE=true \
rails r script/generate-responses-and-expected-results-for-smart-answer.rb \
<name-of-smart-answer>
```

7. Inspect the code coverage report for the Smart Answer under test (`open coverage/rcov/index.html` and find the smart answer under test).

* If all the branches in the flow have been exercised then you don't need to do anything else at this time.

* Code in node-level blocks (e.g. in `value_question`, `date_question`, `multiple_choice` & `outcome` blocks) will always be executed at *flow-definition-time*, and so coverage of these lines is of **no** significance when assessing test coverage of the flow logic.

* Code in blocks inside node-level blocks (e.g. in `precalculate`, `next_node_calculation`, `validate` & `define_predicate` blocks) will be executed at *flow-execution-time*, and so coverage of these lines is of significance when assessing test coverage of the flow logic.
* Code in blocks inside node-level blocks (e.g. in `precalculate`, `next_node_calculation` & `validate` blocks) will be executed at *flow-execution-time*, and so coverage of these lines is of significance when assessing test coverage of the flow logic.

* Coverage of code in ancillary classes (e.g. calculators) should also be considered at this point.

Expand All @@ -54,16 +60,20 @@

9. Generate a yaml file containing the set of source files that this Smart Answer depends upon. The script will automatically take the ruby flow file, locale file and erb templates into account. You just need to supply it with the location of any additional files required by the Smart Answer (e.g. calculators and data files). This data is used to determine whether to run the regression tests based on whether the source files have changed.

$ rails r script/generate-checksums-for-smart-answer.rb \
<name-of-smart-answer> \
<path/to/additional/files>
```bash
$ rails r script/generate-checksums-for-smart-answer.rb \
<name-of-smart-answer> \
<path/to/additional/files>
```

10. Commit the generated yaml file to git.

11. Run the regression test to generate the Govspeak of each landing page and outcome reached by the set of input responses.

$ RUN_REGRESSION_TESTS=<name-of-smart-answer> \
ruby test/regression/smart_answers_regression_test.rb
```bash
$ RUN_REGRESSION_TESTS=<name-of-smart-answer> \
ruby test/regression/smart_answers_regression_test.rb
```

If you want individual tests to fail early when differences are detected, set `ASSERT_EACH_ARTEFACT=true`.
Note that this more than doubles the time it takes to run regression tests.
Expand Down
63 changes: 63 additions & 0 deletions doc/common-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Errors

A list of some of the errors you might run into when developing on Smart Answers locally.


## "NoMethodError" when visiting the root URL

You'll see this error if you visit the root URL of the Smart Answers app (e.g. http://localhost:3000 or http://smartanswers.dev.gov.uk/). This is because we don't have anything configured to respond at this path.

### Exception

```
NoMethodError at /
undefined method `to_html' for nil:NilClass
```

### Resolution

Visit a specific Smart Answer, e.g. /marriage-abroad.


## "SocketError" when viewing a Smart Answer

__NOTE.__ This is specifically when the exception is raised in `SmartAnswerPresenter#artefact`.

You'll see this error if the Smart Answers app can't connect to the Content API.

### Exception

```
SocketError at /marriage-abroad
getaddrinfo: nodename nor servname provided, or not known
```

### Resolution

There are a couple of solutions to this problem:

1. Set the `PLEK_SERVICE_CONTENTAPI_URI` environment variable to a valid host. NOTE. This doesn't need to be hosting the Content API (although you can use "https://www.gov.uk/api" if that's what you want), it simply needs to be a host that responds to HTTP requests.

2. Configure a web server (e.g. Apache) on your machine to respond to http://contentapi.dev.gov.uk. This is the default location of the Content API in development so configuring this means that you won't have to set the `PLEK_SERVICE_CONTENTAPI_URI` environment variable.


## "Slimmer::CouldNotRetrieveTemplate" when viewing a Smart Answer

You'll see this error if the Smart Answers app can't connect to the [Static][static] host.

### Exception

```
Slimmer::CouldNotRetrieveTemplate at /marriage-abroad
Unable to fetch: 'wrapper' from 'http://static.dev.gov.uk/templates/wrapper.html.erb' because getaddrinfo: nodename nor servname provided, or not known
```

### Resolution

There are a couple of solutions to this problem:

1. Set the `PLEK_SERVICE_STATIC_URI` environment variable to "https://assets-origin.preview.alphagov.co.uk", which is the static/assets server running in preview.

2. Run the static/assets server locally at http://static.dev.gov.uk. This is the default location of the static/asset server in development so configuring this means that you won't have to set the `PLEK_SERVICE_STATIC_URI` environment variable.

[static]: https://github.com/alphagov/static
4 changes: 3 additions & 1 deletion doc/content-ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Smart answers need content-ids. You can generate one by running:

$ be rails r "puts SecureRandom.uuid"
```bash
$ be rails r "puts SecureRandom.uuid"
```
78 changes: 78 additions & 0 deletions doc/creating-a-new-smart-answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Creating a new Smart Answer

This walks through the basics of creating a new Smart Answer.

## 1. Create a new skeleton flow

Start by creating a new file to hold the logic of our flow:

```bash
$ touch lib/smart_answer_flows/example-smart-answer.rb
```

Open the new file in your editor and copy/paste this skeleton flow:

```ruby
module SmartAnswer
class ExampleSmartAnswerFlow < Flow
def define
name 'example-smart-answer'

value_question :question_1 do
next_node :outcome_1
end

outcome :outcome_1
end
end
end
```

This flow contains a single question and a single outcome. Any non-empty response to `:question_1` will send you to `:outcome_1`.

If you were to run `rails server` and visit http://localhost:3000/example-smart-answer at this point, you'd see an error that indicates that we need to add a landing page template.

## 2. Create an ERB landing page template

Create a new file for our landing page template.

```
$ mkdir lib/smart_answer_flows/example-smart-answer
$ touch lib/smart_answer_flows/example-smart-answer/example_smart_answer.govspeak.erb
```

Although the landing page template needs to exist, it doesn't actually need to contain anything!

Assuming you're still running `rails server`, visit http://localhost:3000/example-smart-answer and you should see the empty landing page of our new Smart Answer.

Click "Start now" to visit the first question. You should see an error message indicating that we're now missing an ERB template for our question.

## 3. Create an ERB question page template

Create a new file for our question page template.

```
$ mkdir lib/smart_answer_flows/example-smart-answer/questions
$ touch lib/smart_answer_flows/example-smart-answer/questions/question_1.govspeak.erb
```

Although the question page template needs to exist, it doesn't actually need to contain anything!

Assuming you're still running `rails server`, visit http://localhost:3000/example-smart-answer and you should see an empty page containing a text field and a "Next step" button.

Enter any value in the text field and click "Next step". You should see an error message indicating that we're now missing an ERB template for the outcome.

## 4. Create an ERB outcome page template

Create a new file for our outcome page template.

```
$ mkdir lib/smart_answer_flows/example-smart-answer/outcomes
$ touch lib/smart_answer_flows/example-smart-answer/outcomes/outcome_1.govspeak.erb
```

Although the question page template needs to exist, it doesn't actually need to contain anything!

Assuming you're still running `rails server`, visit http://localhost:3000/example-smart-answer and you should see an empty page containing a list of "Previous answers".

And that's all there is to an incredibly simple Smart Answer.
13 changes: 13 additions & 0 deletions doc/developing-without-vm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Developing without using the VM

The simplest way to get Smart Answers running locally is to run:

```bash
$ PLEK_SERVICE_CONTENTAPI_URI=https://www.gov.uk/api \
PLEK_SERVICE_STATIC_URI=https://assets-origin.preview.alphagov.co.uk \
rails s
```

This tells Smart Answers to use the production Content API and the asset server from the preview environment.

If you don't set either environment variable then the app will attempt to connect to the content API and asset server at http://contentapi.dev.gov.uk and http://static.dev.gov.uk respectively. NOTE. These are available automatically if you're [developing using the VM](developing-using-vm.md). If the app can't connect to these hosts then you'll see [errors](common-errors.md).
27 changes: 27 additions & 0 deletions doc/development-principles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Smart Answer flows - Development principles

## Do's

* Make small improvements to the code before making even business-as-usual changes. See [refactoring existing Smart Answers](refactoring.md) for some common improvements.

* Make use of the higher-level abstractions available in the project, for example the `DateRange`, `YearRange` and `TaxYear` classes.

* Extract more higher-level abstractions where the same behaviour is being duplicated across multiple flows.

* Model the domain of the policy/rules that make up a Smart Answer.

* Ensure all policy logic is encapsulated in objects that are instantiated by (but separate from) the flow.

* Ensure all presentation logic is kept in the ERB templates and associated helper methods.

* Ensure the Smart Answer flows only contain routing (`next_node`) logic.

* Iteratively develop new Smart Answers. Get a simply happy-path version deployed and build upon that in collaboration with the department and content team.

## Dont's

* Don't copy the style of existing "legacy" Smart Answers (e.g. [calculate-agricultural-holiday-entitlement](https://github.com/alphagov/smart-answers/blob/829837f1f738c711985bf3a7a5d1655605637edd/lib/smart_answer_flows/calculate-agricultural-holiday-entitlement.rb)).

* Don't blindly follow the logic documents when creating/amending Smart Answers. This has lead to some of the problems we see in the "legacy" Smart Answers, e.g. policy logic being mixed up with flow/routing logic resulting in hard to maintain code.

* Don't do big-bang development of new Smart Answers. See the point about iteratively developing them in the "Do's" section above.
22 changes: 22 additions & 0 deletions doc/environments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Environments

Smart Answers are available in Preview (e.g. [marriage-abroad][marriage-abroad-preview]), Staging (e.g. [marriage-abroad][marriage-abroad-staging]) and Production (e.g. [marriage-abroad][marriage-abroad-production]).

## Preview

Preview is deployed to automatically after a successful build of the master branch on Jenkins.

Preview differs from Staging and Production in that it'll show draft Smart Answers and allow you to [display outcomes as Govspeak](viewing-templates-as-govspeak.md).

## Staging

Staging is deployed to manually during the [deployment process][deployment-doc]. We check that everything is working as expected before deploying to production.

## Production

Production is deployed to manually during the deployment process, once we're happy that the deployment to Staging has worked as expected.

[deployment-doc]: deploying.md
[marriage-abroad-preview]: https://www.preview.alphagov.co.uk/marriage-abroad
[marriage-abroad-staging]: https://www.staging.publishing.service.gov.uk/marriage-abroad
[marriage-abroad-production]: https://www.gov.uk/marriage-abroad
11 changes: 11 additions & 0 deletions doc/erb-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ERB templates

Content is defined in `content_for` blocks.

Any state variable defined in the flow is available to be used in the ERB template. See [storing data](storing-data.md) for the various ways that you can set state variables.

We remove all leading spaces from the content in the `content_for` blocks before processing it using Govspeak. This allows us to indent the content in the `content_for` blocks without having to worry about it affecting the generated HTML when it's processed using Govspeak.

* [Landing page templates](landing-page-template.md)
* [Question templates](question-templates.md)
* [Outcome templates](outcome-templates.md)
Loading