Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/fields/has_one/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The form will be rendered as nested_from to parent relationship.
<% end %>

<% attributes.each do |attribute| %>
<div class="field-unit field-unit--<%= attribute.html_class %>">
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requireness(attribute) %>">
<div class="field-unit field-unit--<%= attribute.html_class %> field-unit--<%= requiredness(attribute) %>">

I think we should probably make the change to "requiredness", as I do think that's more correct than "requireness".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be changed in this PR?
Or would it be okay if I open a new PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Right, it's not actually introduced here. I hadn't realised. Let's leave it for now, we've already got the existing name and it's fine.

<%= render_field attribute, f: has_one_f %>
</div>
<% hint_key = "administrate.field_hints.#{field.name}.#{attribute.name}" %>
Expand Down
4 changes: 3 additions & 1 deletion spec/features/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
Product.human_attribute_name(:name),
Product.human_attribute_name(:description),
Product.human_attribute_name(:price),
Product.human_attribute_name(:image_url)
Product.human_attribute_name(:image_url),
ProductMetaTag.human_attribute_name(:meta_title),
ProductMetaTag.human_attribute_name(:meta_description)
]

required_field_labels = find_all(".field-unit--required").map(&:text)
Expand Down
17 changes: 17 additions & 0 deletions spec/helpers/administrate/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@
end
expect(requireness(release_year)).to eq("optional")
end

context "when the resource is nested" do
it "returns 'required' if nested field is required" do
field = page.attributes.values.flatten.detect { |i| i.attribute == :product_meta_tag }
nested_field = field.nested_form.attributes.values.flatten.detect { |i| i.attribute == :meta_title }
expect(requireness(nested_field)).to eq("required")
end

it "returns 'optional' if nested field is not required" do
field = page.attributes.values.flatten.detect { |i| i.attribute == :product_meta_tag }
nested_field = field.nested_form.attributes.values.flatten.detect { |i| i.attribute == :meta_title }

allow_any_instance_of(ActiveRecord::Validations::PresenceValidator).to receive(:options).and_return({on: :any})

expect(requireness(nested_field)).to eq("optional")
end
end
end

describe "#sort_order" do
Expand Down