-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add html classes to inputs with the wrappers API #622
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -164,6 +164,18 @@ class WrapperTest < ActionView::TestCase | |
assert_select "section.custom_wrapper div.another_wrapper input.string" | ||
end | ||
|
||
test 'wrappers with use classes on input basis with arrays' do | ||
swap_wrapper :default do | ||
with_form_for @user, :name | ||
assert_select "section.custom_wrapper div.class1.class2 input.class3.class4" | ||
|
||
output_buffer.replace "" | ||
|
||
with_form_for @user, :name, wrapper: custom_wrapper_with_no_wrapping_tag | ||
assert_select "div.custom_wrapper div.elem input.input_class_yo.other_class_yo" | ||
end | ||
end | ||
|
||
test 'access wrappers with indifferent access' do | ||
swap_wrapper :another do | ||
with_form_for @user, :name, wrapper: "another" | ||
|
@@ -172,6 +184,52 @@ class WrapperTest < ActionView::TestCase | |
end | ||
end | ||
|
||
test 'single element without wrap_with applies options to component tags' do | ||
swap_wrapper :default, custom_wrapper_with_no_wrapping_tag do | ||
with_form_for @user, :name | ||
assert_select "div.custom_wrapper div.elem input.input_class_yo" | ||
assert_select "div.custom_wrapper div.elem input.other_class_yo" | ||
assert_select "div.custom_wrapper div.elem input.string" | ||
assert_select "div.custom_wrapper div.elem label[data-yo='yo']" | ||
assert_select "div.custom_wrapper div.elem span.custom_yo", :text => "custom" | ||
assert_select "div.custom_wrapper div.elem label.both_yo" | ||
assert_select "div.custom_wrapper div.elem input.both_yo" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, forget about it. Other tests need more clean up with that, we can do that later. |
||
end | ||
end | ||
|
||
test 'single element with wrap with and component options applies to both' do | ||
swap_wrapper :default, custom_wrapper_with_wrapping_tag_and_component_options do | ||
with_form_for @user, :name | ||
assert_no_select "div.custom_wrapper > input" | ||
assert_select "div.custom_wrapper div.wrap input.input_class_yo" | ||
assert_select "div.custom_wrapper div.wrap input.other_class_yo" | ||
end | ||
end | ||
|
||
test 'adding any option to tag components on the input ignores them' do | ||
with_concat_form_for @user do |f| | ||
concat f.input :name, :invalid => 'thing' | ||
end | ||
assert_no_select "input[invalid]" | ||
end | ||
|
||
test 'adding any option to tag components in wrapper makes html attributes' do | ||
swap_wrapper :default, custom_wrapper_with_wrapping_tag_and_invalid_attributes do | ||
with_input_for @user, :name, :string, :other_invalid => 'other_thing' | ||
assert_select "input.input_class_yo" | ||
assert_select "input[invalid='thing']" | ||
assert_no_select "input[other_invalid]" | ||
end | ||
end | ||
|
||
test 'adding invalid options to non-tag components raises an exception' do | ||
assert_raise ArgumentError, "Invalid options [:class] passed to placeholder." do | ||
swap_wrapper :default, custom_wrapper_with_invalid_options do | ||
with_form_for @user, :name | ||
end | ||
end | ||
end | ||
|
||
test 'do not duplicate label classes for different inputs' do | ||
swap_wrapper :default, self.custom_wrapper_with_label_html_option do | ||
with_concat_form_for(@user) do |f| | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can still use the
options.keys != [:wrap_with]
check here.