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

fix: no link on breadcrumb when visiting from an association #3226

Merged
merged 6 commits into from
Sep 12, 2024
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
11 changes: 9 additions & 2 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ def show

add_breadcrumb via_resource.plural_name, resources_path(resource: via_resource)
add_breadcrumb via_resource.record_title, resource_path(record: via_record, resource: via_resource)

add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end

add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)

add_breadcrumb @resource.record_title
add_breadcrumb I18n.t("avo.details").upcase_first
Expand Down Expand Up @@ -120,9 +123,12 @@ def new

add_breadcrumb via_resource.plural_name, resources_path(resource: via_resource)
add_breadcrumb via_resource.record_title, resource_path(record: via_record, resource: via_resource)

add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end

add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
add_breadcrumb t("avo.new").humanize

set_component_for __method__, fallback_view: :edit
Expand Down Expand Up @@ -440,6 +446,7 @@ def set_edit_title_and_breadcrumbs
via_resource_class: params[:via_resource_class],
via_record_id: params[:via_record_id]
}
add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end
Expand Down
49 changes: 48 additions & 1 deletion spec/features/avo/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.feature "Breadcrumbs", type: :feature do
let!(:project) { create :project }
let!(:project) { create :project, users: [admin] }
let!(:url) { "/admin/resources/projects/#{project.id}/edit" }

before do
Expand Down Expand Up @@ -101,4 +101,51 @@
end
end
end

describe "on associations" do
it "show" do
url = avo.resources_project_path(project, via_record_id: admin, via_resource_class: Avo::Resources::User)
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to_not have_link project.name
expect(breadcrumbs).to have_text project.name
expect(breadcrumbs).to_not have_link "Details"
expect(breadcrumbs).to have_text "Details"
end

it "edit" do
url = avo.edit_resources_project_path(project, via_record_id: admin, via_resource_class: Avo::Resources::User)
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to have_link project.name
expect(breadcrumbs).to_not have_link "Edit"
expect(breadcrumbs).to have_text "Edit"
end

it "new" do
url = avo.new_resources_project_path(via_record_id: admin, via_resource_class: Avo::Resources::User, via_relation: :users, via_relation_class: "User")
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to_not have_link "New"
expect(breadcrumbs).to have_text "New"
end
end
end
Loading