Skip to content

Commit

Permalink
feat: #10 validate tiem is between 0 and 23 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianrbp committed Aug 12, 2024
1 parent 3fc7308 commit 9042e25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/app/models/availability.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Availability < ApplicationRecord
belongs_to :engineer

validates :time, inclusion: { in: 0..23, message: "must be between 0 and 23" }
end
22 changes: 22 additions & 0 deletions backend/spec/models/availability_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rails_helper'

RSpec.describe Availability, type: :model do
let(:engineer) { create(:engineer) }

it "is valid with a time between 0 and 23" do
availability = Availability.new(engineer: engineer, week: "2024-01", day: "Monday", time: 10)
expect(availability).to be_valid
end

it "is invalid with a time less than 0" do
availability = Availability.new(engineer: engineer, week: "2024-01", day: "Monday", time: -1)
expect(availability).to_not be_valid
expect(availability.errors[:time]).to include("must be between 0 and 23")
end

it "is invalid with a time greater than 23" do
availability = Availability.new(engineer: engineer, week: "2024-01", day: "Monday", time: 24)
expect(availability).to_not be_valid
expect(availability.errors[:time]).to include("must be between 0 and 23")
end
end

0 comments on commit 9042e25

Please sign in to comment.