Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e6b5ad91
Commit
e6b5ad91
authored
Mar 24, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return nil rather than raising an error
parent
448bc31b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
8 deletions
+6
-8
lib/gitlab/utils/mime_type.rb
lib/gitlab/utils/mime_type.rb
+2
-4
spec/lib/gitlab/utils/mime_type_spec.rb
spec/lib/gitlab/utils/mime_type_spec.rb
+4
-4
No files found.
lib/gitlab/utils/mime_type.rb
View file @
e6b5ad91
...
...
@@ -5,17 +5,15 @@
module
Gitlab
module
Utils
class
MimeType
Error
=
Class
.
new
(
StandardError
)
class
<<
self
def
from_io
(
io
)
r
aise
Error
,
"input isn't an IO object"
unless
io
.
is_a?
(
IO
)
||
io
.
is_a?
(
StringIO
)
r
eturn
unless
io
.
is_a?
(
IO
)
||
io
.
is_a?
(
StringIO
)
MimeMagic
.
by_magic
(
io
).
try
(
:type
)
end
def
from_string
(
string
)
r
aise
Error
,
"input isn't a string"
unless
string
.
is_a?
(
String
)
r
eturn
unless
string
.
is_a?
(
String
)
MimeMagic
.
by_magic
(
string
)
end
...
...
spec/lib/gitlab/utils/mime_type_spec.rb
View file @
e6b5ad91
...
...
@@ -10,8 +10,8 @@ RSpec.describe Gitlab::Utils::MimeType do
context
"input isn't an IO"
do
let
(
:io
)
{
"test"
}
it
"r
aises an error
"
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Utils
::
MimeType
::
Error
)
it
"r
eturns nil
"
do
expect
(
subject
).
to
be_nil
end
end
...
...
@@ -42,8 +42,8 @@ RSpec.describe Gitlab::Utils::MimeType do
context
"input isn't a string"
do
let
(
:str
)
{
nil
}
it
"r
aises an error
"
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Utils
::
MimeType
::
Error
)
it
"r
eturns nil
"
do
expect
(
subject
).
to
be_nil
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment