Skip to content

Commit

Permalink
Amend validator to not expect abrogation of schoolings of last school… (
Browse files Browse the repository at this point in the history
  • Loading branch information
pskl authored Oct 17, 2024
1 parent f238ad5 commit f4799b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/models/asp/payment_request_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ def check_da_attribution
add_error(:missing_attributive_decision) if !payment_request.schooling.attributive_decision.attached?
end

def check_da_abrogation
def check_da_abrogation # rubocop:disable Metrics/AbcSize
if !student.transferred? || (payment_request.schooling.abrogated? && payment_request.pfmp.within_schooling_dates?)
return
end

other_schoolings = student.schoolings.excluding(payment_request.schooling)
other_schoolings = student.schoolings.excluding(payment_request.schooling).to_a.select do |sc|
sc.classe.school_year == SchoolYear.current
end

return if other_schoolings.all?(&:abrogated?)

Expand Down
19 changes: 17 additions & 2 deletions spec/models/asp/payment_request_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,16 @@
end

describe "#check_da_abrogation" do
context "when student transferred and schooling needs abrogated attributive decision" do
context "when student is transferred and schooling needs abrogated attributive decision" do
let(:other_schooling) { instance_double(Schooling, abrogated?: false) }
let(:other_classe) { instance_double(Classe, school_year: SchoolYear.current) }

before do
allow(student).to receive(:transferred?).and_return(true)
allow(schooling).to receive(:abrogated?).and_return(false)
allow(pfmp).to receive(:within_schooling_dates?).and_return(true)
allow(student).to receive_message_chain(:schoolings, :excluding, :all?).and_return(false)
allow(student).to receive_message_chain(:schoolings, :excluding).and_return([other_schooling])
allow(other_schooling).to receive(:classe).and_return(other_classe)
end

it "adds an error" do
Expand All @@ -230,6 +234,17 @@
.to include(a_hash_including(error: :needs_abrogated_attributive_decision))
end
end

context "when conditions for abrogation are not met" do
before do
allow(student).to receive(:transferred?).and_return(false)
end

it "does not add an error" do
expect { validator.send(:check_da_abrogation) }
.not_to change { payment_request.errors.details[:ready_state_validation] }
end
end
end

describe "#validate" do
Expand Down

0 comments on commit f4799b5

Please sign in to comment.