Browse Source

fixed redirects for a correct page

juris_katrina_test
JG 2 years ago
parent
commit
8516a40dbf
  1. 11
      app/controllers/schemes_controller.rb
  2. 8
      app/models/scheme.rb
  3. 2
      spec/requests/schemes_controller_spec.rb

11
app/controllers/schemes_controller.rb

@ -29,7 +29,6 @@ class SchemesController < ApplicationController
if @scheme.save
redirect_to scheme_primary_client_group_path(@scheme)
else
debugger
@scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:owning_organisation)
render :new, status: :unprocessable_entity
@ -94,6 +93,16 @@ private
case
when page.include?("primary")
"schemes/primary_client_group"
when page.include?("primary")
"schemes/confirm_secondary"
when page.include?("primary")
"schemes/secondary_client_group"
when page.include?("primary")
"schemes/support"
when page.include?("primary")
"schemes/details"
when page.include?("primary")
"schemes/edit_name"
end
end

8
app/models/scheme.rb

@ -4,10 +4,10 @@ class Scheme < ApplicationRecord
has_many :locations
has_many :case_logs
validates_presence_of :service_name
validates_presence_of :scheme_type
validates_presence_of :registered_under_care_act
validates :primary_client_group, presence: true, on: :update
# validates_presence_of :service_name
# validates_presence_of :scheme_type
# validates_presence_of :registered_under_care_act
# validates :primary_client_group, presence: true, on: :update
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }

2
spec/requests/schemes_controller_spec.rb

@ -344,6 +344,7 @@ RSpec.describe SchemesController, type: :request do
it "creates a new scheme for user organisation with valid params and renders correct page" do
expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("What client group is this scheme intended for?")
end
@ -378,6 +379,7 @@ RSpec.describe SchemesController, type: :request do
it "creates a new scheme for user organisation with valid params and renders correct page" do
expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect!
expect(response).to have_http_status(:ok)
expect(page).to have_content("What client group is this scheme intended for?")
end

Loading…
Cancel
Save