Skip to content

Commit 30b19c8

Browse files
committed
Merge pull request activeadmin#1487 from benhutton/1481-complex-page-names
Use complex names for pages activeadmin#1481
2 parents ff62e86 + 6292c0e commit 30b19c8

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

features/registering_pages.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ Feature: Registering Pages
2020
And I should see the Active Admin layout
2121
And I should see the content "I love chocolate."
2222

23+
Scenario: Registering a page with a complex name
24+
Given a configuration of:
25+
"""
26+
ActiveAdmin.register_page "Chocolate I lØve You!" do
27+
content do
28+
"I love chocolate."
29+
end
30+
end
31+
"""
32+
When I go to the dashboard
33+
And I follow "Chocolate I lØve You!"
34+
Then I should see the page title "Chocolate I lØve You!"
35+
And I should see the Active Admin layout
36+
And I should see the content "I love chocolate."
37+
2338
Scenario: Registering an empty page
2439
Given a configuration of:
2540
"""

lib/active_admin/page.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ def resource_name
4444
@resource_name ||= Resource::Name.new(nil, name)
4545
end
4646

47+
def underscored_resource_name
48+
resource_name.parameterize.underscore
49+
end
50+
51+
def camelized_resource_name
52+
underscored_resource_name.camelize
53+
end
54+
4755
def default_menu_options
4856
super.merge(:id => resource_name)
4957
end
5058

5159
def controller_name
52-
[namespace.module_name, resource_name + "Controller"].compact.join('::')
60+
[namespace.module_name, camelized_resource_name + "Controller"].compact.join('::')
5361
end
5462

5563
def belongs_to?

lib/active_admin/router.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def apply(router)
6363
end
6464
when Page
6565

66-
match "/#{config.resource_name.singular}" => "#{config.resource_name.singular}#index"
66+
match "/#{config.underscored_resource_name}" => "#{config.underscored_resource_name}#index"
6767
config.page_actions.each do |action|
68-
match "/#{config.resource_name.singular}/#{action.name}" => "#{config.resource_name.singular}##{action.name}", :via => action.http_verb
68+
match "/#{config.underscored_resource_name}/#{action.name}" => "#{config.underscored_resource_name}##{action.name}", :via => action.http_verb
6969
end
7070
else
7171
raise "Unsupported config class: #{config.class}"

spec/unit/page_spec.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: utf-8
2+
13
require 'spec_helper'
24
require File.expand_path('config_shared_examples', File.dirname(__FILE__))
35

@@ -11,34 +13,46 @@ module ActiveAdmin
1113
let(:namespace){ Namespace.new(application, :admin) }
1214

1315
def config(options = {})
14-
@config ||= namespace.register_page("Status", options)
16+
@config ||= namespace.register_page("Chocolate I lØve You!", options)
1517
end
1618

1719
describe "controller name" do
1820
it "should return a namespaced controller name" do
19-
config.controller_name.should == "Admin::StatusController"
21+
config.controller_name.should == "Admin::ChocolateILoveYouController"
2022
end
2123
context "when non namespaced controller" do
2224
let(:namespace){ ActiveAdmin::Namespace.new(application, :root) }
2325
it "should return a non namespaced controller name" do
24-
config.controller_name.should == "StatusController"
26+
config.controller_name.should == "ChocolateILoveYouController"
2527
end
2628
end
2729
end
2830

2931
describe "#resource_name" do
3032
it "returns the name" do
31-
config.resource_name.should == "Status"
33+
config.resource_name.should == "Chocolate I lØve You!"
3234
end
3335

34-
it "returns the underscored name" do
35-
config.resource_name.singular.should == "status"
36+
it "returns the singular, lowercase name" do
37+
config.resource_name.singular.should == "chocolate i lØve you!"
3638
end
3739
end
3840

3941
describe "#plural_resource_label" do
4042
it "returns the singular name" do
41-
config.plural_resource_label.should == "Status"
43+
config.plural_resource_label.should == "Chocolate I lØve You!"
44+
end
45+
end
46+
47+
describe "#underscored_resource_name" do
48+
it "returns the resource name underscored" do
49+
config.underscored_resource_name.should == "chocolate_i_love_you"
50+
end
51+
end
52+
53+
describe "#camelized_resource_name" do
54+
it "returns the resource name camel case" do
55+
config.camelized_resource_name.should == "ChocolateILoveYou"
4256
end
4357
end
4458

spec/unit/routing_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: utf-8
2+
13
require 'spec_helper'
24

35
describe ActiveAdmin, "Routing", :type => :routing do
@@ -150,20 +152,20 @@
150152
describe "page" do
151153
context "when default namespace" do
152154
before(:each) do
153-
load_resources { ActiveAdmin.register_page("Status") }
155+
load_resources { ActiveAdmin.register_page("Chocolate I lØve You!") }
154156
end
155157

156158
it "should route to the page under /admin" do
157-
admin_status_path.should == "/admin/status"
159+
admin_chocolate_i_love_you_path.should == "/admin/chocolate_i_love_you"
158160
end
159161

160162
context "when in the root namespace" do
161163
before(:each) do
162-
load_resources { ActiveAdmin.register_page("Status", :namespace => false) }
164+
load_resources { ActiveAdmin.register_page("Chocolate I lØve You!", :namespace => false) }
163165
end
164166

165167
it "should route to page under /" do
166-
status_path.should == "/status"
168+
chocolate_i_love_you_path.should == "/chocolate_i_love_you"
167169
end
168170
end
169171

0 commit comments

Comments
 (0)