Skip to content

Commit

Permalink
Fix error when routing with array containing symbol.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Wesorick committed Oct 15, 2019
1 parent 46c83e2 commit ec33961
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/resource_controller/polymorphic_routes.rb
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions 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

0 comments on commit ec33961

Please sign in to comment.