Skip to content

Commit

Permalink
fixup! Add ability to ask external caches to invalidate.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Sep 14, 2023
1 parent 26db683 commit cb5ec47
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/info_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ def set_calculated_state!(state)
end
end

def foi_attachment
return unless params[:attachment_id]
@foi_attachment ||= FoiAttachment.find(params[:attachment_id])
end

protected

def variety
Expand Down Expand Up @@ -604,9 +609,4 @@ def filetype
def request_public_body_tags
info_request.public_body.tag_array_for_search
end

def foi_attachment
return unless params[:attachment_id]
@foi_attachment ||= FoiAttachment.find(params[:attachment_id])
end
end
5 changes: 5 additions & 0 deletions spec/factories/info_request_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@
end
end

factory :foi_attachment_event do
event_type { 'edit_attachment' }
params { { attachment_id: 1 } }
end

end

end
46 changes: 46 additions & 0 deletions spec/models/info_request_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,39 @@

end

context "the event is for a comment" do

it "enqueues NotifyCacheJob job for the comment" do
event = FactoryBot.build(:comment_event)
expect(NotifyCacheJob).to receive(:perform_later).with(event.comment)
event.save
end

end

context "the event is for an foi_attachment" do

it "enqueues NotifyCacheJob job for the attachment" do
attachment = mock_model(FoiAttachment)
allow(FoiAttachment).to receive(:find).and_return(attachment)
event = FactoryBot.build(:foi_attachment_event)
expect(NotifyCacheJob).to receive(:perform_later).with(attachment)
event.save
end

end

context "the event is for a request" do

it "enqueues NotifyCacheJob job for the request" do
event = FactoryBot.build(:info_request_event)
expect(NotifyCacheJob).to receive(:perform_later).
with(event.info_request)
event.save
end

end

it "calls the request's create_or_update_request_summary on create" do
info_request = FactoryBot.create(:info_request)
event = FactoryBot.build(:info_request_event, info_request: info_request)
Expand Down Expand Up @@ -879,4 +912,17 @@
end
end

describe '#foi_attachment' do
it 'loads FoiAttachment from params as if it was an assoication' do
event = FactoryBot.build(
:info_request_event, params: { attachment_id: 1 }
)

attachment = mock_model(FoiAttachment)
allow(FoiAttachment).to receive(:find).with(1).and_return(attachment)

expect(event.foi_attachment).to eq(attachment)
end
end

end

0 comments on commit cb5ec47

Please sign in to comment.