diff --git a/docs/api/apiv3/components/schemas/user_non_working_time_collection_model.yml b/docs/api/apiv3/components/schemas/user_non_working_time_collection_model.yml index 1d302ca1340..a45cf41b9c0 100644 --- a/docs/api/apiv3/components/schemas/user_non_working_time_collection_model.yml +++ b/docs/api/apiv3/components/schemas/user_non_working_time_collection_model.yml @@ -41,19 +41,21 @@ example: elements: - _type: UserNonWorkingTime id: 7 - date: "2025-06-18" + startDate: "2025-06-16" + endDate: "2025-06-20" _links: self: - href: /api/v3/users/42/non_working_times/2025-06-16 + href: /api/v3/users/42/non_working_times/7 user: href: /api/v3/users/42 title: Jane Doe - _type: UserNonWorkingTime id: 8 - date: "2025-12-24" + startDate: "2025-12-24" + endDate: "2025-12-24" _links: self: - href: /api/v3/users/42/non_working_times/2025-12-24 + href: /api/v3/users/42/non_working_times/8 user: href: /api/v3/users/42 title: Jane Doe diff --git a/spec/models/user_working_hours_spec.rb b/spec/models/user_working_hours_spec.rb index f883e7e50b8..027575d7b7e 100644 --- a/spec/models/user_working_hours_spec.rb +++ b/spec/models/user_working_hours_spec.rb @@ -38,13 +38,32 @@ RSpec.describe UserWorkingHours do it { is_expected.to validate_presence_of(:valid_from) } + # The *_hours virtual attributes have a converting setter (hours → minutes), so + # shoulda-matchers cannot induce invalid states through it. We bypass the setter + # and write directly to the underlying minute column instead. %i[monday tuesday wednesday thursday friday saturday sunday].each do |day| - it { is_expected.to validate_presence_of(:"#{day}_hours") } + describe "##{day}_hours" do + it "is invalid when exceeding 24 hours" do + subject.public_send(:"#{day}=", (24.5 * 60).round) + expect(subject).not_to be_valid + expect(subject.errors[:"#{day}_hours"]).to be_present + end - it do - expect(subject).to validate_numericality_of(:"#{day}_hours") - .is_greater_than_or_equal_to(0) - .is_less_than_or_equal_to(24) + it "is invalid when negative" do + subject.public_send(:"#{day}=", -60) + expect(subject).not_to be_valid + expect(subject.errors[:"#{day}_hours"]).to be_present + end + + it "is valid at 0 hours" do + subject.public_send(:"#{day}=", 0) + expect(subject).to be_valid + end + + it "is valid at 24 hours" do + subject.public_send(:"#{day}=", 24 * 60) + expect(subject).to be_valid + end end end diff --git a/spec/support/pages/users/non_working_times.rb b/spec/support/pages/users/non_working_times.rb index 29fa5bf748a..f5ae2814fe7 100644 --- a/spec/support/pages/users/non_working_times.rb +++ b/spec/support/pages/users/non_working_times.rb @@ -135,7 +135,7 @@ module Pages end def expect_working_days_count(count) - expect(page).to have_field(I18n.t(:label_working_days), disabled: true, with: count.to_s) + expect(page).to have_field(I18n.t(:label_working_days), with: count.to_s) end def expect_sidebar_entry(text)