Browse Source

fixed tests

pull/730/head
JG 3 years ago
parent
commit
ebb045eaf6
  1. 12
      app/controllers/schemes_controller.rb
  2. 4
      app/views/schemes/details.html.erb
  3. 4
      app/views/schemes/new.html.erb
  4. 10
      spec/requests/schemes_controller_spec.rb

12
app/controllers/schemes_controller.rb

@ -96,7 +96,7 @@ class SchemesController < ApplicationController
render "schemes/support_services_provider"
end
private
private
def validation_errors(scheme_params)
scheme_params.each_key do |key|
@ -139,10 +139,12 @@ class SchemesController < ApplicationController
when "support"
new_location_path
when "details"
if @scheme.support_services_provider_before_type_cast.zero?
if @scheme.support_services_provider_before_type_cast&.zero?
scheme_primary_client_group_path(@scheme)
else
elsif @scheme.support_services_provider_before_type_cast.positive?
scheme_support_services_provider_path(@scheme)
else
scheme_details_path(@scheme)
end
when "edit-name"
scheme_path(@scheme)
@ -165,10 +167,10 @@ class SchemesController < ApplicationController
:support_services_provider_before_type_cast,
:intended_stay).merge(support_services_provider: params[:scheme][:support_services_provider_before_type_cast])
full_params = required_params[:support_services_provider] == "0" && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params = Scheme.support_services_providers.key?(required_params[:support_services_provider]) && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
full_params[:support_services_provider] = full_params[:support_services_provider].to_i if !full_params[:support_services_provider]&.empty?
full_params[:support_services_provider] = full_params[:support_services_provider].to_i unless full_params[:support_services_provider] && full_params[:support_services_provider].empty?
if current_user.data_coordinator?
full_params[:owning_organisation_id] = current_user.organisation_id

4
app/views/schemes/details.html.erb

@ -69,13 +69,13 @@
<%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast,
support_services_provider_selection,
:id,
->(option) do
lambda { |option|
if option.id.zero? && !current_user.support?
"Your organisation"
else
option.name
end
end,
},
legend: { text: "Who provides the support services used by this scheme?", size: "m" } %>
<%= f.hidden_field :page, value: "details" %>

4
app/views/schemes/new.html.erb

@ -72,13 +72,13 @@
<%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast,
support_services_provider_selection,
:id,
->(option) do
lambda { |option|
if option.id.zero? && !current_user.support?
"Your organisation"
else
option.name
end
end,
},
legend: { text: "Who provides the support services used by this scheme?", size: "m" } %>
<%= f.govuk_submit "Save and continue" %>

10
spec/requests/schemes_controller_spec.rb

@ -576,7 +576,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
support_services_provider_before_type_cast: "",
has_other_client_group: "",
page: "details",
} }
@ -593,7 +593,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider_before_type_cast.invalid"))
end
context "when updating from check answers page" do
@ -862,7 +862,7 @@ RSpec.describe SchemesController, type: :request do
registered_under_care_act: "",
support_type: "",
intended_stay: "",
support_services_provider: "",
support_services_provider_before_type_cast: "",
has_other_client_group: "",
page: "details",
} }
@ -880,7 +880,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_type.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.intended_stay.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.has_other_client_group.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider.invalid"))
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.support_services_provider_before_type_cast.invalid"))
end
context "when updating from check answers page" do
@ -1044,7 +1044,7 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer",
registered_under_care_act: "No",
page: "details",
support_services_provider: "The same organisation that owns the housing stock",
support_services_provider_before_type_cast: "The same organisation that owns the housing stock",
owning_organisation_id: another_organisation.id } }
end

Loading…
Cancel
Save