Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass page local when rendering fields #1788

Merged
merged 1 commit into from
Nov 26, 2020
Merged
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/_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,
),
pablobm marked this conversation as resolved.
Show resolved Hide resolved
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: {},
)
pablobm marked this conversation as resolved.
Show resolved Hide resolved

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,
)
pablobm marked this conversation as resolved.
Show resolved Hide resolved

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