Skip to content

Commit

Permalink
Handle empty file
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Oct 29, 2023
1 parent a9169d9 commit 5e5c619
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/shot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Shot < ApplicationRecord
validates :start_time, :information, :sha, presence: true

def self.from_file(user, file_content)
return if file_content.blank?
return Shot.new if file_content.blank?

Parsers::Base.parse(file_content).build_shot(user)
end
Expand Down
5 changes: 5 additions & 0 deletions test/models/shot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def new_shot(path)
Shot.from_file(users(:miha), File.read(path))
end

test "returns invalid Shot with empty file" do
shot = Shot.from_file(users(:miha), "")
assert_not shot.valid?
end

test "extracts fields from .shot file" do
path = "test/fixtures/files/20210921T085910"
shot = new_shot("#{path}.shot")
Expand Down

0 comments on commit 5e5c619

Please sign in to comment.