Skip to content

Commit

Permalink
Pass page local when rendering field, as has_one's rely on page exist…
Browse files Browse the repository at this point in the history
…ing (#1788)
  • Loading branch information
bobcats authored Nov 26, 2020
1 parent 0f8624c commit f27396b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/views/fields/has_one/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ All show page attributes of has_one relationship would be rendered
) %>
</dt>
<dd class="attribute-data attribute-data--<%= attribute.html_class %>">
<%= render_field attribute %>
<%= render_field attribute, { page: page } %>
</dd>
</div>
<% end -%>
Expand Down
53 changes: 50 additions & 3 deletions spec/administrate/views/fields/has_one/_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
it "renders a link to the record" do
product = create(:product)
product_path = polymorphic_path([:admin, product])
nested_show = instance_double(
"Administrate::Page::Show",
resource: double(
class: ProductMetaTag,
),
attributes: [],
resource_name: "Product Tag",
)
has_one = instance_double(
"Administrate::Field::HasOne",
display_associated_resource: product.name,
Expand All @@ -43,15 +51,54 @@
expect(rendered.strip).to include(link)
end

def nested_show
instance_double(
it "renders nested attribute relationships" do
template.extend Administrate::ApplicationHelper

product = create(:product)
page = create(:page, product: product)

nested_has_many = instance_double(
"Administrate::Field::HasMany",
associated_collection: [page],
attribute: :page,
data: [page],
resources: [page],
html_class: "has-many",
name: "Page",
to_partial_path: "fields/has_many/index",
order_from_params: {},
)

nested_show = instance_double(
"Administrate::Page::Show",
resource: double(
class: ProductMetaTag,
),
attributes: [],
attributes: [nested_has_many],
resource_name: "Product Tag",
)

has_one = instance_double(
"Administrate::Field::HasOne",
display_associated_resource: product.name,
data: product,
nested_show: nested_show,
)

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

render(
partial: "fields/has_one/show.html.erb",
locals: {
field: has_one,
namespace: "admin",
page: page_double,
resource_name: "product_meta_tag",
},
)

has_many_count = "1 page"
expect(rendered.strip).to include(has_many_count)
end
end
end

0 comments on commit f27396b

Please sign in to comment.