Browse Source

Use feature flag

pull/968/head
Jack S 4 years ago
parent
commit
6702a58985
  1. 38
      app/models/form/lettings/subsections/setup.rb
  2. 6
      config/initializers/feature_toggle.rb
  3. 66
      spec/models/form/lettings/subsections/setup_spec.rb

38
app/models/form/lettings/subsections/setup.rb

@ -8,8 +8,10 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
def pages
@pages ||= [
Form::Common::Pages::Organisation.new(nil, nil, self),
Form::Common::Pages::CreatedBy.new(nil, nil, self),
organisation_page,
housing_provider_page,
managing_organisation_page,
created_by_page,
Form::Lettings::Pages::NeedsType.new(nil, nil, self),
Form::Lettings::Pages::Scheme.new(nil, nil, self),
Form::Lettings::Pages::Location.new(nil, nil, self),
@ -18,11 +20,7 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
Form::Lettings::Pages::RentType.new(nil, nil, self),
Form::Lettings::Pages::TenantCode.new(nil, nil, self),
Form::Lettings::Pages::PropertyReference.new(nil, nil, self),
]
end
def applicable_questions(lettings_log)
questions.select { |q| support_only_questions.include?(q.id) } + super
].compact
end
def enabled?(_lettings_log)
@ -31,7 +29,29 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
private
def support_only_questions
%w[owning_organisation_id created_by_id].freeze
def organisation_page
return if FeatureToggle.managing_for_other_user_enabled?
Form::Common::Pages::Organisation.new(nil, nil, self)
end
def housing_provider_page
return unless FeatureToggle.managing_for_other_user_enabled?
Form::Lettings::Pages::HousingProvider.new(nil, nil, self)
end
def managing_organisation_page
return unless FeatureToggle.managing_for_other_user_enabled?
Form::Lettings::Pages::ManagingOrganisation.new(nil, nil, self)
end
def created_by_page
if FeatureToggle.managing_for_other_user_enabled?
Form::Lettings::Pages::CreatedBy.new(nil, nil, self)
else
Form::Common::Pages::CreatedBy.new(nil, nil, self)
end
end
end

6
config/initializers/feature_toggle.rb

@ -20,4 +20,10 @@ class FeatureToggle
false
end
def self.managing_for_other_user_enabled?
return true unless Rails.env.production?
false
end
end

66
spec/models/form/lettings/subsections/setup_spec.rb

@ -13,16 +13,19 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has correct pages" do
expect(setup.pages.map(&:id)).to eq(
%w[organisation
created_by
needs_type
scheme
location
renewal
tenancy_start_date
rent_type
tenant_code
property_reference],
%w[
housing_provider
managing_organisation
created_by
needs_type
scheme
location
renewal
tenancy_start_date
rent_type
tenant_code
property_reference
],
)
end
@ -33,4 +36,47 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has the correct label" do
expect(setup.label).to eq("Set up this lettings log")
end
context "when not production" do
it "has correct pages" do
expect(setup.pages.map(&:id)).to eq(
%w[
housing_provider
managing_organisation
created_by
needs_type
scheme
location
renewal
tenancy_start_date
rent_type
tenant_code
property_reference
],
)
end
end
context "when production" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
it "has the correct pages" do
expect(setup.pages.map(&:id)).to eq(
%w[
organisation
created_by
needs_type
scheme
location
renewal
tenancy_start_date
rent_type
tenant_code
property_reference
],
)
end
end
end

Loading…
Cancel
Save