From 301fb1e0f2818b720a88c7f80aec3b02bdd39aa5 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Tue, 21 Jun 2022 09:57:24 +0100 Subject: [PATCH] Default owning organisation if created from their page (#680) * Default owning organisation if created from their page * Button text --- 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 | 14 +++++++++++++- 5 files changed, 21 insertions(+), 7 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..9d8e978dc 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 this organisation", 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 a97be7f06..8d9bee660 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 this organisation") + 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 this organisation") + 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) @@ -189,7 +201,7 @@ RSpec.describe "User Features" do end end - it "shows submenu for selected orgnisation" do + it "shows submenu for selected organisation" do expect(page).to have_css('[aria-current="page"]', text: "Users") expect(page).to have_current_path("/organisations/#{org_id}/users") expect(page).to have_link("Logs")