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 end
def primary_client_group def primary_client_group
case if request.referer&.include?("new") || request.referer&.include?("details")
when request.referrer.include?("new") || request.referrer.include?("details")
@back_button_path = scheme_details_path(@scheme) @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) @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) @back_button_path = scheme_check_asnwers_path(@scheme)
end end
render "schemes/primary_client_group" render "schemes/primary_client_group"
@ -106,8 +105,8 @@ class SchemesController < ApplicationController
private private
def validation_errors scheme_params def validation_errors(scheme_params)
scheme_params.keys.each do |key| scheme_params.each_key do |key|
@scheme.errors.add(key.to_sym) if scheme_params[key].to_s.empty? @scheme.errors.add(key.to_sym) if scheme_params[key].to_s.empty?
end end
end end
@ -117,18 +116,17 @@ private
end end
def current_template(page) def current_template(page)
case if page.include?("primary")
when page.include?("primary")
"schemes/primary_client_group" "schemes/primary_client_group"
when page.include?("confirm") elsif page.include?("confirm")
"schemes/confirm_secondary" "schemes/confirm_secondary"
when page.include?("secondary-client") elsif page.include?("secondary-client")
"schemes/secondary_client_group" "schemes/secondary_client_group"
when page.include?("support") elsif page.include?("support")
"schemes/support" "schemes/support"
when page.include?("details") elsif page.include?("details")
"schemes/details" "schemes/details"
when page.include?("edit") elsif page.include?("edit")
"schemes/edit_name" "schemes/edit_name"
end end
end end
@ -146,7 +144,7 @@ private
when "support" when "support"
new_location_path new_location_path
when "details" 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) scheme_primary_client_group_path(@scheme)
else else
scheme_support_services_provider_path(@scheme) 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" 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] full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
if current_user.data_coordinator? if current_user.data_coordinator?

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

@ -28,10 +28,6 @@
label: { text: "This scheme contains confidential information" } %> label: { text: "This scheme contains confidential information" } %>
<% end %> <% 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? %> <% if current_user.data_coordinator? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% end %> <% end %>
@ -52,6 +48,8 @@
:name, :name,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> 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? %> <% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
organisations, 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 context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } 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 before do
sign_in user sign_in user
@ -370,7 +376,14 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, :support) } 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 before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -582,7 +595,15 @@ RSpec.describe SchemesController, type: :request do
end end
context "when updating details" do 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 it "renders confirm secondary group after successful update" do
follow_redirect! follow_redirect!
@ -789,8 +810,8 @@ RSpec.describe SchemesController, type: :request do
scheme_type: "Foyer", scheme_type: "Foyer",
registered_under_care_act: "No", registered_under_care_act: "No",
page: "details", page: "details",
owning_organisation_id: another_organisation.id, support_services_provider: "The same organisation that owns the housing stock",
managing_organisation_id: another_organisation.id } } owning_organisation_id: another_organisation.id } }
end end
it "renders confirm secondary group after successful update" do it "renders confirm secondary group after successful update" do

Loading…
Cancel
Save