2009-12-01 22:19:20 -05:00
|
|
|
require 'isolation/abstract_unit'
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class RoutingTest < Test::Unit::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
2009-12-23 19:14:34 -05:00
|
|
|
boot_rails
|
|
|
|
require 'rack/test'
|
|
|
|
extend Rack::Test::Methods
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def app
|
|
|
|
@app ||= begin
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
Rails.application
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-23 19:26:10 -05:00
|
|
|
test "rails/info/properties" do
|
|
|
|
get "/rails/info/properties"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
test "simple controller" do
|
|
|
|
controller :foo, <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
|
|
|
render :text => "foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-21 18:47:03 -05:00
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
2009-12-21 21:41:25 -05:00
|
|
|
AppTemplate::Application.routes.draw do |map|
|
2009-12-21 18:47:03 -05:00
|
|
|
match ':controller(/:action)'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
get '/foo'
|
|
|
|
assert_equal 'foo', last_response.body
|
|
|
|
end
|
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
test "simple controller with helper" do
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
|
|
|
render :inline => "<%= foo_or_bar? %>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'app/helpers/bar_helper.rb', <<-RUBY
|
|
|
|
module BarHelper
|
|
|
|
def foo_or_bar?
|
|
|
|
"bar"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
|
|
|
AppTemplate::Application.routes.draw do |map|
|
|
|
|
match ':controller(/:action)'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
get '/foo'
|
|
|
|
assert_equal 'bar', last_response.body
|
|
|
|
end
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
test "multiple controllers" do
|
|
|
|
controller :foo, <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
|
|
|
render :text => "foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller :bar, <<-RUBY
|
|
|
|
class BarController < ActionController::Base
|
|
|
|
def index
|
|
|
|
render :text => "bar"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-21 18:47:03 -05:00
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
2009-12-21 21:41:25 -05:00
|
|
|
AppTemplate::Application.routes.draw do |map|
|
2009-12-21 18:47:03 -05:00
|
|
|
match ':controller(/:action)'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
get '/foo'
|
|
|
|
assert_equal 'foo', last_response.body
|
|
|
|
|
|
|
|
get '/bar'
|
|
|
|
assert_equal 'bar', last_response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "nested controller" do
|
|
|
|
controller 'foo', <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
|
|
|
render :text => "foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller 'admin/foo', <<-RUBY
|
|
|
|
module Admin
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
|
|
|
render :text => "admin::foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-21 18:47:03 -05:00
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
2009-12-21 21:41:25 -05:00
|
|
|
AppTemplate::Application.routes.draw do |map|
|
2010-02-28 19:43:20 -05:00
|
|
|
match 'admin/foo', :to => 'admin/foo#index'
|
|
|
|
match 'foo', :to => 'foo#index'
|
2009-12-21 18:47:03 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
get '/foo'
|
|
|
|
assert_equal 'foo', last_response.body
|
|
|
|
|
|
|
|
get '/admin/foo'
|
|
|
|
assert_equal 'admin::foo', last_response.body
|
|
|
|
end
|
2009-12-14 17:51:13 -05:00
|
|
|
|
2009-12-15 11:48:56 -05:00
|
|
|
test "reloads routes when configuration is changed" do
|
|
|
|
controller :foo, <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-15 11:48:56 -05:00
|
|
|
def bar
|
|
|
|
render :text => "bar"
|
|
|
|
end
|
|
|
|
|
|
|
|
def baz
|
|
|
|
render :text => "baz"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
2009-12-21 21:41:25 -05:00
|
|
|
AppTemplate::Application.routes.draw do |map|
|
2009-12-15 11:48:56 -05:00
|
|
|
match 'foo', :to => 'foo#bar'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
get '/foo'
|
|
|
|
assert_equal 'bar', last_response.body
|
|
|
|
|
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
2009-12-21 21:41:25 -05:00
|
|
|
AppTemplate::Application.routes.draw do |map|
|
2009-12-15 11:48:56 -05:00
|
|
|
match 'foo', :to => 'foo#baz'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2009-12-23 20:01:07 -05:00
|
|
|
sleep 0.1
|
|
|
|
|
2009-12-15 11:48:56 -05:00
|
|
|
get '/foo'
|
|
|
|
assert_equal 'baz', last_response.body
|
|
|
|
end
|
2010-01-21 11:30:17 -05:00
|
|
|
|
|
|
|
test 'resource routing with irrigular inflection' do
|
|
|
|
app_file 'config/initializers/inflection.rb', <<-RUBY
|
|
|
|
ActiveSupport::Inflector.inflections do |inflect|
|
|
|
|
inflect.irregular 'yazi', 'yazilar'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file 'config/routes.rb', <<-RUBY
|
|
|
|
AppTemplate::Application.routes.draw do |map|
|
|
|
|
resources :yazilar
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller 'yazilar', <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class YazilarController < ApplicationController
|
2010-01-21 11:30:17 -05:00
|
|
|
def index
|
|
|
|
render :text => 'yazilar#index'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
get '/yazilars'
|
|
|
|
assert_equal 404, last_response.status
|
|
|
|
|
|
|
|
get '/yazilar'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|