Skip to content

Commit

Permalink
23:59 is the max settable time
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Nov 21, 2024
1 parent 04d6ed9 commit 537fefd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions modules/costs/app/models/time_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class TimeEntry < ApplicationRecord
belongs_to :rate, -> { where(type: %w[HourlyRate DefaultHourlyRate]) }, class_name: "Rate"
belongs_to :logged_by, class_name: "User"

MIN_TIME = 0 # => 00:00
MAX_TIME = (60 * 24) - 1 # => 23:59

acts_as_customizable

acts_as_journalized
Expand All @@ -49,14 +52,14 @@ class TimeEntry < ApplicationRecord
if: -> { TimeEntry.must_track_start_and_end_time? }

validates :start_time,
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 60 * 24 },
numericality: { only_integer: true, greater_than_or_equal_to: MIN_TIME, less_than_or_equal_to: MAX_TIME },
allow_blank: true

validates :end_time,
numericality: {
only_integer: true,
greater_than: ->(te) { te.start_time.to_i },
less_than_or_equal_to: 60 * 24
less_than_or_equal_to: MAX_TIME
# TODO: nice error message
},
allow_blank: true
Expand Down
7 changes: 6 additions & 1 deletion modules/costs/spec/models/time_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,16 @@ def ensure_membership(project, user, permissions)
expect(time_entry).to be_valid
end

it "allows integer values between 0 and 1440" do
it "allows integer values between 0 and 1439" do
time_entry.end_time = 1337
expect(time_entry).to be_valid
end

it "does not allow values > 1439" do
time_entry.end_time = 1440
expect(time_entry).not_to be_valid
end

it "does not allow non integer values" do
time_entry.end_time = 1.5
expect(time_entry).not_to be_valid
Expand Down

0 comments on commit 537fefd

Please sign in to comment.