Skip to content

Commit

Permalink
Add abstract methods and spec Config::Naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcreux committed Nov 17, 2011
1 parent c2476a7 commit 83cde01
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/active_admin/config/naming.rb
@@ -1,6 +1,18 @@
module ActiveAdmin
class Config
module Naming
def resource_name
raise "Subclasses of Config should implement resource_name"
end

def plural_resource_name
raise "Subclasses of Config should implement plural_resource_name"
end

def underscored_resource_name
raise "Subclasses of Config should implement underscored_resource_name"
end

# A camelized safe representation for this resource
def camelized_resource_name
underscored_resource_name.camelize
Expand Down
28 changes: 27 additions & 1 deletion spec/unit/config_shared_examples.rb
Expand Up @@ -17,8 +17,34 @@
it { respond_to :route_collection_path }
it { respond_to :comments? }
it { respond_to :belongs_to? }
it { respond_to :comments? }
it { respond_to :action_items? }
it { respond_to :sidebar_sections? }

describe "Naming" do
it "implements #resource_name" do
expect { config.resource_name }.should_not raise_error
end

it "implements #plural_resource_name" do
expect { config.plural_resource_name }.should_not raise_error
end

it "implements #underscored_resource_name" do
expect { config.underscored_resource_name }.should_not raise_error
end

describe "#camelized_resource_name" do
it "returns the underscored_resource_name camelized" do
config.should_receive(:underscored_resource_name).and_return "my_resource"
config.camelized_resource_name.should == "MyResource"
end
end

describe "#plural_underscored_resource_name" do
it "returns the plural_resource_name underscored" do
config.should_receive(:plural_resource_name).and_return "My Resources"
config.plural_underscored_resource_name.should == "my_resources"
end
end
end
end

0 comments on commit 83cde01

Please sign in to comment.