-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing support for
date_select
method.
Prior to this commit, a corresponding implementation for [ActionView::Helpers::FormBuilder#date_select][date_select] was omitted. This commit corrects that oversight. [date_select]: https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-date_select
- Loading branch information
1 parent
c9d000b
commit d3bbac5
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require "form_builder_test_case" | ||
|
||
class ViewPartialFormBuilderDateSelectTest < FormBuilderTestCase | ||
test "renders defaults when overrides are not declared" do | ||
render(inline: <<~ERB) | ||
<%= form_with(model: Post.new) do |form| %> | ||
<%= form.date_select( | ||
:start_date, | ||
{ | ||
prompt: true, | ||
order: [:year], | ||
start_year: 2000, | ||
end_year: 2001, | ||
}, | ||
{} | ||
) %> | ||
<% end %> | ||
ERB | ||
|
||
assert_select %(option[value=""]), count: 1 | ||
assert_select %(option[value="2000"]), text: "2000" | ||
assert_select %(option[value="2001"]), text: "2001" | ||
end | ||
|
||
test "renders arguments as local assigns" do | ||
declare_template "form_builder/_date_select.html.erb", <<~'HTML' | ||
<%= form.date_select( | ||
method, | ||
options.merge( | ||
prompt: true, | ||
order: [:year], | ||
start_year: 2000, | ||
), | ||
class: "year #{html_options.delete(:class)}", | ||
**html_options | ||
) %> | ||
HTML | ||
|
||
render(inline: <<~ERB) | ||
<%= form_with(model: Post.new) do |form| %> | ||
<%= form.date_select( | ||
:start_date, | ||
{ | ||
order: [:year], | ||
end_year: 2001, | ||
}, | ||
class: "post-year", | ||
"data-attr": "foo", | ||
) %> | ||
<% end %> | ||
ERB | ||
|
||
assert_select %(select[class~="year"][class~="post-year"][data-attr="foo"]) do | ||
assert_select %(option[value=""]), count: 1 | ||
assert_select %(option[value="2000"]), text: "2000" | ||
assert_select %(option[value="2001"]), text: "2001" | ||
end | ||
end | ||
end |