From cea703b50fc1e1896ca12fc33f21881723d3276d Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 20 Jun 2022 17:01:21 +0100 Subject: [PATCH] Default owning organisation if created from their page --- app/controllers/case_logs_controller.rb | 4 ++-- app/models/form/setup/questions/created_by_id.rb | 3 +-- .../form/setup/questions/owning_organisation_id.rb | 3 +-- app/views/organisations/logs.html.erb | 4 ++++ spec/features/organisation_spec.rb | 12 ++++++++++++ 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 6a5ea875d..f82906129 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -128,8 +128,8 @@ private return {} unless params[:case_log] permitted = params.require(:case_log).permit(CaseLog.editable_fields) - permitted["owning_organisation"] = Organisation.find_by(permitted["owning_organisation"]) - permitted["managing_organisation"] = Organisation.find_by(permitted["managing_organisation"]) + owning_id = permitted["owning_organisation_id"] + permitted["owning_organisation"] = Organisation.find(owning_id) if owning_id permitted end diff --git a/app/models/form/setup/questions/created_by_id.rb b/app/models/form/setup/questions/created_by_id.rb index af4493542..f92c688f8 100644 --- a/app/models/form/setup/questions/created_by_id.rb +++ b/app/models/form/setup/questions/created_by_id.rb @@ -7,10 +7,9 @@ class Form::Setup::Questions::CreatedById < ::Form::Question @hint_text = "" @type = "select" @page = page - @answer_options = answer_options_values end - def answer_options_values + def answer_options answer_opts = { "" => "Select an option" } return answer_opts unless ActiveRecord::Base.connected? diff --git a/app/models/form/setup/questions/owning_organisation_id.rb b/app/models/form/setup/questions/owning_organisation_id.rb index 3ce620681..857ccaf68 100644 --- a/app/models/form/setup/questions/owning_organisation_id.rb +++ b/app/models/form/setup/questions/owning_organisation_id.rb @@ -7,10 +7,9 @@ class Form::Setup::Questions::OwningOrganisationId < ::Form::Question @hint_text = "" @type = "select" @page = page - @answer_options = answer_options_values end - def answer_options_values + def answer_options answer_opts = { "" => "Select an option" } return answer_opts unless ActiveRecord::Base.connected? diff --git a/app/views/organisations/logs.html.erb b/app/views/organisations/logs.html.erb index b4625d594..07b4d4f4b 100644 --- a/app/views/organisations/logs.html.erb +++ b/app/views/organisations/logs.html.erb @@ -12,6 +12,10 @@

Logs

+
+ <%= govuk_button_to "Create a new lettings log for #{@organisation.name}", case_logs_path(case_log: { owning_organisation_id: @organisation.id }, method: :post) %> +
+ <%= render partial: "case_logs/log_filters" %>
<%= render SearchComponent.new(current_user:, search_label: "Search by log ID, tenant code, property reference or postcode", value: @searched) %> diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 99e3657c6..128d43756 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -111,6 +111,18 @@ RSpec.describe "User Features" do visit("/organisations/#{org_id}/logs") end + it "shows a create button for that organisation" do + expect(page).to have_button("Create a new lettings log for #{org_name}") + end + + context "when creating a log for that organisation" do + it "pre-fills the value for owning organisation for that log" do + click_button("Create a new lettings log for #{org_name}") + click_link("Set up this lettings log") + expect(page).to have_content(org_name) + end + end + context "when searching for specific logs" do it "displays the logs belonging to the same organisation" do expect(page).to have_content(log_to_search.id)