-
-
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.
When using the select field for a boolean attribute that can be either `true`, `false` or `nil`, the current behavior causes `false` and `nil` to be treated the same. If the attribute is set to `false`, the edit dashboard shows the selected value as being the `nil` option instead of `false` as expected.
- Loading branch information
1 parent
ded79d2
commit 33a46ff
Showing
2 changed files
with
42 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "rails_helper" | ||
require "administrate/field/select" | ||
|
||
describe "fields/select/_form", type: :view do | ||
it "displays the selected option" do | ||
customer = build(:customer) | ||
select = instance_double( | ||
"Administrate::Field::Select", | ||
attribute: :email_subscriber, | ||
data: false, | ||
selectable_options: [true, false, nil], | ||
) | ||
|
||
render( | ||
partial: "fields/select/form.html.erb", | ||
locals: { field: select, f: form_builder(customer) }, | ||
) | ||
|
||
expect(rendered).to have_css( | ||
%{select[name="customer[email_subscriber]"] | ||
option[value="false"][selected="selected"]}, | ||
) | ||
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 | ||
end | ||
end | ||
end |