-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle carryover leaves using
Carryover
model (#1824)
- This will be used to calculate previous year carryforward leaves count Co-authored-by: Nishant Samel <nishant@saeloun.com>
- Loading branch information
Showing
9 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: carryovers | ||
# | ||
# id :bigint not null, primary key | ||
# discarded_at :datetime | ||
# duration :integer | ||
# from_year :integer | ||
# to_year :integer | ||
# total_leave_balance :integer | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# company_id :bigint not null | ||
# leave_type_id :bigint not null | ||
# user_id :bigint not null | ||
# | ||
# Indexes | ||
# | ||
# index_carryovers_on_company_id (company_id) | ||
# index_carryovers_on_discarded_at (discarded_at) | ||
# index_carryovers_on_leave_type_id (leave_type_id) | ||
# index_carryovers_on_user_id (user_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (company_id => companies.id) | ||
# fk_rails_... (leave_type_id => leave_types.id) | ||
# fk_rails_... (user_id => users.id) | ||
# | ||
class Carryover < ApplicationRecord | ||
include Discard::Model | ||
|
||
belongs_to :user | ||
belongs_to :company | ||
belongs_to :leave_type | ||
|
||
validates :from_year, :to_year, :total_leave_balance, :duration, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateCarryovers < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :carryovers do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.references :company, null: false, foreign_key: true | ||
t.references :leave_type, null: false, foreign_key: true | ||
t.integer :from_year | ||
t.integer :to_year | ||
t.integer :total_leave_balance | ||
t.integer :duration | ||
t.datetime :discarded_at | ||
|
||
t.timestamps | ||
end | ||
add_index :carryovers, :discarded_at | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :carryover do | ||
user | ||
company | ||
leave_type | ||
from_year { 2023 } | ||
to_year { 2024 } | ||
total_leave_balance { 10000 } # in minutes | ||
duration { 2400 } # in minutes | ||
discarded_at { "2024-04-29 19:59:39" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Carryover, type: :model do | ||
subject { build(:carryover) } | ||
|
||
describe "Associations" do | ||
it { is_expected.to belong_to(:user) } | ||
it { is_expected.to belong_to(:company) } | ||
it { is_expected.to belong_to(:leave_type) } | ||
end | ||
|
||
describe "Validations" do | ||
it { is_expected.to validate_presence_of(:from_year) } | ||
it { is_expected.to validate_presence_of(:to_year) } | ||
it { is_expected.to validate_presence_of(:total_leave_balance) } | ||
it { is_expected.to validate_presence_of(:duration) } | ||
end | ||
end |