diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f8892a742b9..054b9f57ef8 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -757,6 +757,10 @@ def must_be_internal_or_external end end + def internally_reviewed? + outgoing_messages.where(what_doing: 'internal_review').any? + end + def is_external? external_url.nil? ? false : true end @@ -1039,7 +1043,10 @@ def calculate_status(cached_value_ok=false) end def base_calculate_status - return 'waiting_classification' if awaiting_description + if awaiting_description + return 'internal_review' if internally_reviewed? + return 'waiting_classification' + end return described_state unless described_state == "waiting_response" # Compare by date, so only overdue on next day, not if 1 second late return 'waiting_response_very_overdue' if diff --git a/spec/models/info_request/state/calculator_spec.rb b/spec/models/info_request/state/calculator_spec.rb index 7b109ebca8b..db80d486693 100644 --- a/spec/models/info_request/state/calculator_spec.rb +++ b/spec/models/info_request/state/calculator_spec.rb @@ -195,11 +195,7 @@ end end - context "when the request is in internal_review" do - before :each do - info_request.set_described_state("internal_review") - end - + shared_examples 'internal_review' do context "and the user is the owner" do it "returns only two pending states" do transitions = calculator.transitions( @@ -237,6 +233,25 @@ end end + context "when the request is in internal_review" do + before :each do + info_request.set_described_state("internal_review") + end + + include_examples 'internal_review' + end + + context "when the request was in internal_review" do + let(:info_request) do + FactoryBot.create( + :info_request, :with_internal_review_request, + awaiting_description: true, described_state: 'waiting_response' + ) + end + + include_examples 'internal_review' + end + context "when the request is in an 'other' state" do context "and the user is the owner" do it_behaves_like( diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index b3591271bc1..21b7c0b9298 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -1631,6 +1631,23 @@ end end + describe '#internally_reviewed?' do + subject { info_request.internally_reviewed? } + + context 'when internal review has been sent' do + let(:info_request) do + FactoryBot.create(:info_request, :with_internal_review_request) + end + + it { is_expected.to eq true } + end + + context 'when internal review has not been sent' do + let(:info_request) { FactoryBot.create(:info_request) } + it { is_expected.to eq false } + end + end + describe '#is_external?' do it 'returns true if there is an external url' do