diff --git a/app/models/holiday_info.rb b/app/models/holiday_info.rb index 60677ffb4b..dcd55ded61 100644 --- a/app/models/holiday_info.rb +++ b/app/models/holiday_info.rb @@ -35,7 +35,6 @@ class HolidayInfo < ApplicationRecord format: { with: /\A[a-zA-Z\s]+\z/ }, length: { maximum: 30 } validates :date, :category, presence: true - validate :validate_optional_holidays, if: -> { category == "optional" } validate :validate_holiday_category validate :validate_year @@ -49,12 +48,6 @@ class HolidayInfo < ApplicationRecord private - def validate_optional_holidays - unless holiday&.enable_optional_holidays - errors.add(:base, "optional holidays are disabled") - end - end - def validate_holiday_category unless holiday&.holiday_types&.include?(category) errors.add(:category, "must be a valid holiday category for the associated holiday") diff --git a/app/services/time_tracking_index_service.rb b/app/services/time_tracking_index_service.rb index 52d5f0e889..59f369fd62 100644 --- a/app/services/time_tracking_index_service.rb +++ b/app/services/time_tracking_index_service.rb @@ -93,11 +93,12 @@ def group_timeoff_entries_by_leave_date def leave_types leave = current_company.leaves.find_by(year:) - leave&.leave_types&.kept || [] + leave&.leave_types&.kept end def holiday_infos holiday = current_company.holidays.find_by(year:) - holiday&.holiday_infos&.kept || [] + all_holidays = holiday&.holiday_infos&.kept + holiday.enable_optional_holidays ? all_holidays : all_holidays.national end end diff --git a/spec/models/holiday_info_spec.rb b/spec/models/holiday_info_spec.rb index 967cdf40f1..3e18dd720b 100644 --- a/spec/models/holiday_info_spec.rb +++ b/spec/models/holiday_info_spec.rb @@ -23,12 +23,6 @@ it { is_expected.to validate_presence_of(:date) } it { is_expected.to validate_presence_of(:category) } - it 'validates optional holidays when the category is "optional"' do - optional_holiday_info.holiday.enable_optional_holidays = false - optional_holiday_info.valid? - expect(optional_holiday_info.errors[:base]).to include("optional holidays are disabled") - end - it "validates the year of the date" do invalid_holiday_info = build(:holiday_info, holiday:, date: "2022-01-01") invalid_holiday_info.valid? diff --git a/spec/requests/internal_api/v1/time_tracking/index_spec.rb b/spec/requests/internal_api/v1/time_tracking/index_spec.rb index 2827ed0c30..628555627a 100644 --- a/spec/requests/internal_api/v1/time_tracking/index_spec.rb +++ b/spec/requests/internal_api/v1/time_tracking/index_spec.rb @@ -13,6 +13,9 @@ let!(:project2) { create(:project, client: client1) } let!(:project3) { create(:project, client: client2) } let!(:project4) { create(:project, client: client3) } + let!(:holiday) { create(:holiday, year: Date.current.year, company: company1) } + let(:national_holiday) { create(:holiday_info, date: Date.current, category: "national", holiday:) } + let(:optional_holiday) { create(:holiday_info, date: Date.current + 2.days, category: "optional", holiday:) } before do create(:project_member, user:, project: project1)