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 def pages
@pages ||= [ @pages ||= [
Form::Common::Pages::Organisation.new(nil, nil, self), organisation_page,
Form::Common::Pages::CreatedBy.new(nil, nil, self), housing_provider_page,
managing_organisation_page,
created_by_page,
Form::Lettings::Pages::NeedsType.new(nil, nil, self), Form::Lettings::Pages::NeedsType.new(nil, nil, self),
Form::Lettings::Pages::Scheme.new(nil, nil, self), Form::Lettings::Pages::Scheme.new(nil, nil, self),
Form::Lettings::Pages::Location.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::RentType.new(nil, nil, self),
Form::Lettings::Pages::TenantCode.new(nil, nil, self), Form::Lettings::Pages::TenantCode.new(nil, nil, self),
Form::Lettings::Pages::PropertyReference.new(nil, nil, self), Form::Lettings::Pages::PropertyReference.new(nil, nil, self),
] ].compact
end
def applicable_questions(lettings_log)
questions.select { |q| support_only_questions.include?(q.id) } + super
end end
def enabled?(_lettings_log) def enabled?(_lettings_log)
@ -31,7 +29,29 @@ class Form::Lettings::Subsections::Setup < ::Form::Subsection
private private
def support_only_questions def organisation_page
%w[owning_organisation_id created_by_id].freeze 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
end end

6
config/initializers/feature_toggle.rb

@ -20,4 +20,10 @@ class FeatureToggle
false false
end end
def self.managing_for_other_user_enabled?
return true unless Rails.env.production?
false
end
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 it "has correct pages" do
expect(setup.pages.map(&:id)).to eq( expect(setup.pages.map(&:id)).to eq(
%w[organisation %w[
created_by housing_provider
needs_type managing_organisation
scheme created_by
location needs_type
renewal scheme
tenancy_start_date location
rent_type renewal
tenant_code tenancy_start_date
property_reference], rent_type
tenant_code
property_reference
],
) )
end end
@ -33,4 +36,47 @@ RSpec.describe Form::Lettings::Subsections::Setup, type: :model do
it "has the correct label" do it "has the correct label" do
expect(setup.label).to eq("Set up this lettings log") expect(setup.label).to eq("Set up this lettings log")
end 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 end

Loading…
Cancel
Save