Skip to content

Commit

Permalink
Fix Refinery#route_for_model by not calling singularize on an already…
Browse files Browse the repository at this point in the history
… singular route.
  • Loading branch information
parndt committed Jul 25, 2012
1 parent edbd50a commit b5d5183
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/lib/refinery/core.rb
Expand Up @@ -128,7 +128,7 @@ def root
# Refinery.roots(:'refinery/core') => #<Pathname:/Users/Reset/Code/refinerycms/core>
# Refinery.roots("refinery/core") => #<Pathname:/Users/Reset/Code/refinerycms/core>
def roots(extension_name = nil)
return @roots ||= self.extensions.map { |extension| extension.root } if extension_name.nil?
return @roots ||= self.extensions.map(&:root) if extension_name.nil?

extension_name.to_s.camelize.constantize.root
end
Expand Down Expand Up @@ -157,13 +157,17 @@ def route_for_model(klass, options = {})
options = {:plural => false, :admin => true}.merge options

klass = klass.constantize if klass.respond_to?(:constantize)
active_name = ActiveModel::Name.new(klass, (Refinery if klass.parents.include?(Refinery)))
active_name = ActiveModel::Name.new klass, (Refinery if klass.parents.include?(Refinery))

if options[:admin]
# Most of the time this gets rid of 'refinery'
parts = active_name.underscore.split('/').reject{|name| active_name.singular_route_key.exclude?(name)}
parts = active_name.underscore.split('/').reject{|name|
active_name.singular_route_key.exclude?(name)
}

# Get the singular resource_name from the url parts
resource_name = parts.pop
resource_name = options[:plural] ? resource_name.pluralize : resource_name.singularize
resource_name = resource_name.pluralize if options[:plural]

[parts.join("_"), "admin", resource_name, "path"].reject(&:blank?).join "_"
else
Expand Down
9 changes: 9 additions & 0 deletions core/spec/lib/refinery/core_spec.rb
Expand Up @@ -152,6 +152,15 @@ module Refinery::Dummy
end
end

context 'with Refinery::GroupClass' do
module Refinery::GroupClass
end

it "returns admin_group_class_path" do
Refinery.route_for_model(Refinery::GroupClass).should == "admin_group_class_path"
end
end

context 'with Refinery::DummyName' do
module Refinery::DummyName
end
Expand Down

0 comments on commit b5d5183

Please sign in to comment.