Skip to content

Commit

Permalink
Load a queued request for submission#show
Browse files Browse the repository at this point in the history
This is the post submission action so its safe to assume the request
should be queued by now.
  • Loading branch information
gbp committed May 1, 2018
1 parent b144a2b commit e6364cf
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/controllers/concerns/findable_foi_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def find_foi_request
redirect_if_missing_request
end

def find_queued_foi_request
@foi_request = foi_request_from_session(scope: FoiRequest.queued)
redirect_if_missing_request
end

def foi_request_from_session(scope: FoiRequest)
scope.
includes(:contact).
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/foi/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SubmissionsController < ApplicationController
include FindableFoiRequest

before_action :find_foi_request, only: %i[new create]
before_action :find_foi_request_from_session, only: %i[show]
before_action :find_queued_foi_request, only: %i[show]
before_action :redirect_if_missing_contact
before_action :new_submission, only: %i[new create]
before_action :find_submission, only: %i[show]
Expand All @@ -28,10 +28,6 @@ def show; end

private

def find_foi_request_from_session
@foi_request = foi_request_from_session
end

def redirect_if_missing_contact
return if @foi_request.contact
redirect_to new_foi_request_contact_path
Expand Down
5 changes: 5 additions & 0 deletions app/models/foi_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ class FoiRequest < ApplicationRecord
left_joins(:submission).
where(submissions: { state: [nil, Submission::UNQUEUED] })
}

scope :queued, lambda {
left_joins(:submission).
where.not(submissions: { state: [nil, Submission::UNQUEUED] })
}
end
6 changes: 0 additions & 6 deletions spec/controllers/foi/submissions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@
describe 'GET #show' do
subject { get :show, session: { request_id: '1' } }

before do
# temporary
allow(FoiRequest).to receive(:includes).
with(:contact).and_return(foi_request_scope)
end

include_examples 'redirect if missing contact'

it 'returns http success' do
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/foi_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
trait :unqueued do
association :submission, :unqueued
end

trait :queued do
association :submission, :queued
end
end
end
4 changes: 4 additions & 0 deletions spec/factories/submissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
trait :unqueued do
state Submission::UNQUEUED
end

trait :queued do
state Submission::QUEUED
end
end
end
6 changes: 6 additions & 0 deletions spec/models/foi_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
describe 'scopes' do
let!(:pending) { create(:foi_request) }
let!(:unqueued) { create(:foi_request, :unqueued) }
let!(:queued) { create(:foi_request, :queued) }

describe '.unqueued' do
subject { FoiRequest.unqueued }
it { is_expected.to match [pending, unqueued] }
end

describe '.queued' do
subject { FoiRequest.queued }
it { is_expected.to match [queued] }
end
end
end
3 changes: 3 additions & 0 deletions spec/support/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
before do
allow(FoiRequest).to receive(:unqueued).
and_return(foi_request_scope)
allow(FoiRequest).to receive(:queued).
and_return(foi_request_scope)

allow(foi_request_scope).to receive(:includes).
with(:contact).and_return(foi_request_scope)
allow(foi_request_scope).to receive(:references).
Expand Down

0 comments on commit e6364cf

Please sign in to comment.