Browse Source

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

pull/1721/head
Kat 2 years ago
parent
commit
3cd3504224
  1. 3
      app/controllers/lettings_logs_controller.rb
  2. 12
      app/helpers/review_helper.rb
  3. 2
      app/views/form/review.html.erb
  4. 64
      spec/requests/lettings_logs_controller_spec.rb

3
app/controllers/lettings_logs_controller.rb

@ -1,4 +1,5 @@
class LettingsLogsController < LogsController
include CollectionTimeHelper
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
before_action :find_resource, only: %i[update show]
@ -63,6 +64,8 @@ class LettingsLogsController < LogsController
if @log.unresolved
redirect_to(send(@log.form.unresolved_log_path, @log))
elsif @log.form.edit_end_date < Time.zone.now || (@log.startdate.present? && @log.startdate < previous_collection_start_date)
redirect_to review_lettings_log_path(@log)
else
render("logs/edit", locals: { current_user: })
end

12
app/helpers/review_helper.rb

@ -0,0 +1,12 @@
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
end

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

@ -12,7 +12,7 @@
<%= content_for(:title) %>
</h1>
<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>
<% @log.form.sections.map do |section| %>
<h2 class="govuk-heading-m"><%= section.label %></h2>

64
spec/requests/lettings_logs_controller_spec.rb

@ -908,15 +908,21 @@ RSpec.describe LettingsLogsController, type: :request do
end
context "with a signed in user" do
context "with lettings logs that are owned or managed by your organisation" do
before do
sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
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
Timecop.unfreeze
end
context "with lettings logs that are owned or managed by your organisation" do
before do
sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
@ -933,7 +939,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
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
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
@ -941,11 +947,43 @@ RSpec.describe LettingsLogsController, type: :request do
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")
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: {}
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, 7, 1))
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.")
end
end
@ -992,10 +1030,17 @@ RSpec.describe LettingsLogsController, type: :request do
end
before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
sign_in user
get "/lettings-logs/#{section_completed_lettings_log.id}", headers:, params: {}
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
it "displays a section status for a lettings log" do
assert_select ".govuk-tag", text: /Not started/, count: 6
assert_select ".govuk-tag", text: /Completed/, count: 1
@ -1019,12 +1064,19 @@ RSpec.describe LettingsLogsController, type: :request do
let!(:location) { FactoryBot.create(:location, scheme:) }
before do
Timecop.freeze(2021, 4, 1)
Singleton.__init__(FormHandler)
FactoryBot.create_list(:lettings_log, 3, unresolved: true, created_by: user)
lettings_log.update!(needstype: 2, scheme:, location:, unresolved: true)
sign_in user
get "/lettings-logs/#{lettings_log.id}", headers:, params: {}
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "marks it as resolved when both scheme and location exist" do
lettings_log.reload
expect(lettings_log.unresolved).to eq(false)

Loading…
Cancel
Save