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
0491500d
Commit
0491500d
authored
Feb 10, 2022
by
Mark Florian
Committed by
Alex Kalderimis
Feb 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise if not given a valid selected value
parent
6629bbcb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
app/helpers/listbox_helper.rb
app/helpers/listbox_helper.rb
+4
-3
spec/helpers/listbox_helper_spec.rb
spec/helpers/listbox_helper_spec.rb
+2
-2
No files found.
app/helpers/listbox_helper.rb
View file @
0491500d
...
...
@@ -16,7 +16,8 @@ module ListboxHelper
# the sort key), `text` is the user-facing string for the item, and `href` is
# the path to redirect to when that item is selected.
#
# The `selected` parameter is the currently selected `value`.
# The `selected` parameter is the currently selected `value`, and must
# correspond to one of the `items`.
#
# The final parameter `html_options` applies arbitrary attributes to the
# returned tag. Some of these are passed to the underlying Vue component as
...
...
@@ -38,10 +39,10 @@ module ListboxHelper
selected
||=
items
.
first
[
:value
]
selected_option
=
items
.
find
{
|
opt
|
opt
[
:value
]
==
selected
}
selected_text
=
selected_option
[
:text
]
if
selected_option
raise
ArgumentError
,
"cannot find
#{
selected
}
in
#{
items
}
"
unless
selected_option
button
=
button_tag
(
type: :button
,
class:
DROPDOWN_BUTTON_CLASSES
)
do
content_tag
(
:span
,
selected_
text
,
class:
DROPDOWN_INNER_CLASS
)
+
content_tag
(
:span
,
selected_
option
[
:text
]
,
class:
DROPDOWN_INNER_CLASS
)
+
sprite_icon
(
'chevron-down'
,
css_class:
DROPDOWN_ICON_CLASS
)
end
...
...
spec/helpers/listbox_helper_spec.rb
View file @
0491500d
...
...
@@ -67,8 +67,8 @@ RSpec.describe ListboxHelper do
context
'when selected does not match any item'
do
let
(
:selected
)
{
'qux'
}
it
'
sets button text to empty string
'
do
expect
(
subject
.
at_css
(
'button'
).
content
).
to
eq
(
''
)
it
'
raises an error
'
do
expect
{
subject
}.
to
raise_error
(
ArgumentError
,
/cannot find qux/
)
end
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