Skip to content

Commit

Permalink
Correct string for translation key
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobm committed Aug 11, 2022
1 parent eb7d730 commit dadd31b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/views/fields/has_one/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ All show page attributes of has_one relationship would be rendered
</legend>
<% field.nested_show.attributes.each do |attribute| -%>
<div>
<dt class="attribute-label">
<%= t(
"helpers.label.#{field.associated_class_name.underscore}.#{attribute.name}",
default: attribute.name.titleize,
) %>
</dt>
<dd class="attribute-data attribute-data--<%= attribute.html_class %>">
<%= render_field attribute, { page: page } %>
</dd>
<dt class="attribute-label">
<%= t(
"helpers.label.#{field.associated_class_name.underscore}.#{attribute.name}",
default: attribute.name.titleize,
) %>
</dt>
<dd class="attribute-data attribute-data--<%= attribute.html_class %>">
<%= render_field attribute, { page: page } %>
</dd>
</div>
<% end -%>
</fieldset>
Expand Down
55 changes: 55 additions & 0 deletions spec/administrate/views/fields/has_one/_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,61 @@ def render_field
expect(rendered.strip).not_to include("<a")
end
end

it "uses the correct labels for fields" do
field_resource = create(:product_meta_tag)
path_to_field_resource = polymorphic_path([:admin, field_resource])

nested_simple_field = instance_double(
"Administrate::Field::String",
name: "simple_string_field",
truncate: "string value",
html_class: "string",
to_partial_path: "fields/string/index",
)

nested_show_page_for_has_one = instance_double(
"Administrate::Page::Show",
resource: double(
class: ProductMetaTag,
),
attributes: [
nested_simple_field
]
)

has_one_field = instance_double(
"Administrate::Field::HasOne",
display_associated_resource: "The Nested Resource",
data: field_resource,
linkable?: true,
nested_show: nested_show_page_for_has_one,
associated_class_name: "NestedHasOne",
)

page_double = instance_double("Administrate::Page::Show")

I18n.backend.translations(do_init: true)[:en].deep_merge!(
helpers: {
label: {
nested_has_one: {
simple_string_field: "Just a Simple String"
}
}
}
)

render(
partial: "fields/has_one/show",
locals: {
field: has_one_field,
page: page_double,
resource_name: "parent_resource",
},
)

expect(rendered.strip).to include("Just a Simple String")
end
end

context "when there are nested associations" do
Expand Down

0 comments on commit dadd31b

Please sign in to comment.