From 7a42fce219a2e5c7dffdfaa5683a15e7b2fabaec Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Tue, 2 Aug 2016 13:44:38 -0400 Subject: [PATCH] Fix Relationship links for a Middleware Provider The Middleware Provider controller (ems_middleware) does not support RESTful routing yet, therefore the Relationship links should be routed using :controller, :action and :id cherry-picking changes from https://github.com/ManageIQ/manageiq/pull/8866 Fixes #8803 https://bugzilla.redhat.com/show_bug.cgi?id=1361844 --- app/helpers/application_helper.rb | 15 ++++++++++++--- spec/helpers/application_helper_spec.rb | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b40992cc0c5..1594eacf015 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -84,9 +84,18 @@ def multiple_relationship_link(record, table_name) end else out = content_tag(:li) do - link_to("#{plural} (#{count})", - polymorphic_path(@record, :display => table_name.to_s.pluralize), - :title => _("Show %{plural_linked_name}") % {:plural_linked_name => plural}) + if restful_routed?(record) + link_to("#{plural} (#{count})", + polymorphic_path(record, :display => table_name.to_s.pluralize), + :title => _("Show %{plural_linked_name}") % {:plural_linked_name => plural}) + else + link_to("#{plural} (#{count})", + {:controller => controller_name, + :action => 'show', + :id => record.id, + :display => table_name.to_s.pluralize}, + :title => _("Show %{plural_linked_name}") % {:plural_linked_name => plural}) + end end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 243487f070a..9c94c7ac12e 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1701,4 +1701,14 @@ ).to eq('host_services') end end + + describe "#multiple_relationship_link" do + context "When record is a Container Provider" do + it "Uses polymorphic_path for the show action" do + ems = FactoryGirl.create(:ems_kubernetes) + ContainerProject.create(:ext_management_system => ems, :name => "Test Project") + expect(helper.multiple_relationship_link(ems, "container_project")).to eq("
  • Projects (1)
  • ") + end + end + end end