aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/assertions.rb13
-rw-r--r--actionpack/test/controller/fake_controllers.rb23
-rw-r--r--actionpack/test/controller/routing_test.rb23
-rw-r--r--actionpack/test/controller/test_test.rb15
5 files changed, 45 insertions, 31 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index a034da7ae9..267f22c3ef 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb
index e04d4ccde0..20650c8654 100644
--- a/actionpack/lib/action_controller/assertions.rb
+++ b/actionpack/lib/action_controller/assertions.rb
@@ -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
diff --git a/actionpack/test/controller/fake_controllers.rb b/actionpack/test/controller/fake_controllers.rb
new file mode 100644
index 0000000000..43f933b0d8
--- /dev/null
+++ b/actionpack/test/controller/fake_controllers.rb
@@ -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
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 23d741a58f..cec1b0313d 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -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
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 201fe03b44..0ebd6bc472 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -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)