Skip to content

Commit

Permalink
pfmp: fix the day count validation logic
Browse files Browse the repository at this point in the history
A full week means 5 days which wasn't allowed before.
  • Loading branch information
freesteph committed Apr 5, 2024
1 parent 852eaed commit c6c8fa1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/pfmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Pfmp < ApplicationRecord
only_integer: true,
allow_nil: true,
greater_than: 0,
less_than_or_equal_to: ->(pfmp) { (pfmp.end_date - pfmp.start_date).to_i }
less_than_or_equal_to: ->(pfmp) { (pfmp.end_date - pfmp.start_date).to_i + 1 }
}

scope :finished, -> { where("pfmps.end_date <= (?)", Time.zone.today) }
Expand Down
10 changes: 8 additions & 2 deletions spec/models/pfmp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@
end

describe "day count" do
subject(:pfmp) { build(:pfmp, start_date: Time.zone.now, end_date: 7.days.from_now) }
subject(:pfmp) do
build(
:pfmp,
start_date: Time.zone.now.next_week(:monday),
end_date: Time.zone.now.next_week(:friday)
)
end

context "when the number of days doesn't fit in the date range" do
before { pfmp.day_count = 8 }
Expand All @@ -62,7 +68,7 @@
end

context "when the number fits exactly in the day range" do
before { pfmp.day_count = 7 }
before { pfmp.day_count = 5 }

it { is_expected.to be_valid }
end
Expand Down

0 comments on commit c6c8fa1

Please sign in to comment.