From 654d4ae8e5f37a205b08b70512cb1da1f345181b Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 29 Oct 2021 13:32:51 +0100 Subject: [PATCH 01/14] add select --- app/views/form/_select_question.html.erb | 5 ++ config/forms/2021_2022.json | 78 ++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 app/views/form/_select_question.html.erb diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb new file mode 100644 index 000000000..c4d8dccdc --- /dev/null +++ b/app/views/form/_select_question.html.erb @@ -0,0 +1,5 @@ +<%= f.govuk_collection_select question_key, question["answer_options"], +:id, +:name, +label: { text: question["header"].html_safe, size: "l" }, +hint: { text: question["hint_text"] } %> \ No newline at end of file diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index f4cf447c3..257f5fdd7 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -3,6 +3,84 @@ "start_year": 2021, "end_year": 2022, "sections": { + "about_this_log": { + "label": "About this log", + "subsections": { + "about_this_log": { + "label": "About this log", + "pages": { + "gdpr_acceptance": { + "header": "About this log", + "description": "About this log", + "questions": { + "gdpr_acceptance": { + "check_answer_label": "", + "header": "Has the tenant or buyer seen the DLUHC privacy notice?", + "hint_text": "", + "type": "select", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + }, + "conditional_route_to": { + "organisation_details": { "gdpr_acceptance": "Yes" } + }, + "default_next_page": "gdpr_declined" + }, + "gdpr_declined": { + "header": "You cannot use this service", + "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", + "questions": { + } + }, + "organisation_details": { + "header": "About this log", + "description": "Organisation Details", + "questions": { + "property_owner_organisation": { + "check_answer_label": "", + "header": "Which organisation owns this property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "A", + "1": "B" + } + }, + "property_manager_organisation": { + "check_answer_label": "", + "header": "Which organisation manages this property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "A", + "1": "B" + } + } + } + }, + "sale_or_letting": { + "header": "About this log", + "description": "Is this a sale or a letting?", + "questions": { + "sale_or_letting": { + "check_answer_label": "", + "header": "Is this a sale or a letting?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Sale", + "1": "Letting" + } + } + } + } + } + } + } + }, "household": { "label": "About the household", "subsections": { From ec130db9ac90781a415a398a51cdef43ba1263c4 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Mon, 1 Nov 2021 13:30:48 +0000 Subject: [PATCH 02/14] add select box and pages, waiting for naming convetion meeting --- app/views/form/_select_question.html.erb | 16 +++-- config/forms/2021_2022.json | 90 +++++++++++++++++++++++- 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index c4d8dccdc..88c1a6058 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -1,5 +1,11 @@ -<%= f.govuk_collection_select question_key, question["answer_options"], -:id, -:name, -label: { text: question["header"].html_safe, size: "l" }, -hint: { text: question["hint_text"] } %> \ No newline at end of file + +<%= answers = question["answer_options"].map {|key, value| OpenStruct.new(id:key, name: value)} + f.govuk_collection_select :answer_id, + answers, + :id, + :name, + label: { text: question["header"]}, + hint: { text: question["hint_text"] } + %> + + diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 257f5fdd7..0808a1c54 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -76,7 +76,95 @@ } } } - } + }, + "tenant_same_property_renewal": { + "header": "About this log", + "description": "Is this a renewal to the same tenant in the same property?", + "questions": { + "sale_or_letting": { + "check_answer_label": "", + "header": "Is this a renewal to the same tenant in the same property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + } + }, + "tenancy_start_date": { + "header": "About this log", + "description": "", + "questions": { + "sale_or_letting": { + "check_answer_label": "When is the tenancy start date?", + "header": "What is the tenancy start date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + } + }, + "letting_type": { + "header": "About this log", + "description": "", + "questions": { + "rent_type": { + "check_answer_label": "What is the rent type?", + "header": "What is the rent type?", + "hint_text": "", + "type": "select", + "answer_options": { + "0": "Social Rent", + "1": "Affordable Rent", + "2": "London Affordable Rent", + "3": "Rent To Buy", + "4": "London Living Rent", + "5": "Other Intermediate Rent Product" + }, + "intermediate_rent_product_name": { + "check_answer_label": "Enter the product name", + "header": "What is intermediate rent product name?", + "type": "text", + "conditional_for": { + "rent_type": "Other Intermediate Rent Product" + } + }, + "needs_type": { + "check_answer_label": "What is the needs type?", + "header": "What is the needs type?", + "hint_text": "", + "type": "select", + "answer_options": { + "0": "Supported Housing", + "1": "General Needs" + } + } + }, + "sale_completion_date": { + "header": "About this log", + "description": "", + "questions": { + "sale_completion_date": { + "check_answer_label": "What is the sale completion date?", + "header": "What is the sale completion date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + } + }, + "purchaser_code": { + "header": "About this log", + "description": "", + "questions": { + "purchaser_code": { + "check_answer_label": "What is the purchaser code?", + "header": "What is the purchaser code?", + "hint_text": "", + "type": "text" + } + } + } } } } From df90dde03121237680e6d327531d6ee3ee7126f4 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Tue, 2 Nov 2021 14:00:42 +0000 Subject: [PATCH 03/14] add columns to about form --- app/controllers/case_logs_controller.rb | 2 +- app/views/form/_select_question.html.erb | 4 +-- config/forms/2021_2022.json | 26 +++++++++++++------ ...820_add_about_this_log_readable_columns.rb | 17 ++++++++++++ db/schema.rb | 13 +++++++++- 5 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20211102100820_add_about_this_log_readable_columns.rb diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 48fe5726d..6ac932b56 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -136,7 +136,7 @@ private content["conditional_route_to"].each do |route, conditions| if conditions.keys.all? { |x| case_log[x].present? } && conditions.all? { |k, v| v.include?(case_log[k]) } return "case_log_#{route}_path" - end + end end end form.next_page_redirect_path(previous_page) diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index 88c1a6058..6f41b6b35 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -1,8 +1,8 @@ <%= answers = question["answer_options"].map {|key, value| OpenStruct.new(id:key, name: value)} - f.govuk_collection_select :answer_id, + f.govuk_collection_select question_key, answers, - :id, + :name, :name, label: { text: question["header"]}, hint: { text: question["hint_text"] } diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 0808a1c54..6efc727f4 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -10,14 +10,14 @@ "label": "About this log", "pages": { "gdpr_acceptance": { - "header": "About this log", - "description": "About this log", + "header": "DLUHC Privacy Notice Acceptance", + "description": "", "questions": { "gdpr_acceptance": { - "check_answer_label": "", + "check_answer_label": "GDPR acceptance", "header": "Has the tenant or buyer seen the DLUHC privacy notice?", "hint_text": "", - "type": "select", + "type": "radio", "answer_options": { "0": "Yes", "1": "No" @@ -31,9 +31,12 @@ }, "gdpr_declined": { "header": "You cannot use this service", + "hint_text": "", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", "questions": { - } + + }, + "default_next_page" : "check_answers" }, "organisation_details": { "header": "About this log", @@ -74,14 +77,19 @@ "0": "Sale", "1": "Letting" } - } + }, + "conditional_route_to": { + "sale_completion_date": { "sale_or_letting": "Sale" }, + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : "check_answers" } }, "tenant_same_property_renewal": { "header": "About this log", "description": "Is this a renewal to the same tenant in the same property?", "questions": { - "sale_or_letting": { + "tenant_same_property_renewal": { "check_answer_label": "", "header": "Is this a renewal to the same tenant in the same property?", "hint_text": "", @@ -97,7 +105,7 @@ "header": "About this log", "description": "", "questions": { - "sale_or_letting": { + "tenancy_start_date": { "check_answer_label": "When is the tenancy start date?", "header": "What is the tenancy start date?", "hint_text": "For example, 27 3 2007", @@ -121,6 +129,7 @@ "3": "Rent To Buy", "4": "London Living Rent", "5": "Other Intermediate Rent Product" + } }, "intermediate_rent_product_name": { "check_answer_label": "Enter the product name", @@ -138,6 +147,7 @@ "answer_options": { "0": "Supported Housing", "1": "General Needs" + } } } }, diff --git a/db/migrate/20211102100820_add_about_this_log_readable_columns.rb b/db/migrate/20211102100820_add_about_this_log_readable_columns.rb new file mode 100644 index 000000000..b451af20e --- /dev/null +++ b/db/migrate/20211102100820_add_about_this_log_readable_columns.rb @@ -0,0 +1,17 @@ +class AddAboutThisLogReadableColumns < ActiveRecord::Migration[6.1] + def change + change_table :case_logs, bulk: true do |t| + t.column :gdpr_acceptance, :string + t.column :gdpr_declined, :string + t.column :property_owner_organisation, :string + t.column :property_manager_organisation, :string + t.column :sale_or_letting, :string + t.column :tenant_same_property_renewal, :string + t.column :rent_type, :string + t.column :intermediate_rent_product_name, :string + t.column :needs_type, :string + t.column :sale_completion_date, :string + t.column :purchaser_code, :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 346f047c2..c29297c23 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_27_123535) do +ActiveRecord::Schema.define(version: 2021_11_02_100820) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,6 +133,17 @@ ActiveRecord::Schema.define(version: 2021_10_27_123535) do t.boolean "reasonable_preference_reason_do_not_know" t.datetime "discarded_at" t.string "other_tenancy_type" + t.string "gdpr_acceptance" + t.string "gdpr_declined" + t.string "property_owner_organisation" + t.string "property_manager_organisation" + t.string "sale_or_letting" + t.string "tenant_same_property_renewal" + t.string "rent_type" + t.string "intermediate_rent_product_name" + t.string "needs_type" + t.string "sale_completion_date" + t.string "purchaser_code" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end From 8d3ff3060af546b623eb1c78782c65e9b4af8cb4 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Tue, 2 Nov 2021 14:33:01 +0000 Subject: [PATCH 04/14] conditional fors must be arr --- config/forms/2021_2022.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 6efc727f4..977a2e89e 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -136,7 +136,7 @@ "header": "What is intermediate rent product name?", "type": "text", "conditional_for": { - "rent_type": "Other Intermediate Rent Product" + "rent_type": ["Other Intermediate Rent Product"] } }, "needs_type": { From f14597bbbc78fac51c93482e015a339f420173c3 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 3 Nov 2021 09:54:47 +0000 Subject: [PATCH 05/14] added aboutthislog test json --- app/helpers/check_answers_helper.rb | 2 + config/forms/2021_2022.json | 5 +- ...00820_add_about_this_log_readable_columns} | 0 db/schema.rb | 13 +- spec/fixtures/forms/test_aboutthislog.json | 181 ++++++++++++++++++ 5 files changed, 185 insertions(+), 16 deletions(-) rename db/migrate/{20211102100820_add_about_this_log_readable_columns.rb => 20211102100820_add_about_this_log_readable_columns} (100%) create mode 100644 spec/fixtures/forms/test_aboutthislog.json diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 3e59de811..ff5312cce 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -58,6 +58,8 @@ module CheckAnswersHelper case_log[question_key].blank? || !case_log[question_key].send(operator, operand) when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) + when "select" + case_log[question_key].blank? || !condition.include?(case_log[question_key]) else raise "Not implemented yet" end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 977a2e89e..662cf9cec 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -33,9 +33,6 @@ "header": "You cannot use this service", "hint_text": "", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", - "questions": { - - }, "default_next_page" : "check_answers" }, "organisation_details": { @@ -82,7 +79,7 @@ "sale_completion_date": { "sale_or_letting": "Sale" }, "tenant_same_property_renewal": { "sale_or_letting": "Letting" } }, - "default_next_page" : "check_answers" + "default_next_page" : ["check_answers"] } }, "tenant_same_property_renewal": { diff --git a/db/migrate/20211102100820_add_about_this_log_readable_columns.rb b/db/migrate/20211102100820_add_about_this_log_readable_columns similarity index 100% rename from db/migrate/20211102100820_add_about_this_log_readable_columns.rb rename to db/migrate/20211102100820_add_about_this_log_readable_columns diff --git a/db/schema.rb b/db/schema.rb index c29297c23..346f047c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_02_100820) do +ActiveRecord::Schema.define(version: 2021_10_27_123535) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,17 +133,6 @@ ActiveRecord::Schema.define(version: 2021_11_02_100820) do t.boolean "reasonable_preference_reason_do_not_know" t.datetime "discarded_at" t.string "other_tenancy_type" - t.string "gdpr_acceptance" - t.string "gdpr_declined" - t.string "property_owner_organisation" - t.string "property_manager_organisation" - t.string "sale_or_letting" - t.string "tenant_same_property_renewal" - t.string "rent_type" - t.string "intermediate_rent_product_name" - t.string "needs_type" - t.string "sale_completion_date" - t.string "purchaser_code" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/fixtures/forms/test_aboutthislog.json b/spec/fixtures/forms/test_aboutthislog.json new file mode 100644 index 000000000..5f4313bd0 --- /dev/null +++ b/spec/fixtures/forms/test_aboutthislog.json @@ -0,0 +1,181 @@ +{ + "form_type": "lettings", + "sections": { + "about_this_log": { + "label": "About this log", + "subsections": { + "about_this_log": { + "label": "About this log", + "pages": { + "gdpr_acceptance": { + "header": "DLUHC Privacy Notice Acceptance", + "description": "", + "questions": { + "gdpr_acceptance": { + "check_answer_label": "GDPR acceptance", + "header": "Has the tenant or buyer seen the DLUHC privacy notice?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + }, + "conditional_route_to": { + "organisation_details": { "gdpr_acceptance": "Yes" } + }, + "default_next_page": "gdpr_declined" + }, + "gdpr_declined": { + "header": "You cannot use this service", + "hint_text": "", + "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", + "questions": { + + }, + "default_next_page" : "check_answers" + }, + "organisation_details": { + "header": "About this log", + "description": "Organisation Details", + "questions": { + "property_owner_organisation": { + "check_answer_label": "", + "header": "Which organisation owns this property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "A", + "1": "B" + } + }, + "property_manager_organisation": { + "check_answer_label": "", + "header": "Which organisation manages this property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "A", + "1": "B" + } + } + } + }, + "sale_or_letting": { + "header": "About this log", + "description": "Is this a sale or a letting?", + "questions": { + "sale_or_letting": { + "check_answer_label": "", + "header": "Is this a sale or a letting?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Sale", + "1": "Letting" + } + }, + "conditional_route_to": { + "sale_completion_date": { "sale_or_letting": "Sale" }, + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : ["check_answers"] + } + }, + "tenant_same_property_renewal": { + "header": "About this log", + "description": "Is this a renewal to the same tenant in the same property?", + "questions": { + "tenant_same_property_renewal": { + "check_answer_label": "", + "header": "Is this a renewal to the same tenant in the same property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + } + }, + "tenancy_start_date": { + "header": "About this log", + "description": "", + "questions": { + "tenancy_start_date": { + "check_answer_label": "When is the tenancy start date?", + "header": "What is the tenancy start date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + } + }, + "letting_type": { + "header": "About this log", + "description": "", + "questions": { + "rent_type": { + "check_answer_label": "What is the rent type?", + "header": "What is the rent type?", + "hint_text": "", + "type": "select", + "answer_options": { + "0": "Social Rent", + "1": "Affordable Rent", + "2": "London Affordable Rent", + "3": "Rent To Buy", + "4": "London Living Rent", + "5": "Other Intermediate Rent Product" + } + }, + "intermediate_rent_product_name": { + "check_answer_label": "Enter the product name", + "header": "What is intermediate rent product name?", + "type": "text", + "conditional_for": { + "rent_type": ["Other Intermediate Rent Product"] + } + }, + "needs_type": { + "check_answer_label": "What is the needs type?", + "header": "What is the needs type?", + "hint_text": "", + "type": "select", + "answer_options": { + "0": "Supported Housing", + "1": "General Needs" + } + } + } + }, + "sale_completion_date": { + "header": "About this log", + "description": "", + "questions": { + "sale_completion_date": { + "check_answer_label": "What is the sale completion date?", + "header": "What is the sale completion date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + } + }, + "purchaser_code": { + "header": "About this log", + "description": "", + "questions": { + "purchaser_code": { + "check_answer_label": "What is the purchaser code?", + "header": "What is the purchaser code?", + "hint_text": "", + "type": "text" + } + } + } + } + } + } + } + } +} From ca367d612dbef16cce8bba2f72fb6d8f25bf2957 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 3 Nov 2021 14:43:49 +0000 Subject: [PATCH 06/14] switch test form --- app/helpers/check_answers_helper.rb | 18 ++++++++++++-- config/forms/2021_2022.json | 24 ++++++++++--------- ...20_add_about_this_log_readable_columns.rb} | 0 db/schema.rb | 13 +++++++++- spec/fixtures/forms/test_aboutthislog.json | 21 ++++++++-------- 5 files changed, 51 insertions(+), 25 deletions(-) rename db/migrate/{20211102100820_add_about_this_log_readable_columns => 20211102100820_add_about_this_log_readable_columns.rb} (100%) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index ff5312cce..053c19f89 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -28,12 +28,25 @@ module CheckAnswersHelper def filter_conditional_questions(questions, case_log) applicable_questions = questions + # puts applicable_questions.count questions.each do |k, question| + + # if k == "default_next_page" + # applicable_questions = applicable_questions.reject { |z| z == "default_next_page" } + # else + # question.fetch("conditional_for", []).each do |conditional_question_key, condition| + # if condition_not_met(case_log, k, question, condition) + # applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } + # end + # end + # end + question.fetch("conditional_for", []).each do |conditional_question_key, condition| if condition_not_met(case_log, k, question, condition) applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } end end + end applicable_questions end @@ -56,13 +69,14 @@ module CheckAnswersHelper operator = condition[/[<>=]+/].to_sym operand = condition[/\d+/].to_i case_log[question_key].blank? || !case_log[question_key].send(operator, operand) + when "text" + case_log[question_key].blank? || !condition.include?(case_log[question_key]) when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) when "select" case_log[question_key].blank? || !condition.include?(case_log[question_key]) else - raise "Not implemented yet" - end + raise "Not implemented yet" end end def create_update_answer_link(case_log_answer, case_log_id, page) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 662cf9cec..8355b4f93 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -33,6 +33,9 @@ "header": "You cannot use this service", "hint_text": "", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", + "questions": { + + }, "default_next_page" : "check_answers" }, "organisation_details": { @@ -74,13 +77,12 @@ "0": "Sale", "1": "Letting" } - }, - "conditional_route_to": { - "sale_completion_date": { "sale_or_letting": "Sale" }, - "tenant_same_property_renewal": { "sale_or_letting": "Letting" } - }, - "default_next_page" : ["check_answers"] - } + } + }, + "conditional_route_to": { + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : "check_answers" }, "tenant_same_property_renewal": { "header": "About this log", @@ -126,15 +128,15 @@ "3": "Rent To Buy", "4": "London Living Rent", "5": "Other Intermediate Rent Product" + }, + "conditional_for": { + "intermediate_rent_product_name": ["Other Intermediate Rent Product"] } }, "intermediate_rent_product_name": { "check_answer_label": "Enter the product name", "header": "What is intermediate rent product name?", - "type": "text", - "conditional_for": { - "rent_type": ["Other Intermediate Rent Product"] - } + "type": "text" }, "needs_type": { "check_answer_label": "What is the needs type?", diff --git a/db/migrate/20211102100820_add_about_this_log_readable_columns b/db/migrate/20211102100820_add_about_this_log_readable_columns.rb similarity index 100% rename from db/migrate/20211102100820_add_about_this_log_readable_columns rename to db/migrate/20211102100820_add_about_this_log_readable_columns.rb diff --git a/db/schema.rb b/db/schema.rb index 346f047c2..c29297c23 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_27_123535) do +ActiveRecord::Schema.define(version: 2021_11_02_100820) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,6 +133,17 @@ ActiveRecord::Schema.define(version: 2021_10_27_123535) do t.boolean "reasonable_preference_reason_do_not_know" t.datetime "discarded_at" t.string "other_tenancy_type" + t.string "gdpr_acceptance" + t.string "gdpr_declined" + t.string "property_owner_organisation" + t.string "property_manager_organisation" + t.string "sale_or_letting" + t.string "tenant_same_property_renewal" + t.string "rent_type" + t.string "intermediate_rent_product_name" + t.string "needs_type" + t.string "sale_completion_date" + t.string "purchaser_code" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/fixtures/forms/test_aboutthislog.json b/spec/fixtures/forms/test_aboutthislog.json index 5f4313bd0..2cfd8ff26 100644 --- a/spec/fixtures/forms/test_aboutthislog.json +++ b/spec/fixtures/forms/test_aboutthislog.json @@ -75,13 +75,12 @@ "0": "Sale", "1": "Letting" } - }, - "conditional_route_to": { - "sale_completion_date": { "sale_or_letting": "Sale" }, - "tenant_same_property_renewal": { "sale_or_letting": "Letting" } - }, - "default_next_page" : ["check_answers"] - } + } + }, + "conditional_route_to": { + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : "check_answers" }, "tenant_same_property_renewal": { "header": "About this log", @@ -127,15 +126,15 @@ "3": "Rent To Buy", "4": "London Living Rent", "5": "Other Intermediate Rent Product" + }, + "conditional_for": { + "intermediate_rent_product_name": ["Other Intermediate Rent Product"] } }, "intermediate_rent_product_name": { "check_answer_label": "Enter the product name", "header": "What is intermediate rent product name?", - "type": "text", - "conditional_for": { - "rent_type": ["Other Intermediate Rent Product"] - } + "type": "text" }, "needs_type": { "check_answer_label": "What is the needs type?", From de2ebc6aea812884ada1ac91080dff776bc6bd1f Mon Sep 17 00:00:00 2001 From: magicmilo Date: Thu, 4 Nov 2021 11:48:30 +0000 Subject: [PATCH 07/14] commit --- app/helpers/check_answers_helper.rb | 16 ++-------------- spec/helpers/check_answers_helper_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 053c19f89..37debfd8c 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -15,6 +15,7 @@ module CheckAnswersHelper page_name = subsection_keys.first while page_name.to_s != "check_answers" && subsection_keys.include?(page_name) + binding.pry questions = form.questions_for_page(page_name) applicable_questions = filter_conditional_questions(questions, case_log) total_questions = total_questions.merge(applicable_questions) @@ -30,23 +31,11 @@ module CheckAnswersHelper # puts applicable_questions.count questions.each do |k, question| - - # if k == "default_next_page" - # applicable_questions = applicable_questions.reject { |z| z == "default_next_page" } - # else - # question.fetch("conditional_for", []).each do |conditional_question_key, condition| - # if condition_not_met(case_log, k, question, condition) - # applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } - # end - # end - # end - question.fetch("conditional_for", []).each do |conditional_question_key, condition| if condition_not_met(case_log, k, question, condition) applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } end end - end applicable_questions end @@ -64,6 +53,7 @@ module CheckAnswersHelper end def condition_not_met(case_log, question_key, question, condition) + binding.pry case question["type"] when "numeric" operator = condition[/[<>=]+/].to_sym @@ -73,8 +63,6 @@ module CheckAnswersHelper case_log[question_key].blank? || !condition.include?(case_log[question_key]) when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) - when "select" - case_log[question_key].blank? || !condition.include?(case_log[question_key]) else raise "Not implemented yet" end end diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 3eae2227c..4d45c164d 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -98,7 +98,9 @@ RSpec.describe CheckAnswersHelper do "hint_text" => "", "type" => "date", "check_answer_label" => "Question Label", - "conditional_for" => { "question_2" => %w[12-12-2021] } } } + "conditional_for" => { "question_2" => %w[12-12-2021] } + } + } end it "raises an error" do From 3b0efa52934456ae6cf52dd3bf5808dd643491f2 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Thu, 4 Nov 2021 12:05:18 +0000 Subject: [PATCH 08/14] fixed broken test --- app/helpers/check_answers_helper.rb | 6 ++++-- spec/fixtures/forms/test_form.json | 2 +- spec/helpers/check_answers_helper_spec.rb | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 37debfd8c..4cafe3731 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -14,8 +14,10 @@ module CheckAnswersHelper subsection_keys = form.pages_for_subsection(subsection).keys page_name = subsection_keys.first + # binding.pry + while page_name.to_s != "check_answers" && subsection_keys.include?(page_name) - binding.pry + # binding.pry questions = form.questions_for_page(page_name) applicable_questions = filter_conditional_questions(questions, case_log) total_questions = total_questions.merge(applicable_questions) @@ -53,7 +55,7 @@ module CheckAnswersHelper end def condition_not_met(case_log, question_key, question, condition) - binding.pry + # binding.pry case question["type"] when "numeric" operator = condition[/[<>=]+/].to_sym diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index 35590cb3e..ab1b69c76 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -497,7 +497,7 @@ "check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", - "type": "text", + "type": "date", "conditional_for": { "faake_key": "fake_condition" } } } diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 4d45c164d..38db2ef6b 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -104,7 +104,7 @@ RSpec.describe CheckAnswersHelper do end it "raises an error" do - allow_any_instance_of(Form).to receive(:pages_for_subsection).and_return(unimplemented_conditional) + allow_any_instance_of(Form).to receive(:questions_for_page).and_return(unimplemented_conditional) expect { total_number_of_questions(subsection, case_log, form) }.to raise_error(RuntimeError, "Not implemented yet") end end From dcad47cbe77dd541db04efac3fd2ecd0d092d3fd Mon Sep 17 00:00:00 2001 From: magicmilo Date: Thu, 4 Nov 2021 12:15:45 +0000 Subject: [PATCH 09/14] return test_form data to text --- spec/fixtures/forms/test_form.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index ab1b69c76..35590cb3e 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -497,7 +497,7 @@ "check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", - "type": "date", + "type": "text", "conditional_for": { "faake_key": "fake_condition" } } } From c383493f5e9b4787baeae3fa8ae3121fd39e7fa6 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 09:55:35 +0000 Subject: [PATCH 10/14] add new fields to completecaselog --- spec/fixtures/complete_case_log.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 9238bba6a..3647c6163 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -112,6 +112,18 @@ "reasonable_preference_reason_unsatisfactory_housing": false, "reasonable_preference_reason_medical_grounds": false, "reasonable_preference_reason_avoid_hardship": false, - "reasonable_preference_reason_do_not_know": true + "reasonable_preference_reason_do_not_know": true, + "other_tenancy_type": "", + "gdpr_acceptance": "", + "gdpr_declined": "", + "property_owner_organisation": "", + "property_manager_organisation": "", + "sale_or_letting": "", + "tenant_same_property_renewal": "", + "rent_type": "", + "intermediate_rent_product_name": "", + "needs_type": "", + "sale_completion_date" : "", + "purchaser_code": "" } } From acfe2622e01d6fdc10747c87aa05897ebef3ed47 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 09:57:37 +0000 Subject: [PATCH 11/14] remove debug lines --- app/helpers/check_answers_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 4cafe3731..92bedb2a0 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -14,10 +14,7 @@ module CheckAnswersHelper subsection_keys = form.pages_for_subsection(subsection).keys page_name = subsection_keys.first - # binding.pry - while page_name.to_s != "check_answers" && subsection_keys.include?(page_name) - # binding.pry questions = form.questions_for_page(page_name) applicable_questions = filter_conditional_questions(questions, case_log) total_questions = total_questions.merge(applicable_questions) @@ -55,7 +52,6 @@ module CheckAnswersHelper end def condition_not_met(case_log, question_key, question, condition) - # binding.pry case question["type"] when "numeric" operator = condition[/[<>=]+/].to_sym From 0d82814fee1499d6cf35d6879034f687a1f60293 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 10:42:02 +0000 Subject: [PATCH 12/14] remove debug line and rubocop --- app/controllers/case_logs_controller.rb | 2 +- app/helpers/check_answers_helper.rb | 3 +-- spec/helpers/check_answers_helper_spec.rb | 4 +--- spec/models/case_log_spec.rb | 5 +++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 6ac932b56..48fe5726d 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -136,7 +136,7 @@ private content["conditional_route_to"].each do |route, conditions| if conditions.keys.all? { |x| case_log[x].present? } && conditions.all? { |k, v| v.include?(case_log[k]) } return "case_log_#{route}_path" - end + end end end form.next_page_redirect_path(previous_page) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 92bedb2a0..5a8369ade 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -28,7 +28,6 @@ module CheckAnswersHelper def filter_conditional_questions(questions, case_log) applicable_questions = questions - # puts applicable_questions.count questions.each do |k, question| question.fetch("conditional_for", []).each do |conditional_question_key, condition| if condition_not_met(case_log, k, question, condition) @@ -62,7 +61,7 @@ module CheckAnswersHelper when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) else - raise "Not implemented yet" end + raise "Not implemented yet" end end def create_update_answer_link(case_log_answer, case_log_id, page) diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 38db2ef6b..5ac16b2bd 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -98,9 +98,7 @@ RSpec.describe CheckAnswersHelper do "hint_text" => "", "type" => "date", "check_answer_label" => "Question Label", - "conditional_for" => { "question_2" => %w[12-12-2021] } - } - } + "conditional_for" => { "question_2" => %w[12-12-2021] } } } end it "raises an error" do diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index d95f000a7..8ac7d349d 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -198,10 +198,11 @@ RSpec.describe Form, type: :model do # Crossover over tests here as injured must be answered as well for no error it "must be answered if ever served in the forces as a regular" do - expect { + expect do CaseLog.create!(armed_forces: "Yes - a regular", armed_forces_active: "Yes", - armed_forces_injured: "Yes")} + armed_forces_injured: "Yes") + end end end From ebb564052ac0dbd8e6a31b80e739dc39347d23a4 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 10:46:14 +0000 Subject: [PATCH 13/14] remove end --- app/helpers/check_answers_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 5a8369ade..21b6d4f1a 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -61,7 +61,7 @@ module CheckAnswersHelper when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) else - raise "Not implemented yet" end + raise "Not implemented yet" end def create_update_answer_link(case_log_answer, case_log_id, page) From cff0083aec0770a69c5b4bf730800f3fd00452db Mon Sep 17 00:00:00 2001 From: magicmilo Date: Fri, 5 Nov 2021 10:47:28 +0000 Subject: [PATCH 14/14] move end --- app/helpers/check_answers_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 21b6d4f1a..1cc1bc65e 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -62,6 +62,7 @@ module CheckAnswersHelper case_log[question_key].blank? || !condition.include?(case_log[question_key]) else raise "Not implemented yet" + end end def create_update_answer_link(case_log_answer, case_log_id, page)