Skip to content

Commit

Permalink
[thoughtbot#179] Allowing Administrate Namespace class to return Acti…
Browse files Browse the repository at this point in the history
…veRecord/Model classes. This allows one to reference ActiveModel’s route values (route_key, singular_route_key) when generating Polymorphic URLs.
  • Loading branch information
Daniel Rice committed Mar 2, 2017
1 parent 576976a commit 2b1eac7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/administrate/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def resources
end
end

def models
namespace_controller_paths.uniq.map do |controller|
controller.split(/^#{namespace}\//)[1].classify.constantize
end
end

private

attr_reader :namespace
Expand Down
15 changes: 15 additions & 0 deletions spec/administrate/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@
end
end
end

describe "#models" do
it "searches the routes for ActiveRecord models in the namespace" do
begin
namespace = Administrate::Namespace.new(:admin)
Rails.application.routes.draw do
namespace(:admin) { resources :customers }
end

expect(namespace.models).to eq [::Customer]
ensure
reset_routes
end
end
end
end

0 comments on commit 2b1eac7

Please sign in to comment.