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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
cae27eae
Commit
cae27eae
authored
Oct 27, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Fix booleans not recognized as such when using the `to_boolean` helper
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
b3210df3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
CHANGELOG.md
CHANGELOG.md
+1
-0
lib/api/helpers.rb
lib/api/helpers.rb
+1
-0
spec/requests/api/api_helpers_spec.rb
spec/requests/api/api_helpers_spec.rb
+18
-11
No files found.
CHANGELOG.md
View file @
cae27eae
...
...
@@ -11,6 +11,7 @@ Please view this file on the master branch, on stable branches it's out of date.
-
Fix HipChat notifications rendering (airatshigapov, eisnerd)
-
Add hover to trash icon in notes !7008 (blackst0ne)
-
Fix sidekiq stats in admin area (blackst0ne)
-
API: Fix booleans not recognized as such when using the
`to_boolean`
helper
-
Removed delete branch tooltip !6954
-
Escape ref and path for relative links !6050 (winniehell)
-
Fixed link typo on /help/ui to Alerts section. !6915 (Sam Rose)
...
...
lib/api/helpers.rb
View file @
cae27eae
...
...
@@ -6,6 +6,7 @@ module API
SUDO_PARAM
=
:sudo
def
to_boolean
(
value
)
return
value
if
[
true
,
false
].
include?
(
value
)
return
true
if
value
=~
/^(true|t|yes|y|1|on)$/i
return
false
if
value
=~
/^(false|f|no|n|0|off)$/i
...
...
spec/requests/api/api_helpers_spec.rb
View file @
cae27eae
...
...
@@ -266,18 +266,25 @@ describe API::Helpers, api: true do
end
describe
'.to_boolean'
do
it
'accepts booleans'
do
expect
(
to_boolean
(
true
)).
to
be
(
true
)
expect
(
to_boolean
(
false
)).
to
be
(
false
)
end
it
'converts a valid string to a boolean'
do
expect
(
to_boolean
(
'true'
)).
to
be_truthy
expect
(
to_boolean
(
'YeS'
)).
to
be_truthy
expect
(
to_boolean
(
't'
)).
to
be_truthy
expect
(
to_boolean
(
'1'
)).
to
be_truthy
expect
(
to_boolean
(
'ON'
)).
to
be_truthy
expect
(
to_boolean
(
'FaLse'
)).
to
be_falsy
expect
(
to_boolean
(
'F'
)).
to
be_falsy
expect
(
to_boolean
(
'NO'
)).
to
be_falsy
expect
(
to_boolean
(
'n'
)).
to
be_falsy
expect
(
to_boolean
(
'0'
)).
to
be_falsy
expect
(
to_boolean
(
'oFF'
)).
to
be_falsy
expect
(
to_boolean
(
true
)).
to
be
(
true
)
expect
(
to_boolean
(
'true'
)).
to
be
(
true
)
expect
(
to_boolean
(
'YeS'
)).
to
be
(
true
)
expect
(
to_boolean
(
't'
)).
to
be
(
true
)
expect
(
to_boolean
(
'1'
)).
to
be
(
true
)
expect
(
to_boolean
(
'ON'
)).
to
be
(
true
)
expect
(
to_boolean
(
'FaLse'
)).
to
be
(
false
)
expect
(
to_boolean
(
'F'
)).
to
be
(
false
)
expect
(
to_boolean
(
'NO'
)).
to
be
(
false
)
expect
(
to_boolean
(
'n'
)).
to
be
(
false
)
expect
(
to_boolean
(
'0'
)).
to
be
(
false
)
expect
(
to_boolean
(
'oFF'
)).
to
be
(
false
)
end
it
'converts an invalid string to nil'
do
...
...
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