From fde9a768fa1312e82ee2f6c7a75b4e42b824045a Mon Sep 17 00:00:00 2001 From: Jake Wesorick Date: Thu, 10 Oct 2019 12:18:22 -0400 Subject: [PATCH] Fix error when routing with array containing symbol. --- CHANGELOG.md | 3 ++ .../resource_controller/polymorphic_routes.rb | 2 +- .../polymorphic_routes_spec.rb | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 spec/unit/resource_controller/polymorphic_routes_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ec43c14fbc..f5d74636f45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Bug Fixes * Use filter label when condition has a predicate. [#5886] by [@ko-lem] +* Fix error when routing with array containing symbol. [#5870] by [@jwesorick] ### Removals @@ -526,6 +527,7 @@ Please check [0-6-stable] for previous changes. [#5874]: https://github.com/activeadmin/activeadmin/pull/5874 [#5877]: https://github.com/activeadmin/activeadmin/pull/5877 [#5886]: https://github.com/activeadmin/activeadmin/pull/5886 +[#5870]: https://github.com/activeadmin/activeadmin/pull/5870 [@5t111111]: https://github.com/5t111111 [@aarek]: https://github.com/aarek @@ -566,6 +568,7 @@ Please check [0-6-stable] for previous changes. [@johnnyshields]: https://github.com/johnnyshields [@jscheid]: https://github.com/jscheid [@juril33t]: https://github.com/juril33t +[@jwesorick]: https://github.com/jwesorick [@kjeldahl]: https://github.com/kjeldahl [@ko-lem]: https://github.com/ko-lem [@kobeumut]: https://github.com/kobeumut diff --git a/lib/active_admin/resource_controller/polymorphic_routes.rb b/lib/active_admin/resource_controller/polymorphic_routes.rb index e492f8fb5ca..5c1733fc183 100644 --- a/lib/active_admin/resource_controller/polymorphic_routes.rb +++ b/lib/active_admin/resource_controller/polymorphic_routes.rb @@ -25,7 +25,7 @@ def to_named_resource(record) return ActiveAdmin::Model.new(active_admin_config, record) end - if record.is_a?(parent.class) + if respond_to?(:parent, true) && record.is_a?(parent.class) return ActiveAdmin::Model.new(active_admin_config.belongs_to_config.resource, record) end diff --git a/spec/unit/resource_controller/polymorphic_routes_spec.rb b/spec/unit/resource_controller/polymorphic_routes_spec.rb new file mode 100644 index 00000000000..0884df3dfaf --- /dev/null +++ b/spec/unit/resource_controller/polymorphic_routes_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe ActiveAdmin::ResourceController::PolymorphicRoutes, type: :controller do + let(:klass) { Admin::PostsController } + + shared_context 'with post config' do + before do + load_resources { post_config } + + @controller = klass.new + + get :index + end + end + + context 'polymorphic routes' do + include_context 'with post config' do + let(:post_config) { ActiveAdmin.register Post } + let(:post) { Post.create! title: "Hello World" } + end + + %w(polymorphic_url polymorphic_path).each do |method| + describe method do + it 'arrays wtih action names' do + expect(controller.send(method, [:admin, post])).to include("/admin/posts/#{post.id}") + end + end + end + end +end