Permalink
Browse files

Merge pull request #800 from pcreux/patch-issue-799

Camelcased and underscored names use safe_resource_name. Closes #799.
  • Loading branch information...
2 parents f92c7fe + fab40e8 commit b5b97e1f296d0af95cf44fbb976c9a85f9303b25 @pcreux pcreux committed Jan 22, 2012
@@ -32,11 +32,22 @@ def initialize(namespace, name, options)
include Resource::Naming
# plural_resource_name is singular
+ def resource_name
+ name
+ end
+
+ def safe_resource_name
+ name
+ end
+
+
+ # Force plural to be singular
def plural_resource_name
name
end
- def resource_name
+ # Force plural to be singular
+ def plural_safe_resource_name
name
end
@@ -133,7 +133,7 @@ def csv_builder
# @deprecated
def resource
- @resource_class
+ resource_class
end
ActiveAdmin::Deprecation.deprecate self, :resource,
"ActiveAdmin::Resource#resource is deprecated. Please use #resource_class instead."
@@ -1,14 +1,14 @@
module ActiveAdmin
class Resource
module Naming
- # Returns the name to call this resource such as "Bank Account"
+ # Returns the user facing name. Example: "Bank Account"
def resource_name
@resource_name ||= @options[:as]
@resource_name ||= singular_human_name
- @resource_name ||= resource_class.name.gsub('::',' ')
+ @resource_name ||= safe_resource_name
end
- # Returns the plural version of this resource such as "Bank Accounts"
+ # Returns the plural version of the user facing name. Example: "Bank Accounts"
def plural_resource_name
@plural_resource_name ||= @options[:as].pluralize if @options[:as]
@plural_resource_name ||= plural_human_name
@@ -20,13 +20,22 @@ def resource_key
camelized_resource_name
end
+ def safe_resource_name
+ @safe_resource_name ||= @options[:as]
+ @safe_resource_name ||= resource_class.name.gsub('::',' ')
+ end
+
+ def plural_safe_resource_name
+ safe_resource_name.pluralize
+ end
+
# A camelized safe representation for this resource
def camelized_resource_name
- resource_name.titleize.gsub(' ', '')
+ safe_resource_name.titleize.gsub(' ', '')
end
def plural_camelized_resource_name
- plural_resource_name.titleize.gsub(' ', '')
+ plural_safe_resource_name.titleize.gsub(' ', '')
end
# An underscored safe representation internally for this resource
@@ -39,6 +48,7 @@ def plural_underscored_resource_name
plural_camelized_resource_name.underscore
end
+
private
# @return [String] Titleized human name via ActiveRecord I18n or nil
@@ -29,9 +29,20 @@
expect { config.plural_resource_name }.should_not raise_error
end
+ it "implements #safe_resource_name" do
+ expect { config.safe_resource_name }.should_not raise_error
+ end
+
describe "#camelized_resource_name" do
- it "returns a camelized version of the resource_name" do
- config.should_receive(:resource_name).and_return "My resource"
+ it "returns a camelized version of the safe_resource_name" do
+ config.should_receive(:safe_resource_name).and_return "My resource"
+ config.camelized_resource_name.should == "MyResource"
+ end
+ end
+
+ describe "#plural_camelized_resource_name" do
+ it "returns a camelized version of the plural_safe_resource_name" do
+ config.should_receive(:safe_resource_name).and_return "My resource"
config.camelized_resource_name.should == "MyResource"
end
end
@@ -15,7 +15,7 @@ def config(options = {})
describe "underscored resource name" do
context "when class" do
- it "should be the underscored singular resource name" do
+ it "should be the underscored safe resource name" do
config.underscored_resource_name.should == "category"
end
end

0 comments on commit b5b97e1

Please sign in to comment.