From 634cbbca97762c6f50f15a2a0826bf34be97fbad Mon Sep 17 00:00:00 2001 From: Xavier Spriet Date: Mon, 19 Sep 2011 10:11:20 -0400 Subject: [PATCH] Use HighVoltage::content_path for generated routes too --- config/routes.rb | 3 +- spec/routing/routes_spec.rb | 67 +++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 79031a2..17720f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ Rails.application.routes.draw do - match '/pages/*id' => 'high_voltage/pages#show', :as => :page, :format => false + match "/#{HighVoltage::content_path}*id" => 'high_voltage/pages#show', :as => :page, :format => false + end diff --git a/spec/routing/routes_spec.rb b/spec/routing/routes_spec.rb index a3dc3b1..f92035a 100644 --- a/spec/routing/routes_spec.rb +++ b/spec/routing/routes_spec.rb @@ -1,29 +1,62 @@ require 'spec_helper' - describe 'routes' do + context "using default configuration" do - it "should generate normal resource route with id" do - page_path(:id => "one").should == "/pages/one" - end + it "should generate normal resource route with id" do + page_path(:id => "one").should == "/pages/one" + end - it "should generate normal resource route with string" do - page_path("one").should == "/pages/one" - end + it "should generate normal resource route with string" do + page_path("one").should == "/pages/one" + end - it "should generate nested route with string" do - page_path("one/two").should == "/pages/one/two" - end + it "should generate nested route with string" do + page_path("one/two").should == "/pages/one/two" + end - it "should recognize nested route" do - assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one/two" }, "/pages/one/two") - end + it "should recognize nested route" do + assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one/two" }, "/pages/one/two") + end + + it "should recognize normal route" do + assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one" }, "/pages/one") + end - it "should recognize normal route" do - assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one" }, "/pages/one") + it "should recognize normal route with dots" do + assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one.two.three" }, "/pages/one.two.three") + end end - it "should recognize normal route with dots" do - assert_recognizes({ :controller => "high_voltage/pages", :action => "show", :id => "one.two.three" }, "/pages/one.two.three") + context "using a custom content_path" do + + before(:all) do + HighVoltage::content_path = "other_pages/" + Rails.application.reload_routes! + end + + it "should generate normal resource route with id" do + page_path(:id => "one").should == "/other_pages/one" + end + + it "should generate normal resource route with string" do + page_path("one").should == "/other_pages/one" + end + + it "should generate nested route with string" do + page_path("one/two").should == "/other_pages/one/two" + end + + it "should recognize nested route" do + assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one/two"}, "/other_pages/one/two") + end + + it "should recognize normal route" do + assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one"}, "/other_pages/one") + end + + it "should recognize normal route with dots" do + assert_recognizes({:controller => "high_voltage/pages", :action => "show", :id => "one.two.three"}, "/other_pages/one.two.three") + end end end