From 4012ef6e1029ae7eed260ec0fd96d5063a295bf3 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 | 12 ++++++++++-- 2 files changed, 11 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..142173357 100644 --- a/spec/models/pfmp_spec.rb +++ b/spec/models/pfmp_spec.rb @@ -47,7 +47,15 @@ end describe "day count" do - subject(:pfmp) { build(:pfmp, start_date: Time.zone.now, end_date: 7.days.from_now) } + subject(:pfmp) do + start = Time.zone.now.beginning_of_week + + build( + :pfmp, + start_date: start, + end_date: start.end_of_week(:saturday) + ) + end context "when the number of days doesn't fit in the date range" do before { pfmp.day_count = 8 } @@ -62,7 +70,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