Browse Source

Merge branch 'main' into CLDC-2954-handle-schemes-with-only-deactivated-locations

pull/2510/head
Manny Dinssa 2 years ago committed by GitHub
parent
commit
3d9799d497
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/helpers/filters_helper.rb
  2. 2
      app/helpers/question_view_helper.rb
  3. 7
      app/models/derived_variables/lettings_log_variables.rb
  4. 2
      app/models/form.rb
  5. 8
      app/models/lettings_log.rb
  6. 3
      app/models/user.rb
  7. 2
      app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb
  8. 4
      app/views/layouts/_collection_resources.html.erb
  9. 2
      package.json
  10. 30
      spec/features/form/accessible_autocomplete_spec.rb
  11. 2
      spec/features/organisation_spec.rb
  12. 32
      spec/helpers/filters_helper_spec.rb
  13. 4
      spec/helpers/question_view_helper_spec.rb
  14. 21
      spec/models/organisation_spec.rb
  15. 2
      spec/models/sales_log_spec.rb
  16. 8
      yarn.lock

9
app/helpers/filters_helper.rb

@ -95,11 +95,16 @@ module FiltersHelper
end
def collection_year_options
{
years = {
current_collection_start_year.to_s => year_combo(current_collection_start_year),
previous_collection_start_year.to_s => year_combo(previous_collection_start_year),
archived_collection_start_year.to_s => year_combo(archived_collection_start_year),
}
if FormHandler.instance.in_crossover_period?
return years.merge({ archived_collection_start_year.to_s => year_combo(archived_collection_start_year) })
end
years
end
def collection_year_radio_options

2
app/helpers/question_view_helper.rb

@ -35,7 +35,7 @@ module QuestionViewHelper
return unless resource.instance_of?(Scheme) || resource.instance_of?(Location)
if resource.instance_of?(Scheme)
[resource.primary_client_group, resource.secondary_client_group].compact.join(", ")
"(S#{resource.id}) " + [resource.primary_client_group, resource.secondary_client_group].compact.join(", ")
elsif resource.instance_of?(Location)
resource.name
end

7
app/models/derived_variables/lettings_log_variables.rb

@ -28,13 +28,6 @@ module DerivedVariables::LettingsLogVariables
5 => 6,
}.freeze
def scheme_has_multiple_locations?
return false unless scheme
scheme_locations_count = scheme.locations.active_in_2_weeks.size
scheme_locations_count > 1
end
def set_derived_fields!
clear_inapplicable_derived_values!
set_encoded_derived_values!(DEPENDENCIES)

2
app/models/form.rb

@ -11,6 +11,8 @@ class Form
},
2023 => {
submission_deadline: Time.zone.local(2024, 6, 7),
new_logs_end_date: Time.zone.local(2024, 7, 22),
edit_end_date: Time.zone.local(2024, 7, 22),
},
2024 => {
submission_deadline: Time.zone.local(2025, 6, 6),

8
app/models/lettings_log.rb

@ -709,15 +709,15 @@ class LettingsLog < Log
def scheme_has_multiple_locations?
return false unless scheme
@scheme_locations_count ||= scheme.locations.active_in_2_weeks.size
@scheme_locations_count > 1
scheme_locations_count ||= scheme.locations.active_in_2_weeks.size
scheme_locations_count > 1
end
def scheme_has_large_number_of_locations?
return false unless scheme
@scheme_locations_count ||= scheme.locations.active_in_2_weeks.size
@scheme_locations_count > 19
scheme_locations_count ||= scheme.locations.active_in_2_weeks.size
scheme_locations_count > 19
end
private

3
app/models/user.rb

@ -264,7 +264,8 @@ class User < ApplicationRecord
end
def discard!
update!(discarded_at: Time.zone.now)
self.discarded_at = Time.zone.now
save!(validate: false)
end
protected

2
app/views/bulk_upload_lettings_logs/forms/prepare_your_file_2024.html.erb

@ -26,7 +26,7 @@
<li>If you have reordered the headers, keep the headers in the file.</li>
</ul>
<%= govuk_inset_text(text: "You can upload both general needs and supported housing logs in the same file for 2023/24 data.") %>
<%= govuk_inset_text(text: "You can upload both general needs and supported housing logs in the same file for 2024/25 data.") %>
<h2 class="govuk-heading-s">Save your file</h2>

4
app/views/layouts/_collection_resources.html.erb

@ -6,7 +6,9 @@
<h2 class="govuk-heading-m">Collection resources</h2>
<% end %>
<p class="govuk-body">Use the 2024 to 2025 forms for lettings that start and sales that complete between 1 April 2024 and 31 March 2025.</p>
<p class="govuk-body">Use the 2023 to 2024 forms for lettings that start and sales that complete between 1 April 2023 and 31 March 2024.</p>
<% if FormHandler.instance.lettings_form_for_start_year(2023) && FormHandler.instance.lettings_form_for_start_year(2023).edit_end_date > Time.zone.today %>
<p class="govuk-body">Use the 2023 to 2024 forms for lettings that start and sales that complete between 1 April 2023 and 31 March 2024.</p>
<% end %>
<div class="app-tab__list-view">
<%= govuk_tabs(title: "Collection resources", classes: %w[app-tab__small-headers]) do |c| %>
<% if FormHandler.instance.lettings_form_for_start_year(2024) && FormHandler.instance.lettings_form_for_start_year(2024).edit_end_date > Time.zone.today %>

2
package.json

@ -24,7 +24,7 @@
"html5shiv": "^3.7.3",
"intersection-observer": "^0.12.0",
"mini-css-extract-plugin": "^2.6.0",
"rails_admin": "3.1.2",
"rails_admin": "3.1.3",
"regenerator-runtime": "^0.13.9",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",

30
spec/features/form/accessible_autocomplete_spec.rb

@ -55,6 +55,36 @@ RSpec.describe "Accessible Autocomplete" do
it "displays the placeholder text", js: true do
expect(find("#lettings-log-prevloc-field")["placeholder"]).to eq("Start typing to search")
end
context "and multiple schemes with same names", js: true do
let(:lettings_log) { FactoryBot.create(:lettings_log, :sh, assigned_to: user) }
let!(:schemes) { FactoryBot.create_list(:scheme, 2, owning_organisation_id: user.organisation_id, service_name: "Scheme", primary_client_group: "O", secondary_client_group: "O") }
before do
schemes.each do |scheme|
FactoryBot.create(:location, scheme:)
end
visit("/lettings-logs/#{lettings_log.id}/scheme")
end
it "allows selecting any scheme" do
find("#lettings-log-scheme-id-field").click.native.send_keys("s", "c", "h", :enter)
expect(find("#lettings-log-scheme-id-field").value).to match(/Scheme/)
click_button("Save and continue")
first_selected_scheme_id = lettings_log.reload.scheme_id
expect(schemes.map(&:id)).to include(first_selected_scheme_id)
visit("/lettings-logs/#{lettings_log.id}/scheme")
find("#lettings-log-scheme-id-field").click.native.send_keys("s", "c", "h", :down, :enter)
expect(find("#lettings-log-scheme-id-field").value).to match(/Scheme/)
click_button("Save and continue")
second_selected_scheme_id = lettings_log.reload.scheme_id
expect(schemes.map(&:id)).to include(lettings_log.reload.scheme_id)
expect(first_selected_scheme_id).not_to eq(second_selected_scheme_id)
end
end
end
context "when searching schemes" do

2
spec/features/organisation_spec.rb

@ -131,6 +131,7 @@ RSpec.describe "User Features" do
let(:number_of_lettings_logs) { LettingsLog.count }
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
visit("/organisations/#{org_id}/lettings-logs")
end
@ -220,6 +221,7 @@ RSpec.describe "User Features" do
let(:number_of_sales_logs) { SalesLog.count }
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id)
visit("/organisations/#{org_id}/sales-logs")
end

32
spec/helpers/filters_helper_spec.rb

@ -245,12 +245,32 @@ RSpec.describe FiltersHelper do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1))
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023/24", "2022" => "2022/23", "2021" => "2021/22"
},
)
context "and in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023/24", "2022" => "2022/23", "2021" => "2021/22"
},
)
end
end
context "and not in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023/24", "2022" => "2022/23"
},
)
end
end
end

4
spec/helpers/question_view_helper_spec.rb

@ -151,10 +151,10 @@ RSpec.describe QuestionViewHelper do
end
context "when resource is a scheme" do
let(:resource) { build(:scheme, primary_client_group: "O", secondary_client_group: "E") }
let(:resource) { build(:scheme, primary_client_group: "O", secondary_client_group: "E", id: 2_736_276) }
it "returns the primary and secondary client groups" do
expect(answer_option_hint(resource)).to eq("Homeless families with support needs, People with mental health problems")
expect(answer_option_hint(resource)).to eq("(S2736276) Homeless families with support needs, People with mental health problems")
end
end

21
spec/models/organisation_spec.rb

@ -298,4 +298,25 @@ RSpec.describe Organisation, type: :model do
expect(organisation.status).to be(:active)
end
end
describe "discard" do
let(:organisation) { create(:organisation) }
let!(:user) { create(:user, organisation:) }
let!(:scheme) { create(:scheme, owning_organisation: organisation) }
context "when merged organisation is discarded" do
before do
organisation.merge_date = Time.zone.yesterday
organisation.absorbing_organisation_id = create(:organisation).id
organisation.save!
end
it "discards all of the organisation resources" do
organisation.discard!
expect(organisation.status).to eq(:deleted)
expect(user.reload.status).to eq(:deleted)
expect(scheme.reload.status).to eq(:deleted)
end
end
end
end

2
spec/models/sales_log_spec.rb

@ -173,7 +173,7 @@ RSpec.describe SalesLog, type: :model do
end
describe "#search_by" do
let!(:sales_log_to_search) { create(:sales_log, :completed) }
let!(:sales_log_to_search) { create(:sales_log, :completed, id: 193_285) }
it "allows searching using ID" do
result = described_class.search_by(sales_log_to_search.id.to_s)

8
yarn.lock

@ -4703,10 +4703,10 @@ quick-lru@^5.1.1:
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932"
integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==
rails_admin@3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/rails_admin/-/rails_admin-3.1.2.tgz#00d6d85b7a00c89c69b5dbf5f1f4620702626504"
integrity sha512-uIQHN27lBvlav6s5ppmOtVxKN8GIxyhHuDFc9ZbvWgFknR4zgG4/xEUGzKzQ9R34AEsfZ/t8cZbvtvgj+aXp4A==
rails_admin@3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/rails_admin/-/rails_admin-3.1.3.tgz#1da3f2214876f4ffd3a1db01452c28a8f7d4d989"
integrity sha512-79CBB2BMB3fSGPz1P8eNxCboHVlkBWBaxKxfo4QwCAFxsA3WAjfM0MeWUtGHI8Mn8XEZxCdEDz9oYlvlBpMtng==
dependencies:
"@babel/runtime" "^7.16.7"
"@fortawesome/fontawesome-free" ">=5.15.0 <7.0.0"

Loading…
Cancel
Save