Browse Source

Merge branch 'main' into CLDC-487/why-were-they-given-reasonable-preference

pull/52/head
Matthew Phelan 3 years ago
parent
commit
9b97a3eb47
  1. 6
      README.md
  2. 15
      app/controllers/case_logs_controller.rb
  3. 20
      app/models/case_log.rb
  4. 2
      config/forms/2021_2022.json
  5. 9
      db/migrate/20211015090040_update_property_number_of_times_relet_type.rb
  6. 0
      docs/adr/adr-001-initial-architecture-decisions.md
  7. 0
      docs/adr/adr-002-repositories.md
  8. 0
      docs/adr/adr-003-form-submission-flow.md
  9. 0
      docs/adr/adr-004-gov-paas.md
  10. 0
      docs/adr/adr-005-form-definition.md
  11. 0
      docs/adr/adr-006-saving-values.md
  12. 0
      docs/adr/adr-007-data-validations.md
  13. 1154
      docs/api/DLUHC-CORE-Data.v1.json
  14. 17
      docs/index.html
  15. 2
      spec/fixtures/complete_case_log.json
  16. 15
      spec/models/case_log_spec.rb
  17. 18
      spec/requests/case_log_controller_spec.rb

6
README.md

@ -4,6 +4,12 @@
This is the codebase for the Ruby on Rails app that will handle the submission of Lettings and Sales of Social Housing in England data.
## API documentation
API documentation can be found here: https://communitiesuk.github.io/mhclg-data-collection-beta/. This is driven by [OpenAPI docs](docs/api/DLUHC-CORE-Data.v1.json)
## Required Setup
Pre-requisites:

15
app/controllers/case_logs_controller.rb

@ -33,9 +33,18 @@ class CaseLogsController < ApplicationController
end
end
# We don't have a dedicated non-editable show view
def show
edit
respond_to do |format|
# We don't have a dedicated non-editable show view
format.html { edit }
format.json do
if (case_log = CaseLog.find_by(id: params[:id]))
render json: case_log, status: :ok
else
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
end
end
end
end
def edit
@ -90,7 +99,7 @@ class CaseLogsController < ApplicationController
private
API_ACTIONS = %w[create update destroy].freeze
API_ACTIONS = %w[create show update destroy].freeze
def question_responses(questions_for_page)
questions_for_page.each_with_object({}) do |(question_key, question_info), result|

20
app/models/case_log.rb

@ -29,6 +29,16 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_other_reason_for_leaving_last_settled_home(record)
if record.reason_for_leaving_last_settled_home == "Other" && record.other_reason_for_leaving_last_settled_home.blank?
record.errors.add :other_reason_for_leaving_last_settled_home, "If reason for leaving settled home is other then the other reason must be provided"
end
if record.reason_for_leaving_last_settled_home != "Other" && record.other_reason_for_leaving_last_settled_home.present?
record.errors.add :other_reason_for_leaving_last_settled_home, "The other reason must not be provided if the reason for leaving settled home was not other"
end
end
def validate(record)
# If we've come from the form UI we only want to validate the specific fields
# that have just been submitted. If we're submitting a log via API or Bulk Upload
@ -103,6 +113,14 @@ private
end
def mandatory_fields
attributes.except(*AUTOGENERATED_FIELDS)
required = attributes.except(*AUTOGENERATED_FIELDS)
dynamically_not_required = []
if reason_for_leaving_last_settled_home != "Other"
dynamically_not_required << "other_reason_for_leaving_last_settled_home"
end
required.delete_if { |key, _value| dynamically_not_required.include?(key) }
end
end

2
config/forms/2021_2022.json

@ -31,7 +31,7 @@
"hint_text": "",
"type": "numeric",
"min": 0,
"max": 150,
"max": 120,
"step": 1
}
}

9
db/migrate/20211015090040_update_property_number_of_times_relet_type.rb

@ -1,6 +1,9 @@
class UpdatePropertyNumberOfTimesReletType < ActiveRecord::Migration[6.1]
def change
remove_column :case_logs, :property_number_of_times_relet, :string
add_column :case_logs, :property_number_of_times_relet, :integer
def up
change_column :case_logs, :property_number_of_times_relet, "integer USING CAST(property_number_of_times_relet AS integer)"
end
def down
change_column :case_logs, :property_number_of_times_relet, :string
end
end

0
doc/adr/adr-001-initial-architecture-decisions.md → docs/adr/adr-001-initial-architecture-decisions.md

0
doc/adr/adr-002-repositories.md → docs/adr/adr-002-repositories.md

0
doc/adr/adr-003-form-submission-flow.md → docs/adr/adr-003-form-submission-flow.md

0
doc/adr/adr-004-gov-paas.md → docs/adr/adr-004-gov-paas.md

0
doc/adr/adr-005-form-definition.md → docs/adr/adr-005-form-definition.md

0
doc/adr/adr-006-saving-values.md → docs/adr/adr-006-saving-values.md

0
doc/adr/adr-007-data-validations.md → docs/adr/adr-007-data-validations.md

1154
docs/api/DLUHC-CORE-Data.v1.json

File diff suppressed because it is too large Load Diff

17
docs/index.html

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="//pagecdn.io/lib/swagger-ui/v3.31.1/swagger-ui.css">
<title>OpenAPI DLUHC CORE Data Collection</title>
<body><div id="openapi"><script src="//pagecdn.io/lib/swagger-ui/v3.31.1/swagger-ui-bundle.js"></script>
<script>
window.onload = function () {
const ui = SwaggerUIBundle({
url: "api/DLUHC-CORE-Data.v1.json",
dom_id: "#openapi"
})
}
</script>
</body>

2
spec/fixtures/complete_case_log.json vendored

@ -89,7 +89,7 @@
"chr_letting": false,
"cap_letting": false,
"outstanding_rent_or_charges": 25,
"other_reason_for_leaving_last_settled_home": "Other reason",
"other_reason_for_leaving_last_settled_home": null,
"accessibility_requirements_fully_wheelchair_accessible_housing": true,
"accessibility_requirements_wheelchair_access_to_essential_rooms": false,
"accessibility_requirements_level_access_housing": false,

15
spec/models/case_log_spec.rb

@ -58,6 +58,21 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "other reason for leaving last settled home validation" do
it "must be provided if main reason for leaving last settled home was given as other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Other",
other_reason_for_leaving_last_settled_home: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be provided if the main reason for leaving settled home is not other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Repossession",
other_reason_for_leaving_last_settled_home: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
describe "status" do

18
spec/requests/case_log_controller_spec.rb

@ -99,6 +99,24 @@ RSpec.describe CaseLogsController, type: :request do
end
end
describe "GET" do
let(:case_log) { FactoryBot.create(:case_log, :completed) }
let(:id) { case_log.id }
before do
get "/case_logs/#{id}", headers: headers
end
it "returns http success" do
expect(response).to have_http_status(:success)
end
it "returns a serialized Case Log" do
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq(case_log.status)
end
end
describe "PATCH" do
let(:case_log) do
FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "Old Value")

Loading…
Cancel
Save