mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1837 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fixed assert_routing so that testing controllers in modules works as expected [Nicholas Seckar, Rick Olson]
|
||||
|
||||
* Fixed bug with :success/:failure callbacks for the JavaScriptHelper methods #1730 [court3nay/Thomas Fuchs]
|
||||
|
||||
* Added named_route method to RouteSet instances so that RouteSet instance methods do not prevent certain names from being used. [Nicholas Seckar]
|
||||
|
||||
@@ -138,12 +138,7 @@ module Test #:nodoc:
|
||||
# Load routes.rb if it hasn't been loaded.
|
||||
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
|
||||
|
||||
# Assume given controller
|
||||
request = ActionController::TestRequest.new({}, {}, nil)
|
||||
request.path_parameters = (defaults or {}).clone
|
||||
request.path_parameters[:controller] ||= options[:controller]
|
||||
|
||||
generated_path, found_extras = ActionController::Routing::Routes.generate(options, request)
|
||||
generated_path, found_extras = ActionController::Routing::Routes.generate(options, extras)
|
||||
msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
|
||||
assert_block(msg) { found_extras == extras }
|
||||
|
||||
@@ -156,6 +151,12 @@ module Test #:nodoc:
|
||||
# options is same as path, and also that the options recognized from path are same as options
|
||||
def assert_routing(path, options, defaults={}, extras={}, message=nil)
|
||||
assert_recognizes(options, path, extras, message)
|
||||
|
||||
controller, default_controller = options[:controller], defaults[:controller]
|
||||
if controller && controller.include?(?/) && default_controller && default_controller.include?(?/)
|
||||
options[:controller] = "/#{controller}"
|
||||
end
|
||||
|
||||
assert_generates(path, options, defaults, extras, message)
|
||||
end
|
||||
|
||||
|
||||
23
actionpack/test/controller/fake_controllers.rb
Normal file
23
actionpack/test/controller/fake_controllers.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module Object::Controllers
|
||||
def self.const_available?(*args)
|
||||
const_defined?(*args)
|
||||
end
|
||||
|
||||
class ContentController < ActionController::Base
|
||||
end
|
||||
|
||||
module Admin
|
||||
def self.const_available?(*args)
|
||||
const_defined?(*args)
|
||||
end
|
||||
|
||||
class UserController < ActionController::Base
|
||||
end
|
||||
class NewsFeedController < ActionController::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActionController::Routing::Routes.draw do |map|
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
||||
@@ -1,4 +1,5 @@
|
||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
require File.dirname(__FILE__) + '/fake_controllers'
|
||||
require 'test/unit'
|
||||
require 'stringio'
|
||||
|
||||
@@ -94,28 +95,6 @@ class CodeGeneratorTests < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
# XXX Extract to test/controller/fake_controllers.rb
|
||||
module Object::Controllers
|
||||
def self.const_available?(*args)
|
||||
const_defined?(*args)
|
||||
end
|
||||
|
||||
class ContentController
|
||||
end
|
||||
module Admin
|
||||
def self.const_available?(*args)
|
||||
const_defined?(*args)
|
||||
end
|
||||
|
||||
class UserController
|
||||
end
|
||||
|
||||
class NewsFeedController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class RecognitionTests < Test::Unit::TestCase
|
||||
attr_accessor :generator
|
||||
alias :g :generator
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
require File.dirname(__FILE__) + '/fake_controllers'
|
||||
|
||||
class TestTest < Test::Unit::TestCase
|
||||
class TestController < ActionController::Base
|
||||
@@ -52,12 +53,12 @@ HTML
|
||||
|
||||
def test_process_without_flash
|
||||
process :set_flash
|
||||
assert_flash_equal "><", "test"
|
||||
assert_equal '><', flash['test']
|
||||
end
|
||||
|
||||
def test_process_with_flash
|
||||
process :set_flash, nil, nil, { "test" => "value" }
|
||||
assert_flash_equal ">value<", "test"
|
||||
assert_equal '>value<', flash['test']
|
||||
end
|
||||
|
||||
def test_process_with_request_uri_with_no_params
|
||||
@@ -100,10 +101,18 @@ HTML
|
||||
:only => { :tag => "li" } } }
|
||||
end
|
||||
|
||||
def test_assert_routing
|
||||
def test_assert_generates
|
||||
assert_generates 'controller/action/5', :controller => 'controller', :action => 'action', :id => '5'
|
||||
end
|
||||
|
||||
def test_assert_routing
|
||||
assert_routing 'content', :controller => 'content', :action => 'index'
|
||||
end
|
||||
|
||||
def test_assert_routing_in_module
|
||||
assert_routing 'admin/user', :controller => 'admin/user', :action => 'index'
|
||||
end
|
||||
|
||||
def test_params_passing
|
||||
get :test_params, :page => {:name => "Page name", :month => '4', :year => '2004', :day => '6'}
|
||||
parsed_params = eval(@response.body)
|
||||
|
||||
Reference in New Issue
Block a user