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. 25
      spec/models/case_log_spec.rb

2
app/components/primary_navigation_component.rb

@ -3,7 +3,7 @@ class PrimaryNavigationComponent < ViewComponent::Base
def initialize(items:) def initialize(items:)
@items = 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 super
end end

6
app/models/case_log.rb

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

9
config/forms/2021_2022.json

@ -16,7 +16,7 @@
"needstype": { "needstype": {
"check_answer_label": "Needs type", "check_answer_label": "Needs type",
"header": "What is the 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", "type": "radio",
"answer_options": { "answer_options": {
"1": { "1": {
@ -28,8 +28,11 @@
} }
} }
}, },
"derived": true, "depends_on": [
"depends_on": [false] {
"supported_housing_schemes_enabled?" : true
}
]
}, },
"renewal": { "renewal": {
"header": "", "header": "",

9
config/forms/2022_2023.json

@ -16,7 +16,7 @@
"needstype": { "needstype": {
"check_answer_label": "Needs type", "check_answer_label": "Needs type",
"header": "What is the 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", "type": "radio",
"answer_options": { "answer_options": {
"1": { "1": {
@ -28,8 +28,11 @@
} }
} }
}, },
"derived": true, "depends_on": [
"depends_on": [false] {
"supported_housing_schemes_enabled?" : true
}
]
}, },
"renewal": { "renewal": {
"header": "", "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

25
spec/models/case_log_spec.rb

@ -211,11 +211,18 @@ RSpec.describe CaseLog do
}) })
end end
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 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] 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(record_from_db["needstype"]).to eq(1)
expect(case_log["needstype"]).to eq(1) expect(case_log["needstype"]).to eq(1)
end end
end
it "correctly derives and saves partial and full major repairs date" do it "correctly derives and saves partial and full major repairs date" do
record_from_db = ActiveRecord::Base.connection.execute("select mrcdate from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select mrcdate from case_logs where id=#{case_log.id}").to_a[0]
@ -2097,4 +2104,22 @@ RSpec.describe CaseLog do
end end
end 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 end

Loading…
Cancel
Save