diff --git a/spec/administrate/views/fields/has_one/_show_spec.rb b/spec/administrate/views/fields/has_one/_show_spec.rb
index 3d728f9f9e..c063103b9b 100644
--- a/spec/administrate/views/fields/has_one/_show_spec.rb
+++ b/spec/administrate/views/fields/has_one/_show_spec.rb
@@ -27,41 +27,9 @@ def view.namespace
end
context "with a persisted record" do
- it "renders a link to the record" do
- field_resource = create(:product_meta_tag)
- path_to_field_resource = polymorphic_path([:admin, field_resource])
-
- nested_show_page_for_has_one = instance_double(
- "Administrate::Page::Show",
- resource: double(
- class: ProductMetaTag,
- ),
- attributes: []
- )
-
- 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,
- )
-
- render(
- partial: "fields/has_one/show",
- locals: {
- field: has_one_field,
- resource_name: "parent_resource",
- },
- )
-
- link = "The Nested Resource"
- expect(rendered.strip).to include(link)
- end
-
- it "uses the correct labels for fields" do
+ before do
field_resource = create(:product_meta_tag)
- path_to_field_resource = polymorphic_path([:admin, field_resource])
+ @path_to_field_resource = polymorphic_path([:admin, field_resource])
nested_simple_field = instance_double(
"Administrate::Field::String",
@@ -81,7 +49,7 @@ def view.namespace
]
)
- has_one_field = instance_double(
+ @has_one_field = instance_double(
"Administrate::Field::HasOne",
display_associated_resource: "The Nested Resource",
data: field_resource,
@@ -90,8 +58,27 @@ def view.namespace
associated_class_name: "NestedHasOne",
)
- page_double = instance_double("Administrate::Page::Show")
+ @page_double = instance_double("Administrate::Page::Show")
+ end
+
+ def render_field
+ render(
+ partial: "fields/has_one/show",
+ locals: {
+ field: @has_one_field,
+ page: @page_double,
+ resource_name: "parent_resource",
+ },
+ )
+ end
+ it "renders a link to the record" do
+ render_field
+ link = "The Nested Resource"
+ expect(rendered.strip).to include(link)
+ end
+
+ it "uses the correct labels for fields" do
I18n.backend.translations(do_init: true)[:en].deep_merge!(
helpers: {
label: {
@@ -102,15 +89,7 @@ def view.namespace
}
)
- render(
- partial: "fields/has_one/show",
- locals: {
- field: has_one_field,
- page: page_double,
- resource_name: "parent_resource",
- },
- )
-
+ render_field
expect(rendered.strip).to include("Just a Simple String")
end
end