Browse Source

Make the needs type question available in non-prod environments

Co-authored-by: Ted-U <Ted-U@users.noreply.github.com>
pull/661/head
Dushan Despotovic 3 years ago
parent
commit
8b7b4817b7
  1. 2
      app/components/primary_navigation_component.rb
  2. 6
      app/models/case_log.rb
  3. 7
      config/forms/2021_2022.json
  4. 7
      config/forms/2022_2023.json
  5. 9
      config/initializers/feature_toggle.rb
  6. 35
      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.show_schemes_button? ? @items = @items.reject { |nav_item| nav_item.text.include?("Supported housing") } : @items
super
end

6
app/models/case_log.rb

@ -112,6 +112,10 @@ class CaseLog < ApplicationRecord
status == "in_progress"
end
def needs_question_enabled?
FeatureToggle.needs_question_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 needs_question_enabled?
if rsnvac.present?
self.newprop = has_first_let_vacancy_reason? ? 1 : 2
end

7
config/forms/2021_2022.json

@ -28,8 +28,11 @@
}
}
},
"derived": true,
"depends_on": [false]
"depends_on": [
{
"needs_question_enabled?" : true
}
]
},
"renewal": {
"header": "",

7
config/forms/2022_2023.json

@ -28,8 +28,11 @@
}
}
},
"derived": true,
"depends_on": [false]
"depends_on": [
{
"needs_question_enabled?" : true
}
]
},
"renewal": {
"header": "",

9
config/initializers/feature_toggle.rb

@ -0,0 +1,9 @@
class FeatureToggle
def self.needs_question_enabled?
!Rails.env.production?
end
def self.show_schemes_button?
Rails.env.production?
end
end

35
spec/models/case_log_spec.rb

@ -210,12 +210,19 @@ RSpec.describe CaseLog do
hbrentshortfall: 1,
})
end
context "production specific code" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
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)
end
it "derives that all forms are general needs when in production" 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
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
describe "needs_question_enabled?" do
it "returns false for the case log if the environment is not production" do
case_log = FactoryBot.create(:case_log)
expect(case_log.needs_question_enabled?).to eq(false)
end
context "when in the production environment" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "returns true for a case log" do
case_log = FactoryBot.create(:case_log)
expect(case_log.needs_question_enabled?).to eq(true)
end
end
end
end

Loading…
Cancel
Save