-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #10 validate tiem is between 0 and 23 hours
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Availability < ApplicationRecord | ||
belongs_to :engineer | ||
|
||
validates :time, inclusion: { in: 0..23, message: "must be between 0 and 23" } | ||
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,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 |