Browse Source

Default owning organisation if created from their page (#680)

* Default owning organisation if created from their page

* Button text
pull/687/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
301fb1e0f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/controllers/case_logs_controller.rb
  2. 3
      app/models/form/setup/questions/created_by_id.rb
  3. 3
      app/models/form/setup/questions/owning_organisation_id.rb
  4. 4
      app/views/organisations/logs.html.erb
  5. 14
      spec/features/organisation_spec.rb

4
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

3
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?

3
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?

4
app/views/organisations/logs.html.erb

@ -12,6 +12,10 @@
<h2 class="govuk-visually-hidden">Logs</h2>
<div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle">
<%= govuk_button_to "Create a new lettings log for this organisation", case_logs_path(case_log: { owning_organisation_id: @organisation.id }, method: :post) %>
</div>
<%= render partial: "case_logs/log_filters" %>
<div class="app-filter-layout__content">
<%= render SearchComponent.new(current_user:, search_label: "Search by log ID, tenant code, property reference or postcode", value: @searched) %>

14
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")

Loading…
Cancel
Save