Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/time off type #71

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/models/time_off.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_offs
#
# id :bigint not null, primary key
# ends_at :datetime
# starts_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# time_off_type_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_time_offs_on_time_off_type_id (time_off_type_id)
# index_time_offs_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (time_off_type_id => time_off_types.id)
# fk_rails_... (user_id => users.id)
#
class TimeOff < ApplicationRecord
belongs_to :user
belongs_to :time_off_type

validates :starts_at, presence: true
validates :ends_at, presence: true
end
14 changes: 14 additions & 0 deletions app/models/time_off_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_off_types
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
class TimeOffType < ApplicationRecord
validates :name, presence: true
end
11 changes: 11 additions & 0 deletions db/migrate/20231106170512_create_time_off_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class CreateTimeOffTypes < ActiveRecord::Migration[7.0]
def change
create_table :time_off_types do |t|
t.string :name

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20231106173201_create_time_offs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class CreateTimeOffs < ActiveRecord::Migration[7.0]
def change
create_table :time_offs do |t|
t.references :user, null: false, foreign_key: true
t.references :time_off_type, null: false, foreign_key: true
t.datetime :starts_at
t.datetime :ends_at

t.timestamps
end
end
end
22 changes: 20 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions spec/factories/time_off_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_off_types
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
FactoryBot.define do
factory :time_off_type do
name { 'paid time off' }
end
end
32 changes: 32 additions & 0 deletions spec/factories/time_offs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_offs
#
# id :bigint not null, primary key
# ends_at :datetime
# starts_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# time_off_type_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_time_offs_on_time_off_type_id (time_off_type_id)
# index_time_offs_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (time_off_type_id => time_off_types.id)
# fk_rails_... (user_id => users.id)
#
FactoryBot.define do
factory :time_off do
user
time_of_type
starts_at { '2023-11-06 17:32:01' }
ends_at { '2023-12-06 17:32:01' }
end
end
37 changes: 37 additions & 0 deletions spec/models/time_off_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_offs
#
# id :bigint not null, primary key
# ends_at :datetime
# starts_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# time_off_type_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_time_offs_on_time_off_type_id (time_off_type_id)
# index_time_offs_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (time_off_type_id => time_off_types.id)
# fk_rails_... (user_id => users.id)
#
require 'rails_helper'

RSpec.describe TimeOff, type: :model do
context 'validations' do
it { should validate_presence_of(:starts_at) }
it { should validate_presence_of(:ends_at) }
end

context 'associations' do
it { should belong_to(:user) }
it { should belong_to(:time_off_type) }
end
end
18 changes: 18 additions & 0 deletions spec/models/time_off_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: time_off_types
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'

RSpec.describe TimeOffType, type: :model do
context 'validations' do
it { should validate_presence_of(:name) }
end
end
Loading