Browse Source

Merge 45e9b75f07 into c54204af53

pull/3151/merge
Katherine Langford 1 day ago committed by GitHub
parent
commit
602c61cc30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      docs/adr/index.md
  2. 8
      docs/dev_tasks/index.md
  3. 124
      docs/dev_tasks/new_question.md
  4. 2
      docs/documentation_website.md
  5. 121
      docs/form/question.md
  6. 10
      docs/setup.md

2
docs/adr/index.md

@ -1,6 +1,6 @@
---
has_children: true
nav_order: 14
nav_order: 15
---
# Architecture decisions

8
docs/dev_tasks/index.md

@ -0,0 +1,8 @@
---
has_children: true
nav_order: 14
---
# Common dev tasks
A collection of guides for tasks that may have to be carried out repeatedly.

124
docs/dev_tasks/new_question.md

@ -0,0 +1,124 @@
---
parent: Common dev tasks
nav_order: 1
---
# New Questions
Concerns adding a brand-new question to Lettings Logs or Sales Logs. This question will appear on the website as part of the Sales form and should be handled in Bulk Uploads.
Note: this document focuses on Sales Logs but the steps are equivalent for Lettings Logs by replacing `sales` with `lettings` in file paths etc.
Guide is up-to-date as of 2026.
## Basic checklist of tasks
### 1. Create a migration to add the new field to the database
This allows the answer to the new question to be saved.
You can create a new empty migration file from the terminal if you are in the root of the project:
```
bin/rails generate migration NameOfMigration
```
The new migration file will be saved in `db/migrate`.
Whilst the specifics will vary, the new migration file should look something like this:
```ruby
class AddSexRegisteredAtBirthToSalesLogs < ActiveRecord::Migration[7.2]
def change
# Add a new column called "name" of type string to the sales_logs table
change_table :sales_logs, bulk: true do |t|
t.column :name, :string
end
end
end
```
See also: [Active record migrations](https://guides.rubyonrails.org/active_record_migrations.html)
### 2. Run the new migration
`bundle exec rake db:migrate`
This will update `schema.rb`. You should not edit `schema.rb` directly.
### 3. Create a new question class
This will define the question that gets rendered on the online form.
Existing question classes can be found in `app/models/form/sales/questions/`. Depending on the type of question (checkboxes, radio groups, free-text fields), there will almost certainly be an existing question class that you can refer to as a guide.
For example, if you need to create a new radio form, then you may want to copy `armed_forces.rb`.
See also: [Question]({% link form/question.md %})
### 4. Create a new page class
This creates the page that your new question will be rendered on.
Existing page classes can be found in `app/models/form/sales/pages`.
Usually there is only one question per page, but in some cases there may be multiple. It may not be necessary to create a new page if the new question is being added to an existing one.
See also: [Page]({% link form/page.md %})
### 5. Add new page to an existing subsection
Without this step, your new page will not be inserted into the form!
Subsections can be found in `app/models/form/sales/subsections`.
You will want to add your new page to the appropriate place in the list returned by `def pages`.
To make your new page only appear in the forms for the upcoming year, you wrap the page class in parentheses and add a conditional expression to the end, like so:
```ruby
(Form::Sales::Pages::SexRegisteredAtBirth1.new(nil, nil, self) if form.start_year_2026_or_later?),
```
Note: the `@id` attribute of a page is what will be displayed in the url when visiting it. It must be unique within a collection year (i.e. two pages in 25/26 cannot share an ID, but two pages in different collection years can share an ID).
### 6. Update the locale file
The locale files define some of the text for the new question, including hints and the question itself.
Locale files can be found in `config/locales/forms/<year>/sales/` and there is one locale file for each form subsection.
Copy the entry for an existing question and substitute in the text for your new one.
### 7. Include the new field in exports
The fields that get exported in CSVs and XMLs are defined in `app/services/exports/sales_log_export_constants.rb`.
If there is not a set for POST\_<year>\_EXPORT_FIELDS, create one. Add your new field to the current year's set.
You may also have to update the `sales_log_export_service.rb` to correctly filter the year-specific fields.
### 8. Update the bulk upload row parser
This will allow bulk upload files to save the new field to the database.
You can find the relevant file at `app/services/bulk_upload/sales/year<year>/row_parser.rb`.
You will need to add a new `field_XXX` for the new field. In total, update the following places:
- Add the new field to `QUESTIONS` with the text of the question.
- Add a new attribute alongside the existing ones neat the top of the file:
```ruby
attribute :field_XXX, :type
```
- Add the new field to `field_mapping_for_errors` with the name of the field in the database.
- Add the new field to `attributes_for_log` with the name of the field in the database.
You may also have to add some additional validation rules in this file.
Validation for ensuring that the value uploaded is one of the permitted options is handled automatically, using the question class as the original source of truth.
### 9. Update unit tests
- Create new test files for any new classes you have created. Update any test files for files that you have edited.
- Update `spec/fixtures/variable_definitions/sales_download_25_26.csv` (for sales/lettings and for the relevant collection year) with the new question's field name and definition.

2
docs/documentation_website.md

@ -1,5 +1,5 @@
---
nav_order: 15
nav_order: 16
---
# This documentation website

121
docs/form/question.md

@ -6,81 +6,106 @@ nav_order: 4
# Question
_Updated for 2026._
Questions are under the page level of the form definition.
An example question might look something like this:
```
class Form::Sales::Questions::PostcodeKnown < ::Form::Question
```ruby
class Form::Sales::Questions::PreviousPostcodeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = postcode_known
@hint_text = ""
@header = "Do you know the property postcode?"
@check_answer_label = "Do you know the property postcode?"
@id = "ppcodenk"
@copy_key = "sales.household_situation.last_accommodation.ppcodenk"
@type = "radio"
@answer_options = {
"1" => { "value" => "Yes" },
"0" => { "value" => "No" }
},
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"postcode_full" => [1]
},
@hidden_in_check_answers = true
"ppostcode_full" => [0],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"ppcodenk" => 0,
},
{
"ppcodenk" => 1,
},
],
}
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
@disable_clearing_if_not_routed_or_dynamic_answer_options = true
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
QUESTION_NUMBER_FROM_YEAR = { 2023 => 57, 2024 => 59, 2025 => 57 }.freeze
end
```
In the above example the the question has the id `postcode_known`.
Let's take a look at the properties in the `initialize` function.
The `check_answer_label` contains the text that will be displayed in the label of the table on the check answers page.
<dl>
<dt>id</dt>
<dd>The name of the field. This should correspond to a column in the database. In the example, the id is 'ppcodenk'.</dd>
The header is text that is displayed for the question.
<dt>copy_key</dt>
<dd>This specifies copy from <code>config/locales/forms/...</code> that should be associated with the question</dd>
Hint text is optional, but if provided it sits under the header and is normally given to provide the data inputters with guidance when answering the question, for example it might inform them about terms used in the question.
<dt>type</dt>
<dd>Determines what type of question is rendered on the page. In the example, the question is a Radio Form so the <code>app/views/form/_radio_question.html.erb</code> partial will be rendered on the page when this question is displayed to the user</dd>
The type is question type, which is used to determine the view rendered for the question. In the above example the question is a radio type so the `app/views/form/_radio_question.html.erb` partial will be rendered on the page when this question is displayed to the user.
<dt>answer_options</dt>
<dd>Some types of question offer multiple options to pick from, which can be defined here. In the example, there are two options. The option that will be rendered with the label 'Yes' has the underlying value 0. The option with the label 'No' has the underlying value 1.</dd>
The `conditional_for` contains the value needed to be selected by the data inputter in order to display another question that appears on the same page. In the example above the `postcode_full` question depends on the answer to `postcode_known` being selected as `1` or `Yes`, this would then display the `postcode_full` underneath the `Yes` option on the page, allowing the provide the provide the postcode if they have indicated they know it. If the user has JavaScript enabled then this realtime conditional display is handled by the `app/frontend/controllers/conditional_question_controller.js` file.
<dt>conditional_for</dt>
<dd>Allows for additional questions to be rendered on the page if a certain value is chosen for the current question. In the example, if the value of this question is 0 (the 'Yes' option is selected), then the question with id 'ppostcode_full' will be rendered beneath the selected option.<br/>If the user has JavaScript enabled then this realtime conditional display is handled by the <code>app/frontend/controllers/conditional_question_controller.js</code> file.</dd>
the `hidden_in_check_answers` is used to hide a value from displaying on the check answers page. You only need to provide this if you want to set it to true in order to hide the value for some reason e.g. it's one of two questions appearing on a page and the other question is displayed on the check answers page. It's also worth noting that you can declare this as a with a `depends_on` which can be useful for conditionally displaying values on the check answers page. For example:
<dt>hidden_in_check_answers</dt>
<dd>
Allows us to hide the question on the 'check your answers' page. You only need to provide this if you want to set it to true in order to hide the value for some reason e.g. it's one of two questions appearing on a page and the other question is displayed on the check answers page.
<br/>
If <code>depends_on</code> is supplied, then whether this question is hidden can be made conditional on the answers provided to any question. In the example, the question is hidden if 'ppcodenk' (this question) has value 0 or 1. (As these are the only two possible answers, the question will always be hidden.)
</dd>
```
@hidden_in_check_answers = {
"depends_on" => [
{ "age6_known" => 0 },
{ "age6_known" => 1 }
]
}
```
Would mean the question the above is attached to would be hidden in the check answers page if the value of age6_known is either `0` or `1`.
<dt>question_number</dt>
<dd>
Determines which number gets rendered next to the question text on the question page and in the 'check your answers' page.
<br/>
The convention that we use for the question number is that we only add to the 'QUESTION_NUMBER_FROM_YEAR' hash when the question number changes. So, if the example remains unchanged into 2026, 2027, etc., that means that it is still question 57.
</dd>
</dl>
The answer the data inputter provides to some questions allows us to infer the values of other questions we might have asked in the form, allowing us to save the data inputters some time. An example of how this might look is as follows:
Another example shows us some fields that are used when we want to infer the answers to one question based on a user's answers to another question. This can allow the user to have to answer fewer questions, lowering their total number of clicks.
```
class Form::Sales::Questions::PostcodeFull < ::Form::Question
```ruby
class Form::Sales::Questions::PostcodeForFullAddress < ::Form::Question
def initialize(id, hsh, page)
super
@id = postcode_full
@hint_text = ""
@header = "What is the property’s postcode?""
@check_answer_label = "Postcode""
@type = "text"
@width = 5
@id = "postcode_full"
@inferred_check_answers_value = [{
"condition" => {
"pcodenk" => 1,
},
"value" => "Not known",
}]
@inferred_answers = {
"la" => { "is_la_inferred" => true }
"la" => {
"is_la_inferred" => true,
},
}
@inferred_check_answers_value => [{
"condition" => { "postcode_known" => 0 },
"value": "Not known"
}]
# Other fields omitted for brevity
end
end
```
In the above example the width is an optional attribute and can be provided for text type questions to determine the width of the text box on the page when when the question is displayed to a user (this allows you to match the width of the text box on the page to that of the design for a question).
The above example links to the first example as both of these questions would be on the same page. The `inferred_check_answers_value` is what should be displayed on the check answers page for this question if we infer it. If the value of `postcode_known` was given as `0` (which is a no), as seen in the condition part of `inferred_check_answers_value` then we can infer that the data inputter does not know the postcode and so we would display the value of `Not known` on the check answers page for the postcode.
<dl>
<dt>inferred_check_answers_value</dt>
<dd>Determines what gets shown on the 'check your answers' page if we infer the answer to this question. In the example, if the question 'pcodenk' has value 1 (indicating that the postcode is not known), then the answer shown for this question will be 'Not known'.</dd>
In the above example the `inferred_answers` refers to a question where we can infer the answer based on the answer of this question. In this case the `la` question can be inferred from the postcode value given by the data inputter as we are able to lookup the local authority based on the postcode given. We then set a property on the lettings log `is_la_inferred` to true to indicate that this is an answer we've inferred.
<dt>inferred_answers</dt>
<dd>Determines any questions whose answers can be inferred based on the answer to this question. In the example, the 'la' question (Local Authority) can be inferred from the Postcode. We set a property 'is_la_inferred' on the log to record this inferrance.</dd>
</dl>

10
docs/setup.md

@ -18,6 +18,14 @@ We recommend using [RBenv](https://github.com/rbenv/rbenv) to manage Ruby versio
We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS versions.
## Instructions for Windows users
If you are working on a windows machine, you will want to install the tools on [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) as some of them are not native to windows. The instructions in these docs assume a Debian-based distribution, such as Ubuntu.
_You will see a significant performance degradation if you are running the server on WSL whilst the files are on windows._ Thus, make sure to clone the repository into your WSL instance.
Some windows IDEs, such as [VSCode](https://code.visualstudio.com/docs/remote/wsl) and [RubyMine](jetbrains.com/help/ruby/remote-development-starting-page.html#run_in_wsl_ij) can connect you to WSL, which will allow you to develop as though the files were on the local windows filesystem. Ignore any reccommendations that you might see suggesting you keep the files on windows - our experience is that both tests and page loads are much slower when the files are on windows.
## Pre-setup installation
1. Install PostgreSQL
@ -78,7 +86,7 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm) to manage NodeJS version
5. Install JavaScript dependencies
Note that we currently use node v16, which is no longer the latest LTS version so you will need to specify the version number when installing
Note that we currently use node v20, which is no longer the latest LTS version so you will need to specify the version number when installing
macOS (using nvm):

Loading…
Cancel
Save