Skip to content

Commit

Permalink
Add duration validation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
radical-ube committed Oct 14, 2024
1 parent 07e3b46 commit 31731d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/uncut.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Uncut < MediaResource
validates :medium, inclusion: {in: %w[audio]}, if: :status_complete?
validates :duration, numericality: {greater_than: 0}, if: :status_complete?
validate :validate_segmentation

before_validation :set_defaults
Expand Down
14 changes: 13 additions & 1 deletion test/models/uncut_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

uncut.segmentation[0] = [0.5, 1]
uncut.segmentation[2] = [3.5, nil]
episode.contents[0].update(status: "complete", medium: "audio")
episode.contents[0].update!(status: "complete", medium: "audio", duration: 1)
uncut.slice_contents

assert_equal 5, episode.contents.size
Expand All @@ -50,6 +50,18 @@
uncut.medium = "audio"
assert uncut.valid?
end

it "must have a duration greater than 0 when complete" do
assert uncut.valid?
assert uncut.status_created?

uncut.duration = 0
uncut.status = "complete"
refute uncut.valid?

uncut.duration = 100
assert uncut.valid?
end
end

describe "#validate_segmentation" do
Expand Down

0 comments on commit 31731d8

Please sign in to comment.