Skip to content

Commit

Permalink
fixup! Update request base calculated status
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Oct 27, 2023
1 parent 82fce05 commit c7c54e5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
7 changes: 2 additions & 5 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def must_be_internal_or_external
end
end

def internally_reviewed?
def internal_review_requested?
outgoing_messages.where(what_doing: 'internal_review').any?
end

Expand Down Expand Up @@ -1043,10 +1043,7 @@ def calculate_status(cached_value_ok=false)
end

def base_calculate_status
if awaiting_description
return 'internal_review' if internally_reviewed?
return 'waiting_classification'
end
return 'waiting_classification' if awaiting_description
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
Expand Down
13 changes: 10 additions & 3 deletions app/models/info_request/state/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def transitions(opts = {})
other: {}
}
end
opts.merge!(in_internal_review: state == 'internal_review')
opts.merge!(

Check warning on line 96 in app/models/info_request/state/calculator.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Performance/RedundantMerge: Use opts[:in_internal_review] = state == 'internal_review'; opts[:internal_review_requested] = @info_request.internal_review_requested? instead of opts.merge!( Raw Output: app/models/info_request/state/calculator.rb:96:9: C: [Correctable] Performance/RedundantMerge: Use opts[:in_internal_review] = state == 'internal_review'; opts[:internal_review_requested] = @info_request.internal_review_requested? instead of opts.merge!( in_internal_review: state == 'internal_review', internal_review_requested: @info_request.internal_review_requested? ). (https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code) opts.merge!( ... ^^^^^^^^^^^^
in_internal_review: state == 'internal_review',
internal_review_requested: @info_request.internal_review_requested?
)
build_transitions_hash(opts)
end

Expand Down Expand Up @@ -132,7 +135,11 @@ def pending_states(opts)
if opts.fetch(:in_internal_review, false)
states = %w[internal_review gone_postal]
else
states = %w[
states = []
if opts.fetch(:internal_review_requested, false)
states += ['internal_review']
end
states += %w[
waiting_response
waiting_clarification
gone_postal
Expand All @@ -141,7 +148,7 @@ def pending_states(opts)
states += ['internal_review']
end
end
states
states.uniq
end

def complete_states(_opts = {})
Expand Down
6 changes: 4 additions & 2 deletions app/models/info_request/state/transitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def self.owner_gone_postal_transition_label(_opts = {})
end

def self.owner_internal_review_transition_label(opts = {})
if opts.fetch(:in_internal_review, false)
if opts.fetch(:in_internal_review, false) ||
opts.fetch(:internal_review_requested, false)

Check warning on line 90 in app/models/info_request/state/transitions.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. Raw Output: app/models/info_request/state/transitions.rb:90:13: C: [Correctable] Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. opts.fetch(:internal_review_requested, false) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_("I'm still <strong>waiting</strong> for the internal review")
else
_("I'm waiting for an <strong>internal review</strong> response")
Expand Down Expand Up @@ -139,7 +140,8 @@ def self.other_user_gone_postal_transition_label(_opts = {})
end

def self.other_user_internal_review_transition_label(opts = {})
if opts.fetch(:in_internal_review, false)
if opts.fetch(:in_internal_review, false) ||
opts.fetch(:internal_review_requested, false)

Check warning on line 144 in app/models/info_request/state/transitions.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. Raw Output: app/models/info_request/state/transitions.rb:144:13: C: [Correctable] Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. opts.fetch(:internal_review_requested, false) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_("Still awaiting an <strong>internal review</strong>")
else
# To match what would happen if this method didn't exist, because
Expand Down
61 changes: 49 additions & 12 deletions spec/models/info_request/state/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@
end
end

shared_examples 'internal_review' do
context "when the request is in internal_review" do
before :each do
info_request.set_described_state("internal_review")
end

context "and the user is the owner" do
it "returns only two pending states" do
transitions = calculator.transitions(
Expand Down Expand Up @@ -233,23 +237,56 @@
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
context "when the request received a response after being in internal_review" do
let(:info_request) do
FactoryBot.create(
:info_request, :with_internal_review_request,
awaiting_description: true, described_state: 'waiting_response'
described_state: 'waiting_response'
)
end

include_examples 'internal_review'
before do
mail = Mail.new
mail.to info_request.incoming_email
mail.body 'Internal review reply'
info_request.receive(mail, mail.to_s)
end

context "and the user is the owner" do
it "returns only two pending states" do
transitions = calculator.transitions(
is_owning_user: true,
user_asked_to_update_status: false)

Check warning on line 259 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. Raw Output: spec/models/info_request/state/calculator_spec.rb:259:47: C: [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. user_asked_to_update_status: false) ^
expected = %w[internal_review waiting_response waiting_clarification gone_postal]

Check warning on line 260 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/LineLength: Line is too long. [91/80] (https://rubystyle.guide#max-line-length) Raw Output: spec/models/info_request/state/calculator_spec.rb:260:81: C: [Correctable] Layout/LineLength: Line is too long. [91/80] (https://rubystyle.guide#max-line-length) expected = %w[internal_review waiting_response waiting_clarification gone_postal] ^^^^^^^^^^^
expect(transitions[:pending].keys).to eq(expected)
end

it "returns a different label for the internal_review status" do
transitions = calculator.transitions(
is_owning_user: true,
user_asked_to_update_status: false)

Check warning on line 267 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. Raw Output: spec/models/info_request/state/calculator_spec.rb:267:47: C: [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. user_asked_to_update_status: false) ^
expected = "I'm still <strong>waiting</strong> for the internal review"

Check warning on line 268 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Layout/LineLength: Line is too long. [81/80] (https://rubystyle.guide#max-line-length) Raw Output: spec/models/info_request/state/calculator_spec.rb:268:81: C: Layout/LineLength: Line is too long. [81/80] (https://rubystyle.guide#max-line-length) expected = "I'm still <strong>waiting</strong> for the internal review" ^
expect(transitions[:pending]["internal_review"]).to eq expected
end
end

context "and the user is some other user" do
it "returns only two pending states" do
transitions = calculator.transitions(
is_owning_user: false,
user_asked_to_update_status: false)

Check warning on line 277 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. Raw Output: spec/models/info_request/state/calculator_spec.rb:277:47: C: [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. user_asked_to_update_status: false) ^
expected = %w[internal_review waiting_response waiting_clarification gone_postal]

Check warning on line 278 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/LineLength: Line is too long. [91/80] (https://rubystyle.guide#max-line-length) Raw Output: spec/models/info_request/state/calculator_spec.rb:278:81: C: [Correctable] Layout/LineLength: Line is too long. [91/80] (https://rubystyle.guide#max-line-length) expected = %w[internal_review waiting_response waiting_clarification gone_postal] ^^^^^^^^^^^
expect(transitions[:pending].keys).to eq(expected)
end

it "returns a different label for the internal_review status" do
transitions = calculator.transitions(
is_owning_user: false,
user_asked_to_update_status: false)

Check warning on line 285 in spec/models/info_request/state/calculator_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. Raw Output: spec/models/info_request/state/calculator_spec.rb:285:47: C: [Correctable] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. user_asked_to_update_status: false) ^
expected = "Still awaiting an <strong>internal review</strong>"
expect(transitions[:pending]["internal_review"]).to eq expected
end
end
end

context "when the request is in an 'other' state" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/info_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,8 @@
end
end

describe '#internally_reviewed?' do
subject { info_request.internally_reviewed? }
describe '#internal_review_requested?' do
subject { info_request.internal_review_requested? }

context 'when internal review has been sent' do
let(:info_request) do
Expand Down

0 comments on commit c7c54e5

Please sign in to comment.