-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring textarea input options (#2665)
This allows configuring the rendered `<textarea>` for `Field::Text` fields, e.g.: ATTRIBUTE_TYPES = { body: Field::Text.with_options(input_options: { rows: 20 }), }.freeze Will render: <textarea rows="20" name="post[body]" id="post_body">...</textarea>
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
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,56 @@ | ||
require "rails_helper" | ||
require "administrate/field/text" | ||
|
||
RSpec.describe "fields/text/_form", type: :view do | ||
it "allows configuring input options" do | ||
textarea = instance_double( | ||
"Administrate::Field::Text", | ||
attribute: :name, | ||
data: nil, | ||
options: {input_options: {rows: 50}} | ||
) | ||
|
||
render_partial(textarea) | ||
|
||
expect(rendered).to have_css(%(textarea[rows=50])) | ||
end | ||
|
||
it "doesn't require input options" do | ||
textarea = instance_double( | ||
"Administrate::Field::Text", | ||
attribute: :name, | ||
data: nil, | ||
options: {} | ||
) | ||
|
||
render_partial(textarea) | ||
|
||
expect(rendered).to have_css(%(textarea)) | ||
end | ||
|
||
def render_partial(field) | ||
product = build(:product) | ||
|
||
render( | ||
partial: "fields/text/form", | ||
locals: {field: field, f: form_builder(product)} | ||
) | ||
end | ||
|
||
def form_builder(object) | ||
ActionView::Helpers::FormBuilder.new( | ||
object.model_name.singular, | ||
object, | ||
build_template, | ||
{} | ||
) | ||
end | ||
|
||
def build_template | ||
Object.new.tap do |template| | ||
template.extend ActionView::Helpers::FormHelper | ||
template.extend ActionView::Helpers::FormOptionsHelper | ||
template.extend ActionView::Helpers::FormTagHelper | ||
end | ||
end | ||
end |