Browse Source

CLDC-1248-select-needs-type (#661)

* Make the needs type question available in non-prod environments

Co-authored-by: Ted-U <Ted-U@users.noreply.github.com>

* lint fixes

* fixes based on review

* add hint text

Co-authored-by: Ted-U <Ted-U@users.noreply.github.com>
pull/666/head
Dushan 3 years ago committed by GitHub
parent
commit
4ddf18c3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/primary_navigation_component.rb
  2. 6
      app/models/case_log.rb
  3. 9
      config/forms/2021_2022.json
  4. 9
      config/forms/2022_2023.json
  5. 7
      config/initializers/feature_toggle.rb
  6. 33
      spec/models/case_log_spec.rb

2
app/components/primary_navigation_component.rb

@ -3,7 +3,7 @@ class PrimaryNavigationComponent < ViewComponent::Base
def initialize(items:)
@items = items
Rails.env.production? ? @items = @items.reject { |nav_item| nav_item.text.include?("Supported housing") } : @items
FeatureToggle.supported_housing_schemes_enabled? ? @items : @items.reject! { |nav_item| nav_item.text.include?("Supported housing") }
super
end

6
app/models/case_log.rb

@ -112,6 +112,10 @@ class CaseLog < ApplicationRecord
status == "in_progress"
end
def supported_housing_schemes_enabled?
FeatureToggle.supported_housing_schemes_enabled?
end
def weekly_net_income
return unless earnings && incfreq
@ -520,7 +524,7 @@ private
def set_derived_fields!
# TODO: Remove once we support supported housing logs
self.needstype = 1 unless needstype
self.needstype = 1 unless FeatureToggle.supported_housing_schemes_enabled?
if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end

9
config/forms/2021_2022.json

@ -16,7 +16,7 @@
"needstype": {
"check_answer_label": "Needs type",
"header": "What is the needs type?",
"hint_text": "",
"hint_text": "General needs housing includes both self-contained and shared housing without support or specific adaptations. Supported housing can include direct access hostels, group homes, residential care and nursing homes.",
"type": "radio",
"answer_options": {
"1": {
@ -28,8 +28,11 @@
}
}
},
"derived": true,
"depends_on": [false]
"depends_on": [
{
"supported_housing_schemes_enabled?" : true
}
]
},
"renewal": {
"header": "",

9
config/forms/2022_2023.json

@ -16,7 +16,7 @@
"needstype": {
"check_answer_label": "Needs type",
"header": "What is the needs type?",
"hint_text": "",
"hint_text": "General needs housing includes both self-contained and shared housing without support or specific adaptations. Supported housing can include direct access hostels, group homes, residential care and nursing homes.",
"type": "radio",
"answer_options": {
"1": {
@ -28,8 +28,11 @@
}
}
},
"derived": true,
"depends_on": [false]
"depends_on": [
{
"supported_housing_schemes_enabled?" : true
}
]
},
"renewal": {
"header": "",

7
config/initializers/feature_toggle.rb

@ -0,0 +1,7 @@
class FeatureToggle
def self.supported_housing_schemes_enabled?
return true unless Rails.env.production?
false
end
end

33
spec/models/case_log_spec.rb

@ -211,10 +211,17 @@ RSpec.describe CaseLog do
})
end
it "derives that all forms are general needs" do
record_from_db = ActiveRecord::Base.connection.execute("select needstype from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["needstype"]).to eq(1)
expect(case_log["needstype"]).to eq(1)
context "when a case log is created in production" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "derives that all forms are general needs" do
case_log = FactoryBot.create(:case_log)
record_from_db = ActiveRecord::Base.connection.execute("select needstype from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["needstype"]).to eq(1)
expect(case_log["needstype"]).to eq(1)
end
end
it "correctly derives and saves partial and full major repairs date" do
@ -2097,4 +2104,22 @@ RSpec.describe CaseLog do
end
end
end
describe "supported_housing_schemes_enabled?" do
it "returns true for the case log if the environment is not production" do
case_log = FactoryBot.create(:case_log)
expect(case_log.supported_housing_schemes_enabled?).to eq(true)
end
context "when in the production environment" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "returns false for a case log" do
case_log = FactoryBot.create(:case_log)
expect(case_log.supported_housing_schemes_enabled?).to eq(false)
end
end
end
end

Loading…
Cancel
Save