Browse Source

CLDC-2460 Update edit end date functionality (#1721)

* Redirect lettings log to review page if the collection year is closed for editing

* Redirect sales log to review page if the collection year is closed for editing

* Update location default deactivation date

* Update location default deactivation date

* Do not display resources for a closed collection year

* lint

* Extract a method

* tests

* Update breadcrumbs for closed period
pull/1749/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
14a163d979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/lettings_logs_controller.rb
  2. 2
      app/controllers/locations_controller.rb
  3. 6
      app/controllers/sales_logs_controller.rb
  4. 2
      app/controllers/schemes_controller.rb
  5. 28
      app/helpers/review_helper.rb
  6. 16
      app/models/form_handler.rb
  7. 4
      app/models/location_deactivation_period.rb
  8. 4
      app/models/log.rb
  9. 4
      app/models/scheme_deactivation_period.rb
  10. 8
      app/views/form/review.html.erb
  11. 168
      app/views/layouts/_collection_resources.html.erb
  12. 2
      app/views/locations/toggle_active.html.erb
  13. 2
      app/views/schemes/toggle_active.html.erb
  14. 70
      spec/requests/lettings_logs_controller_spec.rb
  15. 2
      spec/requests/locations_controller_spec.rb
  16. 39
      spec/requests/organisations_controller_spec.rb
  17. 78
      spec/requests/sales_logs_controller_spec.rb

2
app/controllers/lettings_logs_controller.rb

@ -63,6 +63,8 @@ class LettingsLogsController < LogsController
if @log.unresolved if @log.unresolved
redirect_to(send(@log.form.unresolved_log_path, @log)) redirect_to(send(@log.form.unresolved_log_path, @log))
elsif @log.collection_closed_for_editing?
redirect_to review_lettings_log_path(@log)
else else
render("logs/edit", locals: { current_user: }) render("logs/edit", locals: { current_user: })
end end

2
app/controllers/locations_controller.rb

@ -280,7 +280,7 @@ private
if params[:location_deactivation_period].blank? if params[:location_deactivation_period].blank?
return return
elsif params[:location_deactivation_period]["#{key}_type".to_sym] == "default" elsif params[:location_deactivation_period]["#{key}_type".to_sym] == "default"
return FormHandler.instance.start_date_of_earliest_open_collection_period return FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif params[:location_deactivation_period][key.to_sym].present? elsif params[:location_deactivation_period][key.to_sym].present?
return params[:location_deactivation_period][key.to_sym] return params[:location_deactivation_period][key.to_sym]
end end

6
app/controllers/sales_logs_controller.rb

@ -37,7 +37,11 @@ class SalesLogsController < LogsController
def edit def edit
@log = current_user.sales_logs.visible.find(params[:id]) @log = current_user.sales_logs.visible.find(params[:id])
render "logs/edit", locals: { current_user: } if @log.collection_closed_for_editing?
redirect_to review_sales_log_path(@log, sales_log: true)
else
render "logs/edit", locals: { current_user: }
end
end end
def destroy def destroy

2
app/controllers/schemes_controller.rb

@ -318,7 +318,7 @@ private
if params[:scheme_deactivation_period].blank? if params[:scheme_deactivation_period].blank?
return return
elsif params[:scheme_deactivation_period]["#{key}_type".to_sym] == "default" elsif params[:scheme_deactivation_period]["#{key}_type".to_sym] == "default"
return FormHandler.instance.start_date_of_earliest_open_collection_period return FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif params[:scheme_deactivation_period][key.to_sym].present? elsif params[:scheme_deactivation_period][key.to_sym].present?
return params[:scheme_deactivation_period][key.to_sym] return params[:scheme_deactivation_period][key.to_sym]
end end

28
app/helpers/review_helper.rb

@ -0,0 +1,28 @@
module ReviewHelper
include CollectionTimeHelper
def review_log_info_text(log)
if log.collection_period_open?
"You can review and make changes to this log until #{log.form.submission_deadline.to_formatted_s(:govuk_date)}.".html_safe
else
start_year = log.startdate ? collection_start_year_for_date(log.startdate) : log.form.start_date.year
"This log is from the #{start_year}/#{start_year + 1} collection window, which is now closed."
end
end
def review_breadcrumbs(log)
class_name = log.class.model_name.human.downcase
if log.collection_closed_for_editing?
content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => url_for(log.class),
"Log #{log.id}" => "",
})
else
content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => url_for(log.class),
"Log #{log.id}" => url_for(log),
"Review #{class_name}" => "",
})
end
end
end

16
app/models/form_handler.rb

@ -115,10 +115,18 @@ class FormHandler
in_crossover_period? ? previous_collection_start_date : current_collection_start_date in_crossover_period? ? previous_collection_start_date : current_collection_start_date
end end
def start_date_of_earliest_open_for_editing_collection_period
in_edit_crossover_period? ? previous_collection_start_date : current_collection_start_date
end
def in_crossover_period?(now: Time.zone.now) def in_crossover_period?(now: Time.zone.now)
lettings_in_crossover_period?(now:) || sales_in_crossover_period?(now:) lettings_in_crossover_period?(now:) || sales_in_crossover_period?(now:)
end end
def in_edit_crossover_period?(now: Time.zone.now)
lettings_in_edit_crossover_period?(now:) || sales_in_edit_crossover_period?(now:)
end
def lettings_in_crossover_period?(now: Time.zone.now) def lettings_in_crossover_period?(now: Time.zone.now)
forms = lettings_forms.values forms = lettings_forms.values
forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1 forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1
@ -157,6 +165,14 @@ class FormHandler
end end
end end
def earliest_open_for_editing_collection_start_date(now: Time.zone.now)
if in_edit_crossover_period?(now:)
collection_start_date(now) - 1.year
else
collection_start_date(now)
end
end
private private
def get_all_forms def get_all_forms

4
app/models/location_deactivation_period.rb

@ -34,8 +34,8 @@ class LocationDeactivationPeriodValidator < ActiveModel::Validator
end end
elsif location.location_deactivation_periods.any? { |period| period.reactivation_date.present? && record.deactivation_date.between?(period.deactivation_date, period.reactivation_date - 1.day) } elsif location.location_deactivation_periods.any? { |period| period.reactivation_date.present? && record.deactivation_date.between?(period.deactivation_date, period.reactivation_date - 1.day) }
record.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation.during_deactivated_period")) record.errors.add(:deactivation_date, message: I18n.t("validations.location.deactivation.during_deactivated_period"))
elsif record.deactivation_date.before? FormHandler.instance.start_date_of_earliest_open_collection_period elsif record.deactivation_date.before? FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
record.errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: FormHandler.instance.start_date_of_earliest_open_collection_period.to_formatted_s(:govuk_date))) record.errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period.to_formatted_s(:govuk_date)))
elsif record.deactivation_date.before? location.available_from elsif record.deactivation_date.before? location.available_from
record.errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.before_creation", date: location.available_from.to_formatted_s(:govuk_date))) record.errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.before_creation", date: location.available_from.to_formatted_s(:govuk_date)))
end end

4
app/models/log.rb

@ -188,6 +188,10 @@ class Log < ApplicationRecord
bulk_upload_id.present? bulk_upload_id.present?
end end
def collection_closed_for_editing?
form.edit_end_date < Time.zone.now || older_than_previous_collection_year?
end
private private
# Handle logs that are older than previous collection start date # Handle logs that are older than previous collection start date

4
app/models/scheme_deactivation_period.rb

@ -34,8 +34,8 @@ class SchemeDeactivationPeriodValidator < ActiveModel::Validator
end end
elsif scheme.scheme_deactivation_periods.any? { |period| period.reactivation_date.present? && record.deactivation_date.between?(period.deactivation_date, period.reactivation_date - 1.day) } elsif scheme.scheme_deactivation_periods.any? { |period| period.reactivation_date.present? && record.deactivation_date.between?(period.deactivation_date, period.reactivation_date - 1.day) }
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation.during_deactivated_period")) record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.deactivation.during_deactivated_period"))
elsif record.deactivation_date.before? FormHandler.instance.start_date_of_earliest_open_collection_period elsif record.deactivation_date.before? FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.out_of_range", date: FormHandler.instance.start_date_of_earliest_open_collection_period.to_formatted_s(:govuk_date))) record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.out_of_range", date: FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period.to_formatted_s(:govuk_date)))
elsif record.deactivation_date.before? scheme.available_from elsif record.deactivation_date.before? scheme.available_from
record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.before_creation", date: scheme.available_from.to_formatted_s(:govuk_date))) record.errors.add(:deactivation_date, message: I18n.t("validations.scheme.toggle_date.before_creation", date: scheme.available_from.to_formatted_s(:govuk_date)))
end end

8
app/views/form/review.html.erb

@ -1,10 +1,6 @@
<% class_name = @log.class.model_name.human.downcase %> <% class_name = @log.class.model_name.human.downcase %>
<% content_for :title, "Review #{class_name}" %> <% content_for :title, "Review #{class_name}" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { <% review_breadcrumbs(@log) %>
"Logs" => url_for(@log.class),
"Log #{@log.id}" => url_for(@log),
"Review #{class_name}" => "",
}) %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
@ -12,7 +8,7 @@
<%= content_for(:title) %> <%= content_for(:title) %>
</h1> </h1>
<p class="govuk-body"> <p class="govuk-body">
You can review and make changes to this log until <%= @log.form.submission_deadline.to_formatted_s(:govuk_date) %>. <%= review_log_info_text(@log) %>
</p> </p>
<% @log.form.sections.map do |section| %> <% @log.form.sections.map do |section| %>
<h2 class="govuk-heading-m"><%= section.label %></h2> <h2 class="govuk-heading-m"><%= section.label %></h2>

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

@ -2,89 +2,93 @@
<h2 class="govuk-heading-m">Collection resources</h2> <h2 class="govuk-heading-m">Collection resources</h2>
<p class="govuk-body-s">For lettings starting during 1 April 2023 to 31 March 2024 and sales completing during the same period, use the 2023/24 forms.</p> <p class="govuk-body-s">For lettings starting during 1 April 2023 to 31 March 2024 and sales completing during the same period, use the 2023/24 forms.</p>
<h3 class="govuk-heading-s">Lettings 2023/24</h3> <% if FormHandler.instance.lettings_form_for_start_year(2023) && FormHandler.instance.lettings_form_for_start_year(2023).edit_end_date > Time.zone.today %>
<%= render DocumentListComponent.new(items: [ <h3 class="govuk-heading-s">Lettings 2023/24</h3>
{ <%= render DocumentListComponent.new(items: [
name: "Lettings log for tenants (2023/24)", {
href: download_23_24_lettings_form_path, name: "Lettings log for tenants (2023/24)",
metadata: file_type_size_and_pages("2023_24_lettings_paper_form.pdf", number_of_pages: 8), href: download_23_24_lettings_form_path,
}, metadata: file_type_size_and_pages("2023_24_lettings_paper_form.pdf", number_of_pages: 8),
{ },
name: "Lettings bulk upload template (2023/24) – New question ordering", {
href: download_23_24_lettings_bulk_upload_template_path, name: "Lettings bulk upload template (2023/24) – New question ordering",
metadata: file_type_size_and_pages("bulk-upload-lettings-template-2023-24.xlsx"), href: download_23_24_lettings_bulk_upload_template_path,
}, metadata: file_type_size_and_pages("bulk-upload-lettings-template-2023-24.xlsx"),
{ },
name: "Lettings bulk upload template (2023/24)", {
href: download_23_24_lettings_bulk_upload_legacy_template_path, name: "Lettings bulk upload template (2023/24)",
metadata: file_type_size_and_pages("bulk-upload-lettings-legacy-template-2023-24.xlsx"), href: download_23_24_lettings_bulk_upload_legacy_template_path,
}, metadata: file_type_size_and_pages("bulk-upload-lettings-legacy-template-2023-24.xlsx"),
{ },
name: "Lettings bulk upload specification (2023/24)", {
href: download_23_24_lettings_bulk_upload_specification_path, name: "Lettings bulk upload specification (2023/24)",
metadata: file_type_size_and_pages("bulk-upload-lettings-specification-2023-24.xlsx"), href: download_23_24_lettings_bulk_upload_specification_path,
}, metadata: file_type_size_and_pages("bulk-upload-lettings-specification-2023-24.xlsx"),
]) %> },
]) %>
<h3 class="govuk-heading-s">Sales 2023/24</h3> <h3 class="govuk-heading-s">Sales 2023/24</h3>
<%= render DocumentListComponent.new(items: [ <%= render DocumentListComponent.new(items: [
{ {
name: "Sales log for buyers (2023/24)", name: "Sales log for buyers (2023/24)",
href: download_23_24_sales_form_path, href: download_23_24_sales_form_path,
metadata: file_type_size_and_pages("2023_24_sales_paper_form.pdf", number_of_pages: 8), metadata: file_type_size_and_pages("2023_24_sales_paper_form.pdf", number_of_pages: 8),
}, },
{ {
name: "Sales bulk upload template (2023/24) – New question ordering", name: "Sales bulk upload template (2023/24) – New question ordering",
href: download_23_24_sales_bulk_upload_template_path, href: download_23_24_sales_bulk_upload_template_path,
metadata: file_type_size_and_pages("bulk-upload-sales-template-2023-24.xlsx"), metadata: file_type_size_and_pages("bulk-upload-sales-template-2023-24.xlsx"),
}, },
{ {
name: "Sales bulk upload template (2023/24)", name: "Sales bulk upload template (2023/24)",
href: download_23_24_sales_bulk_upload_legacy_template_path, href: download_23_24_sales_bulk_upload_legacy_template_path,
metadata: file_type_size_and_pages("bulk-upload-sales-legacy-template-2023-24.xlsx"), metadata: file_type_size_and_pages("bulk-upload-sales-legacy-template-2023-24.xlsx"),
}, },
{ {
name: "Sales bulk upload specification (2023/24)", name: "Sales bulk upload specification (2023/24)",
href: download_23_24_sales_bulk_upload_specification_path, href: download_23_24_sales_bulk_upload_specification_path,
metadata: file_type_size_and_pages("bulk-upload-sales-specification-2023-24.xlsx"), metadata: file_type_size_and_pages("bulk-upload-sales-specification-2023-24.xlsx"),
}, },
]) %> ]) %>
<% end %>
<h3 class="govuk-heading-s">Lettings 2022/23</h3> <% if FormHandler.instance.lettings_form_for_start_year(2022) && FormHandler.instance.lettings_form_for_start_year(2022).edit_end_date > Time.zone.today %>
<%= render DocumentListComponent.new(items: [ <h3 class="govuk-heading-s">Lettings 2022/23</h3>
{ <%= render DocumentListComponent.new(items: [
name: "Lettings log for tenants (2022/23)", {
href: download_22_23_lettings_form_path, name: "Lettings log for tenants (2022/23)",
metadata: file_type_size_and_pages("2022_23_lettings_paper_form.pdf", number_of_pages: 4), href: download_22_23_lettings_form_path,
}, metadata: file_type_size_and_pages("2022_23_lettings_paper_form.pdf", number_of_pages: 4),
{ },
name: "Lettings bulk upload template (2022/23)", {
href: download_22_23_lettings_bulk_upload_template_path, name: "Lettings bulk upload template (2022/23)",
metadata: file_type_size_and_pages("bulk-upload-lettings-template-2022-23.xlsx"), href: download_22_23_lettings_bulk_upload_template_path,
}, metadata: file_type_size_and_pages("bulk-upload-lettings-template-2022-23.xlsx"),
{ },
name: "Lettings bulk upload specification (2022/23)", {
href: download_22_23_lettings_bulk_upload_specification_path, name: "Lettings bulk upload specification (2022/23)",
metadata: file_type_size_and_pages("bulk-upload-lettings-specification-2022-23.xlsx"), href: download_22_23_lettings_bulk_upload_specification_path,
}, metadata: file_type_size_and_pages("bulk-upload-lettings-specification-2022-23.xlsx"),
]) %> },
]) %>
<h3 class="govuk-heading-s">Sales 2022/23</h3> <h3 class="govuk-heading-s">Sales 2022/23</h3>
<%= render DocumentListComponent.new(items: [ <%= render DocumentListComponent.new(items: [
{ {
name: "Sales log for buyers (2022/23)", name: "Sales log for buyers (2022/23)",
href: download_22_23_sales_form_path, href: download_22_23_sales_form_path,
metadata: file_type_size_and_pages("2022_23_sales_paper_form.pdf", number_of_pages: 5), metadata: file_type_size_and_pages("2022_23_sales_paper_form.pdf", number_of_pages: 5),
}, },
{ {
name: "Sales bulk upload template (2022/23)", name: "Sales bulk upload template (2022/23)",
href: download_22_23_sales_bulk_upload_template_path, href: download_22_23_sales_bulk_upload_template_path,
metadata: file_type_size_and_pages("bulk-upload-sales-template-2022-23.xlsx"), metadata: file_type_size_and_pages("bulk-upload-sales-template-2022-23.xlsx"),
}, },
{ {
name: "Sales bulk upload specification (2022/23)", name: "Sales bulk upload specification (2022/23)",
href: download_22_23_sales_bulk_upload_specification_path, href: download_22_23_sales_bulk_upload_specification_path,
metadata: file_type_size_and_pages("bulk-upload-sales-template-2022-23.xlsx"), metadata: file_type_size_and_pages("bulk-upload-sales-template-2022-23.xlsx"),
}, },
]) %> ]) %>
<% end %>
</div> </div>

2
app/views/locations/toggle_active.html.erb

@ -10,7 +10,7 @@
<%= form_with model: @location_deactivation_period, url: toggle_location_form_path(action, @location), method: "patch", local: true do |f| %> <%= form_with model: @location_deactivation_period, url: toggle_location_form_path(action, @location), method: "patch", local: true do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<% start_date = FormHandler.instance.earliest_open_collection_start_date(now: @location.available_from) %> <% start_date = FormHandler.instance.earliest_open_for_editing_collection_start_date %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset date_type_question(action), <%= f.govuk_radio_buttons_fieldset date_type_question(action),
legend: { text: I18n.t("questions.location.toggle_active.apply_from") }, legend: { text: I18n.t("questions.location.toggle_active.apply_from") },

2
app/views/schemes/toggle_active.html.erb

@ -10,7 +10,7 @@
<%= form_with model: @scheme_deactivation_period, url: toggle_scheme_form_path(action, @scheme), method: "patch", local: true do |f| %> <%= form_with model: @scheme_deactivation_period, url: toggle_scheme_form_path(action, @scheme), method: "patch", local: true do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<% start_date = FormHandler.instance.start_date_of_earliest_open_collection_period %> <% start_date = FormHandler.instance.earliest_open_for_editing_collection_start_date %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset date_type_question(action), <%= f.govuk_radio_buttons_fieldset date_type_question(action),
legend: { text: I18n.t("questions.scheme.toggle_active.apply_from") }, legend: { text: I18n.t("questions.scheme.toggle_active.apply_from") },

70
spec/requests/lettings_logs_controller_spec.rb

@ -908,15 +908,21 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "with a signed in user" do context "with a signed in user" do
before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), voiddate: Time.zone.local(2021, 4, 1), mrcdate: Time.zone.local(2021, 4, 1))
completed_lettings_log.reload
end
context "with lettings logs that are owned or managed by your organisation" do context "with lettings logs that are owned or managed by your organisation" do
before do before do
sign_in user sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {} get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
Timecop.freeze(2021, 4, 1) end
Singleton.__init__(FormHandler)
completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), voiddate: Time.zone.local(2021, 4, 1), mrcdate: Time.zone.local(2021, 4, 1)) after do
completed_lettings_log.reload Timecop.return
Timecop.unfreeze
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
end end
@ -933,19 +939,51 @@ RSpec.describe LettingsLogsController, type: :request do
end end
it "displays a link to update the log for currently editable logs" do it "displays a link to update the log for currently editable logs" do
completed_lettings_log.update!(startdate: Time.zone.local(2022, 4, 1), tenancylength: nil) completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), tenancylength: nil)
completed_lettings_log.reload completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2023, 12, 31)) expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31))
expect(completed_lettings_log.status).to eq("completed") expect(completed_lettings_log.status).to eq("completed")
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review") expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review")
end end
end
xit "displays a closed collection window message for previous collection year logs" do context "with lettings logs from a closed collection period before the previous collection" do
before do
sign_in user
Timecop.return
Singleton.__init__(FormHandler)
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
end
it "redirects to review page" do
expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}/review")
end
end
context "with lettings logs from a closed previous collection period" do
before do
sign_in user
Timecop.freeze(2023, 2, 1)
Singleton.__init__(FormHandler)
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 7, 1)) end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "redirects to review page" do
expect(response).to redirect_to("/lettings-logs/#{completed_lettings_log.id}/review")
end
it "displays a closed collection window message for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31))
expect(completed_lettings_log.status).to eq("completed") expect(completed_lettings_log.status).to eq("completed")
follow_redirect!
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.") expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.")
end end
end end
@ -992,10 +1030,17 @@ RSpec.describe LettingsLogsController, type: :request do
end end
before do before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
sign_in user sign_in user
get "/lettings-logs/#{section_completed_lettings_log.id}", headers:, params: {} get "/lettings-logs/#{section_completed_lettings_log.id}", headers:, params: {}
end end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
it "displays a section status for a lettings log" do it "displays a section status for a lettings log" do
assert_select ".govuk-tag", text: /Not started/, count: 6 assert_select ".govuk-tag", text: /Not started/, count: 6
assert_select ".govuk-tag", text: /Completed/, count: 1 assert_select ".govuk-tag", text: /Completed/, count: 1
@ -1019,12 +1064,19 @@ RSpec.describe LettingsLogsController, type: :request do
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:) }
before do before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
FactoryBot.create_list(:lettings_log, 3, unresolved: true, created_by: user) FactoryBot.create_list(:lettings_log, 3, unresolved: true, created_by: user)
lettings_log.update!(needstype: 2, scheme:, location:, unresolved: true) lettings_log.update!(needstype: 2, scheme:, location:, unresolved: true)
sign_in user sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {} get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
end end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "marks it as resolved when both scheme and location exist" do it "marks it as resolved when both scheme and location exist" do
lettings_log.reload lettings_log.reload
expect(lettings_log.unresolved).to eq(false) expect(lettings_log.unresolved).to eq(false)

2
spec/requests/locations_controller_spec.rb

@ -1832,7 +1832,7 @@ RSpec.describe LocationsController, type: :request do
let(:startdate) { Time.utc(2022, 9, 11) } let(:startdate) { Time.utc(2022, 9, 11) }
before do before do
Timecop.freeze(Time.utc(2023, 1, 10)) Timecop.freeze(Time.utc(2023, 9, 10))
sign_in user sign_in user
create(:location_deactivation_period, deactivation_date:, location:) create(:location_deactivation_period, deactivation_date:, location:)
location.save! location.save!

39
spec/requests/organisations_controller_spec.rb

@ -175,7 +175,10 @@ RSpec.describe OrganisationsController, type: :request do
describe "#show" do describe "#show" do
context "with an organisation that the user belongs to" do context "with an organisation that the user belongs to" do
let(:set_time) {}
before do before do
set_time
sign_in user sign_in user
get "/organisations/#{organisation.id}", headers:, params: {} get "/organisations/#{organisation.id}", headers:, params: {}
end end
@ -183,6 +186,42 @@ RSpec.describe OrganisationsController, type: :request do
it "redirects to details" do it "redirects to details" do
expect(response).to have_http_status(:redirect) expect(response).to have_http_status(:redirect)
end end
context "and 2022 collection window is open" do
let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 1)) }
it "displays correct resources for 2022/23 and 2023/24 collection years" do
follow_redirect!
expect(page).to have_content("Lettings 2023/24")
expect(page).to have_content("Sales 2023/24")
expect(page).to have_content("Lettings 2022/23")
expect(page).to have_content("Sales 2022/23")
end
end
context "and 2022 collection window is closed for editing" do
let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 1)) }
it "displays correct resources for 2022/23 and 2023/24 collection years" do
follow_redirect!
expect(page).to have_content("Lettings 2023/24")
expect(page).to have_content("Sales 2023/24")
expect(page).not_to have_content("Lettings 2022/23")
expect(page).not_to have_content("Sales 2022/23")
end
end
context "and 2023 collection window is closed for editing" do
let(:set_time) { allow(Time).to receive(:now).and_return(Time.zone.local(2025, 1, 1)) }
it "displays correct resources for 2022/23 and 2023/24 collection years" do
follow_redirect!
expect(page).not_to have_content("Lettings 2023/24")
expect(page).not_to have_content("Sales 2023/24")
expect(page).not_to have_content("Lettings 2022/23")
expect(page).not_to have_content("Sales 2022/23")
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

78
spec/requests/sales_logs_controller_spec.rb

@ -556,6 +556,84 @@ RSpec.describe SalesLogsController, type: :request do
end end
end end
context "when viewing a sales log" do
let(:headers) { { "Accept" => "text/html" } }
let(:completed_sales_log) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, created_by: user) }
before do
sign_in user
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
completed_sales_log.update!(saledate: Time.zone.local(2021, 4, 1))
completed_sales_log.reload
end
context "with sales logs that are owned by your organisation" do
before do
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "shows the tasklist for sales logs you have access to" do
expect(response.body).to match("Log")
expect(response.body).to match(completed_sales_log.id.to_s)
end
it "displays a link to update the log for currently editable logs" do
completed_sales_log.update!(saledate: Time.zone.local(2021, 4, 1))
completed_sales_log.reload
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
expect(completed_sales_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31))
expect(completed_sales_log.status).to eq("completed")
expect(page).to have_link("review and make changes to this log", href: "/sales-logs/#{completed_sales_log.id}/review?sales_log=true")
end
end
context "with sales logs from a closed collection period before the previous collection" do
before do
sign_in user
Timecop.return
Singleton.__init__(FormHandler)
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
end
it "redirects to review page" do
expect(response).to redirect_to("/sales-logs/#{completed_sales_log.id}/review?sales_log=true")
end
end
context "with sales logs from a closed previous collection period" do
before do
sign_in user
Timecop.freeze(2023, 2, 1)
Singleton.__init__(FormHandler)
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "redirects to review page" do
expect(response).to redirect_to("/sales-logs/#{completed_sales_log.id}/review?sales_log=true")
end
it "displays a closed collection window message for previous collection year logs" do
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
expect(completed_sales_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31))
expect(completed_sales_log.status).to eq("completed")
follow_redirect!
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.")
end
end
end
context "when requesting CSV download" do context "when requesting CSV download" do
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
let(:search_term) { "foot" } let(:search_term) { "foot" }

Loading…
Cancel
Save