Skip to content

Commit

Permalink
Fix broken controller node functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Nov 10, 2015
1 parent 9f23ef3 commit 5e92715
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
12 changes: 1 addition & 11 deletions releaf-content/lib/releaf/content/node_mapper.rb
@@ -1,19 +1,9 @@
module Releaf::Content
module NodeMapper
def releaf_routes_for(node_class, controller: default_controller(node_class), &block)
def releaf_routes_for(node_class, controller: Releaf::Content::Route.node_class_default_controller(node_class), &block)
Releaf::Content::Route.for(node_class, controller).each do |route|
Releaf::Content::RouterProxy.new(self, route).draw(&block)
end
end

private

def default_controller(node_class)
if node_class.is_a? ActionController::Base
node_class.name.underscore.sub(/controller$/, '')
else
node_class.name.pluralize.underscore
end
end
end
end
8 changes: 8 additions & 0 deletions releaf-content/lib/releaf/content/route.rb
Expand Up @@ -7,6 +7,14 @@ def self.node_class
::Node
end

def self.node_class_default_controller(node_class)
if node_class <= ActionController::Base
node_class.name.underscore.sub(/_controller$/, '')
else
node_class.name.pluralize.underscore
end
end

# Return node route params which can be used in Rails route options
#
# @param method_or_path [String] string with action and controller for route (Ex. home#index)
Expand Down
14 changes: 14 additions & 0 deletions releaf-content/spec/lib/releaf/content/route_spec.rb
Expand Up @@ -9,6 +9,20 @@
end
end

describe ".node_class_default_controller" do
context "when given node class inherits `ActionController::Base`" do
it "returns undercored, stripped down controller class" do
expect(described_class.node_class_default_controller(HomePagesController)).to eq("home_pages")
end
end

context "when given node class does not inherit `ActionController::Base`" do
it "returns pluralized, underscorized class" do
expect(described_class.node_class_default_controller(TextPage)).to eq("text_pages")
end
end
end

describe ".for" do
before do
create(:home_page_node)
Expand Down

0 comments on commit 5e92715

Please sign in to comment.