Skip to content

Commit

Permalink
Merge branch 'fix-duplicate-response-on-old-request' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Sep 21, 2023
2 parents b6c48e4 + a4111f8 commit 905fc22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
26 changes: 14 additions & 12 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,13 @@ def self.requests_very_old_after_months
def self.stop_new_responses_on_old_requests
# 'old' months since last change to request, only allow new incoming
# messages from authority domains
InfoRequest
.been_published
.where(allow_new_responses_from: 'anybody')
.where.not(url_title: 'holding_pen')
.updated_before(requests_old_after_months.months.ago.to_date)
.find_in_batches do |batch|
InfoRequest.
been_published.
where(allow_new_responses_from: 'anybody').
where.not(url_title: 'holding_pen').
updated_before(requests_old_after_months.months.ago.to_date).
distinct.
find_in_batches do |batch|
batch.each do |info_request|
old_allow_new_responses_from = info_request.allow_new_responses_from

Expand All @@ -570,12 +571,13 @@ def self.stop_new_responses_on_old_requests

# 'very_old' months since last change to request, don't allow any new
# incoming messages
InfoRequest
.been_published
.where(allow_new_responses_from: %w[anybody authority_only])
.where.not(url_title: 'holding_pen')
.updated_before(requests_very_old_after_months.months.ago.to_date)
.find_in_batches do |batch|
InfoRequest.
been_published.
where(allow_new_responses_from: %w[anybody authority_only]).
where.not(url_title: 'holding_pen').
updated_before(requests_very_old_after_months.months.ago.to_date).
distinct.
find_in_batches do |batch|
batch.each do |info_request|
old_allow_new_responses_from = info_request.allow_new_responses_from

Expand Down
5 changes: 4 additions & 1 deletion spec/models/info_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,11 @@

it 'logs an event after changing new responses to authority_only' do
request.update(updated_at: 6.months.ago - 1.day)
request.log_event('edit', {})
subject
last_event = request.reload.last_event
request.reload
last_event = request.last_event
expect(request.info_request_events.size).to eq(3)
expect(last_event.event_type).to eq('edit')
expect(last_event.params).
to match(old_allow_new_responses_from: 'anybody',
Expand Down

0 comments on commit 905fc22

Please sign in to comment.