Browse Source

fet: simplify controller args

pull/954/head
natdeanlewissoftwire 3 years ago
parent
commit
63193a150d
  1. 9
      app/controllers/organisation_relationships_controller.rb
  2. 1
      spec/requests/organisations_controller_spec.rb

9
app/controllers/organisation_relationships_controller.rb

@ -45,26 +45,27 @@ class OrganisationRelationshipsController < ApplicationController
def create_housing_provider def create_housing_provider
child_organisation_id = @organisation.id child_organisation_id = @organisation.id
parent_organisation_id = related_organisation_id parent_organisation_id = related_organisation_id
relationship_type = OrganisationRelationship::OWNING
if related_organisation_id.empty? if related_organisation_id.empty?
@organisation.errors.add :related_organisation_id, "You must choose a housing provider" @organisation.errors.add :related_organisation_id, "You must choose a housing provider"
@organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name) @organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name)
render 'organisation_relationships/add_housing_provider' render 'organisation_relationships/add_housing_provider'
return return
elsif OrganisationRelationship.exists?(child_organisation_id:, parent_organisation_id:, relationship_type: 0) elsif OrganisationRelationship.exists?(child_organisation_id:, parent_organisation_id:, relationship_type:)
@organisation.errors.add :related_organisation_id, "You have already added this housing provider" @organisation.errors.add :related_organisation_id, "You have already added this housing provider"
@organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name) @organisations = Organisation.where.not(id: child_organisation_id).pluck(:id, :name)
render 'organisation_relationships/add_housing_provider' render 'organisation_relationships/add_housing_provider'
return return
end end
create(child_organisation_id, parent_organisation_id, 0) create(child_organisation_id:, parent_organisation_id:, relationship_type:)
redirect_to housing_providers_organisation_path(related_organisation_id:) redirect_to housing_providers_organisation_path(related_organisation_id:)
end end
def create_managing_agent def create_managing_agent
create(related_organisation_id, @organisation.id, 1) create(child_organisation_id: related_organisation_id, parent_organisation_id: @organisation.id, relationship_type: 1)
end end
def create(child_organisation_id, parent_organisation_id, relationship_type) def create(child_organisation_id:, parent_organisation_id:, relationship_type:)
@resource = OrganisationRelationship.new(child_organisation_id:, parent_organisation_id:, relationship_type:) @resource = OrganisationRelationship.new(child_organisation_id:, parent_organisation_id:, relationship_type:)
@resource.save! @resource.save!
end end

1
spec/requests/organisations_controller_spec.rb

@ -335,7 +335,6 @@ RSpec.describe OrganisationsController, type: :request do
end end
end end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
before do before do
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {} get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {}

Loading…
Cancel
Save