Skip to content

Instantly share code, notes, and snippets.

@DEfusion
Created November 10, 2009 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DEfusion/231408 to your computer and use it in GitHub Desktop.
Save DEfusion/231408 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Foo::BarsController do
before(:each) do
@request.host = 'foo.test.host'
end
it "should route" do
params_from(:get, "/bars/1").should == {:controller => "foo/bars", :action => "show", :id => '1'}
# FAILS
# ActionController::RoutingError in 'Foo::BarsController should route'
# No route matches "/bars/1" with {:method=>:get}
end
end
describe Foo::SubBarsController do
before(:each) do
@request.host = 'foo.test.host'
end
it "should route" do
params_from(:get, "/bars/1/sub_bars/1").should == {:controller => "foo/sub_bars", :action => "show", :bar_id => '1', :id => '1'}
# Passes
end
end
describe Foo::MonkeysController do
before(:each) do
@request.host = 'foo.test.host'
end
it "should route" do
params_from(:get, "/monkeys/1").should == {:controller => "foo/monkeys", :action => "show", :id => '1'}
# FAILS
# ActionController::RoutingError in 'Foo::MonkeysController should route'
# No route matches "/monkeys/1" with {:method=>:get}
end
end
# rake routes output
foo_bar_sub_bar GET /bars/:bar_id/sub_bars/:id(.:format) {:controller=>"foo/sub_bars", :action=>"show"}
foo_bar GET /bars/:id(.:format) {:controller=>"foo/bars", :action=>"show"}
foo_monkey GET /monkeys/:id(.:format) {:controller=>"foo/monkeys", :action=>"show"}
map.namespace :foo, :path_prefix => '', :conditions => { :subdomain => 'foo' } do |foo|
foo.resources :bars, :only => :show do |bars|
bars.resources :sub_bars, :only => :show
end
foo.resources :monkeys, :only => :show
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment