Browse Source

passing tests and working functionality

juris_katrina_test
JG 2 years ago
parent
commit
2e9ca55dec
  1. 28
      app/controllers/schemes_controller.rb
  2. 6
      app/views/schemes/details.html.erb
  3. 31
      spec/requests/schemes_controller_spec.rb

28
app/controllers/schemes_controller.rb

@ -65,12 +65,11 @@ class SchemesController < ApplicationController
end
def primary_client_group
case
when request.referrer.include?("new") || request.referrer.include?("details")
if request.referer&.include?("new") || request.referer&.include?("details")
@back_button_path = scheme_details_path(@scheme)
when request.referrer.include?("provider")
elsif request.referer&.include?("provider")
@back_button_path = scheme_support_services_provider_path(@scheme)
when request.query_parameters["check_answers"]
elsif request.query_parameters["check_answers"]
@back_button_path = scheme_check_asnwers_path(@scheme)
end
render "schemes/primary_client_group"
@ -106,8 +105,8 @@ class SchemesController < ApplicationController
private
def validation_errors scheme_params
scheme_params.keys.each do |key|
def validation_errors(scheme_params)
scheme_params.each_key do |key|
@scheme.errors.add(key.to_sym) if scheme_params[key].to_s.empty?
end
end
@ -117,18 +116,17 @@ private
end
def current_template(page)
case
when page.include?("primary")
if page.include?("primary")
"schemes/primary_client_group"
when page.include?("confirm")
elsif page.include?("confirm")
"schemes/confirm_secondary"
when page.include?("secondary-client")
elsif page.include?("secondary-client")
"schemes/secondary_client_group"
when page.include?("support")
elsif page.include?("support")
"schemes/support"
when page.include?("details")
elsif page.include?("details")
"schemes/details"
when page.include?("edit")
elsif page.include?("edit")
"schemes/edit_name"
end
end
@ -146,7 +144,7 @@ private
when "support"
new_location_path
when "details"
if @scheme.support_services_provider.eql?"The same organisation that owns the housing stock"
if @scheme.support_services_provider.eql? "The same organisation that owns the housing stock"
scheme_primary_client_group_path(@scheme)
else
scheme_support_services_provider_path(@scheme)
@ -173,7 +171,7 @@ private
same_org_providing_support = required_params[:support_services_provider] == "The same organisation that owns the housing stock"
full_params = same_org_providing_support ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params = same_org_providing_support && 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]
if current_user.data_coordinator?

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

@ -28,10 +28,6 @@
label: { text: "This scheme contains confidential information" } %>
<% end %>
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.data_coordinator? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% end %>
@ -52,6 +48,8 @@
:name,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id,
organisations,

31
spec/requests/schemes_controller_spec.rb

@ -336,7 +336,13 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No" } } }
let(:params) do
{ scheme: { service_name: "testy",
sensitive: "1",
scheme_type: "Foyer",
registered_under_care_act: "No",
support_services_provider: "The same organisation that owns the housing stock" } }
end
before do
sign_in user
@ -370,7 +376,14 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do
let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, :support) }
let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", owning_organisation_id: organisation.id } } }
let(:params) do
{ scheme: { service_name: "testy",
sensitive: "1",
scheme_type: "Foyer",
registered_under_care_act: "No",
owning_organisation_id: organisation.id,
support_services_provider: "The same organisation that owns the housing stock" } }
end
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -582,7 +595,15 @@ RSpec.describe SchemesController, type: :request do
end
context "when updating details" do
let(:params) { { scheme: { service_name: "testy", sensitive: "1", scheme_type: "Foyer", registered_under_care_act: "No", page: "details" } } }
let(:params) do
{ scheme: { service_name: "testy",
sensitive: "1",
scheme_type: "Foyer",
registered_under_care_act: "No",
page: "details",
owning_organisation_id: organisation.id,
support_services_provider: "The same organisation that owns the housing stock" } }
end
it "renders confirm secondary group after successful update" do
follow_redirect!
@ -789,8 +810,8 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer",
registered_under_care_act: "No",
page: "details",
owning_organisation_id: another_organisation.id,
managing_organisation_id: another_organisation.id } }
support_services_provider: "The same organisation that owns the housing stock",
owning_organisation_id: another_organisation.id } }
end
it "renders confirm secondary group after successful update" do

Loading…
Cancel
Save