From ac17c831bee019e460a57b4895b0b0f4f5376a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= Date: Fri, 5 Apr 2024 10:13:39 +0200 Subject: [PATCH] pfmp: fix the day count validation logic A full week means 5 days which wasn't allowed before. --- app/models/pfmp.rb | 2 +- spec/models/pfmp_spec.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/pfmp.rb b/app/models/pfmp.rb index 6c1d43252..0ce0010db 100644 --- a/app/models/pfmp.rb +++ b/app/models/pfmp.rb @@ -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) } diff --git a/spec/models/pfmp_spec.rb b/spec/models/pfmp_spec.rb index 58ee570d3..4883f1cef 100644 --- a/spec/models/pfmp_spec.rb +++ b/spec/models/pfmp_spec.rb @@ -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 } @@ -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