Permalink
Browse files

Allow content_path override for PagesController subclasses

  • Loading branch information...
1 parent d4ba056 commit 8884f70be1bd01e306d1f9ee3f5ad4daa4783095 @mhoran mhoran committed Feb 22, 2012
@@ -4,7 +4,7 @@ class HighVoltage::PagesController < ApplicationController
layout Proc.new { HighVoltage::layout }
rescue_from ActionView::MissingTemplate do |exception|
- if exception.message =~ %r{Missing template #{HighVoltage::content_path}}
+ if exception.message =~ %r{Missing template #{content_path}}
raise ActionController::RoutingError, "No such page: #{params[:id]}"
else
raise exception
@@ -18,12 +18,16 @@ def show
protected
def current_page
- "#{HighVoltage::content_path}#{clean_path}"
+ "#{content_path}#{clean_path}"
end
def clean_path
path = Pathname.new "/#{params[:id]}"
path.cleanpath.to_s[1..-1]
end
+ def content_path
+ HighVoltage::content_path
+ end
+
end
@@ -4,12 +4,12 @@
render_views
- describe "on GET to /subclassed_pages/exists" do
- before { get :show, :id => 'exists' }
+ describe "on GET to /subclassed_pages/also_exists" do
+ before { get :show, :id => 'also_exists' }
it "should respond with success and render template" do
response.should be_success
- response.should render_template('exists')
+ response.should render_template('also_exists')
end
it "should use the custom configured layout" do
@@ -18,6 +18,15 @@
end
end
+ describe "on GET to /subclassed_pages/also_dir/nested" do
+ before { get :show, :id => 'also_dir/also_nested' }
+
+ it "should respond with success and render template" do
+ response.should be_success
+ response.should render_template('other_pages/also_dir/also_nested')
+ end
+ end
+
it "should raise a routing error for an invalid page" do
lambda { get :show, :id => "invalid" }.should raise_error(ActionController::RoutingError)
end
@@ -27,6 +36,6 @@
end
it "should raise missing template error for valid page with invalid partial" do
- lambda { get :show, :id => "exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
+ lambda { get :show, :id => "also_exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
end
end
@@ -1,3 +1,7 @@
class SubclassedPagesController < HighVoltage::PagesController
layout 'alternate'
+
+ def content_path
+ 'other_pages/'
+ end
end

0 comments on commit 8884f70

Please sign in to comment.