Skip to content

Commit

Permalink
Add integer validations for recurring meeting intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Dec 9, 2024
1 parent 9c2bd2b commit b0be0bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/meeting/app/models/recurring_meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class RecurringMeeting < ApplicationRecord
validates_presence_of :start_time, :title, :frequency, :end_after
validates_presence_of :end_date, if: -> { end_after_specific_date? }
validates_numericality_of :iterations, if: -> { end_after_iterations? }
validates_numericality_of :interval,
only_integer: true,
greater_than_or_equal_to: 1,
if: -> { !frequency_working_days? }

validate :end_date_constraints,
if: -> { end_after_specific_date? }
Expand Down
28 changes: 28 additions & 0 deletions modules/meeting/spec/models/recurring_meeting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@
end
end

describe "intervals" do
subject { build(:recurring_meeting) }

it "validates integer values >= 1" do
subject.interval = 1
expect(subject).to be_valid
expect(subject.errors[:interval]).to be_empty
end

it "adds errors for invalid values", :aggregate_failures do
subject.interval = 0
expect(subject).not_to be_valid
expect(subject.errors[:interval]).to include("must be greater than or equal to 1.")

subject.interval = -1
expect(subject).not_to be_valid
expect(subject.errors[:interval]).to include("must be greater than or equal to 1.")

subject.interval = 0.1
expect(subject).not_to be_valid
expect(subject.errors[:interval]).to include("is not an integer.")

subject.interval = "asdf"
expect(subject).not_to be_valid
expect(subject.errors[:interval]).to include("is not a number.")
end
end

describe "daily schedule" do
subject do
build(:recurring_meeting,
Expand Down

0 comments on commit b0be0bd

Please sign in to comment.