<%= f.select(field.attribute_key, nil, {}, multiple: true) do %>
diff --git a/app/views/fields/has_one/_form.html.erb b/app/views/fields/has_one/_form.html.erb
index 701f9e7ce0..8bdfa53eef 100644
--- a/app/views/fields/has_one/_form.html.erb
+++ b/app/views/fields/has_one/_form.html.erb
@@ -18,7 +18,7 @@ The form will be rendered as nested_from to parent relationship.
<%= f.fields_for field.attribute, field.data || field.nested_form.resource.class.new do |has_one_f| %>
- <%= field.nested_form.resource_name.titleize %>
+ <%= t "helpers.label.#{f.object_name}.#{field.nested_form.resource_name}", default: field.nested_form.resource_name.titleize %>
<% field.nested_form.attributes.each do |attribute| -%>
<%= render_field attribute, f: has_one_f %>
diff --git a/spec/administrate/views/fields/has_many/_form_spec.rb b/spec/administrate/views/fields/has_many/_form_spec.rb
index c52d90a3f3..83de3a1494 100644
--- a/spec/administrate/views/fields/has_many/_form_spec.rb
+++ b/spec/administrate/views/fields/has_many/_form_spec.rb
@@ -13,14 +13,14 @@
locals: { f: fake_form_builder, field: has_many },
)
- expect(rendered).to include("Associated Objects")
+ expect(rendered).to include("Associated objects")
end
end
def fake_form_builder
double("Form Builder").as_null_object.tap do |form_builder|
allow(form_builder).to receive(:label) do |*args|
- args.second.to_s.titleize
+ args.first.to_s.humanize
end
end
end
diff --git a/spec/administrate/views/fields/has_one/_form_spec.rb b/spec/administrate/views/fields/has_one/_form_spec.rb
index c7e9fc0851..713700eaca 100644
--- a/spec/administrate/views/fields/has_one/_form_spec.rb
+++ b/spec/administrate/views/fields/has_one/_form_spec.rb
@@ -23,6 +23,7 @@ def form_builder
allow(builder).to receive(:fields_for) do |&block|
block.call(double("Fields For Form Builder"))
end
+ allow(builder).to receive(:object_name).and_return(:product)
builder
end
diff --git a/spec/features/orders_form_spec.rb b/spec/features/orders_form_spec.rb
index 6738e0e18d..0d6725cf1d 100644
--- a/spec/features/orders_form_spec.rb
+++ b/spec/features/orders_form_spec.rb
@@ -36,8 +36,8 @@
line_items = create_list(:line_item, 3)
visit edit_admin_order_path(order)
- find_option(line_items.first, "line_item_ids").select_option
- find_option(line_items.last, "line_item_ids").select_option
+ find_option(line_items.first, "Line items").select_option
+ find_option(line_items.last, "Line items").select_option
click_on "Update Order"
order.reload
@@ -51,7 +51,7 @@
line_item = create(:line_item, order: order)
visit edit_admin_order_path(order)
- find_option(line_item, "line_item_ids").unselect_option
+ find_option(line_item, "Line items").unselect_option
click_on "Update Order"
order.reload
@@ -71,8 +71,29 @@
expect(find("#order_line_item_ids").value).to match_array(expected)
end
- def find_option(associated_model, field_id)
- field = find("#order_" + field_id)
+ it "displays translated labels" do
+ custom_label = "Lines"
+ order = create(:order)
+
+ translations = {
+ helpers: {
+ label: {
+ order: {
+ line_items: custom_label,
+ },
+ },
+ },
+ }
+
+ with_translations(:en, translations) do
+ visit edit_admin_order_path(order)
+
+ expect(page).to have_css("label", text: custom_label)
+ end
+ end
+
+ def find_option(associated_model, field_locator)
+ field = find_field(field_locator)
field.find("option", text: displayed(associated_model))
end
end
diff --git a/spec/features/products_form_spec.rb b/spec/features/products_form_spec.rb
index c3f84ab8bb..383f98a151 100644
--- a/spec/features/products_form_spec.rb
+++ b/spec/features/products_form_spec.rb
@@ -11,6 +11,8 @@
fill_in "Meta title", with: "Example meta title"
fill_in "Meta description", with: "Example meta description"
+ expect(page).to have_css("legend", text: "Product Meta Tag")
+
click_on "Create Product"
expect(page).to have_link(ProductMetaTag.last.id)
@@ -31,4 +33,27 @@
t("administrate.controller.update.success", resource: "Product")
)
end
+
+ describe "has_one relationships" do
+ it "displays translated labels" do
+ custom_label = "Meta Tags"
+ product = create(:product)
+
+ translations = {
+ helpers: {
+ label: {
+ product: {
+ product_meta_tag: custom_label,
+ },
+ },
+ },
+ }
+
+ with_translations(:en, translations) do
+ visit edit_admin_product_path(product)
+
+ expect(page).to have_css("legend", text: custom_label)
+ end
+ end
+ end
end