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
159c1822
Commit
159c1822
authored
Jan 15, 2019
by
Winnie Hellmann
Committed by
Kushal Pandya
Jan 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make parseBoolean idempotent
parent
0e510780
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
7 deletions
+19
-7
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+4
-3
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+15
-4
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
159c1822
...
@@ -430,13 +430,14 @@ export const historyPushState = newUrl => {
...
@@ -430,13 +430,14 @@ export const historyPushState = newUrl => {
};
};
/**
/**
* Returns true for a String "true" and false otherwise.
* Returns true for a String value of "true" and false otherwise.
* This is the opposite of Boolean(...).toString()
* This is the opposite of Boolean(...).toString().
* `parseBoolean` is idempotent.
*
*
* @param {String} value
* @param {String} value
* @returns {Boolean}
* @returns {Boolean}
*/
*/
export
const
parseBoolean
=
value
=>
value
===
'
true
'
;
export
const
parseBoolean
=
value
=>
(
value
&&
value
.
toString
())
===
'
true
'
;
/**
/**
* Converts permission provided as strings to booleans.
* Converts permission provided as strings to booleans.
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
159c1822
...
@@ -347,20 +347,31 @@ describe('common_utils', () => {
...
@@ -347,20 +347,31 @@ describe('common_utils', () => {
});
});
describe
(
'
parseBoolean
'
,
()
=>
{
describe
(
'
parseBoolean
'
,
()
=>
{
const
{
parseBoolean
}
=
commonUtils
;
it
(
'
returns true for "true"
'
,
()
=>
{
it
(
'
returns true for "true"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
true
'
)).
toEqual
(
true
);
expect
(
parseBoolean
(
'
true
'
)).
toEqual
(
true
);
});
});
it
(
'
returns false for "false"
'
,
()
=>
{
it
(
'
returns false for "false"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
false
'
)).
toEqual
(
false
);
expect
(
parseBoolean
(
'
false
'
)).
toEqual
(
false
);
});
});
it
(
'
returns false for "something"
'
,
()
=>
{
it
(
'
returns false for "something"
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
'
something
'
)).
toEqual
(
false
);
expect
(
parseBoolean
(
'
something
'
)).
toEqual
(
false
);
});
});
it
(
'
returns false for null
'
,
()
=>
{
it
(
'
returns false for null
'
,
()
=>
{
expect
(
commonUtils
.
parseBoolean
(
null
)).
toEqual
(
false
);
expect
(
parseBoolean
(
null
)).
toEqual
(
false
);
});
it
(
'
is idempotent
'
,
()
=>
{
const
input
=
[
'
true
'
,
'
false
'
,
'
something
'
,
null
];
input
.
forEach
(
value
=>
{
const
result
=
parseBoolean
(
value
);
expect
(
parseBoolean
(
result
)).
toBe
(
result
);
});
});
});
});
});
...
...
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