Skip to content

Commit

Permalink
Fix enable / disable of optional holidays (#1740)
Browse files Browse the repository at this point in the history
* Fix enable / disable of optional holidays

- Show only `National` holidays in dropdown after diabling `Optional` holiday
- Remove unwanted validation and respective spec

* Fix failing specs

---------

Co-authored-by: Nishant Samel <nishant@saeloun.com>
  • Loading branch information
nisusam and Nishant Samel authored Mar 21, 2024
1 parent 3e1b25d commit 64f6723
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
7 changes: 0 additions & 7 deletions app/models/holiday_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions app/services/time_tracking_index_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions spec/models/holiday_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions spec/requests/internal_api/v1/time_tracking/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64f6723

Please sign in to comment.