aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract/url_for_test.rb272
-rw-r--r--actionpack/test/abstract_unit.rb8
-rw-r--r--actionpack/test/active_record_unit.rb1
-rw-r--r--actionpack/test/activerecord/controller_runtime_test.rb7
-rw-r--r--actionpack/test/activerecord/polymorphic_routes_test.rb2
-rw-r--r--actionpack/test/controller/base_test.rb88
-rw-r--r--actionpack/test/controller/caching_test.rb16
-rw-r--r--actionpack/test/controller/logging_test.rb3
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb283
-rw-r--r--actionpack/test/dispatch/routing_test.rb31
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb23
-rw-r--r--actionpack/test/dispatch/string_coercion_test.rb40
-rw-r--r--actionpack/test/template/active_model_helper_i18n_test.rb12
-rw-r--r--actionpack/test/template/form_helper_test.rb4
-rw-r--r--actionpack/test/template/form_options_helper_i18n_test.rb6
-rw-r--r--actionpack/test/template/text_helper_test.rb14
16 files changed, 410 insertions, 400 deletions
diff --git a/actionpack/test/abstract/url_for_test.rb b/actionpack/test/abstract/url_for_test.rb
new file mode 100644
index 0000000000..e5570349b8
--- /dev/null
+++ b/actionpack/test/abstract/url_for_test.rb
@@ -0,0 +1,272 @@
+require 'abstract_unit'
+
+module AbstractController
+ module Testing
+
+ class UrlForTests < ActionController::TestCase
+ class W
+ include AbstractController::UrlFor
+ end
+
+ def teardown
+ W.default_url_options.clear
+ end
+
+ def add_host!
+ W.default_url_options[:host] = 'www.basecamphq.com'
+ end
+
+ def test_exception_is_thrown_without_host
+ assert_raise RuntimeError do
+ W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
+ end
+ end
+
+ def test_anchor
+ assert_equal('/c/a#anchor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor')
+ )
+ end
+
+ def test_anchor_should_call_to_param
+ assert_equal('/c/a#anchor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anchor'))
+ )
+ end
+
+ def test_anchor_should_be_cgi_escaped
+ assert_equal('/c/a#anc%2Fhor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anc/hor'))
+ )
+ end
+
+ def test_default_host
+ add_host!
+ assert_equal('http://www.basecamphq.com/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i')
+ )
+ end
+
+ def test_host_may_be_overridden
+ add_host!
+ assert_equal('http://37signals.basecamphq.com/c/a/i',
+ W.new.url_for(:host => '37signals.basecamphq.com', :controller => 'c', :action => 'a', :id => 'i')
+ )
+ end
+
+ def test_port
+ add_host!
+ assert_equal('http://www.basecamphq.com:3000/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :port => 3000)
+ )
+ end
+
+ def test_protocol
+ add_host!
+ assert_equal('https://www.basecamphq.com/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
+ )
+ end
+
+ def test_protocol_with_and_without_separator
+ add_host!
+ assert_equal('https://www.basecamphq.com/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
+ )
+ assert_equal('https://www.basecamphq.com/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://')
+ )
+ end
+
+ def test_trailing_slash
+ add_host!
+ options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'}
+ assert_equal('http://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
+ end
+
+ def test_trailing_slash_with_protocol
+ add_host!
+ options = { :trailing_slash => true,:protocol => 'https', :controller => 'foo', :action => 'bar', :id => '33'}
+ assert_equal('https://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
+ assert_equal 'https://www.basecamphq.com/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string'}))
+ end
+
+ def test_trailing_slash_with_only_path
+ options = {:controller => 'foo', :trailing_slash => true}
+ assert_equal '/foo/', W.new.url_for(options.merge({:only_path => true}))
+ options.update({:action => 'bar', :id => '33'})
+ assert_equal '/foo/bar/33/', W.new.url_for(options.merge({:only_path => true}))
+ assert_equal '/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string',:only_path => true}))
+ end
+
+ def test_trailing_slash_with_anchor
+ options = {:trailing_slash => true, :controller => 'foo', :action => 'bar', :id => '33', :only_path => true, :anchor=> 'chapter7'}
+ assert_equal '/foo/bar/33/#chapter7', W.new.url_for(options)
+ assert_equal '/foo/bar/33/?query=string#chapter7', W.new.url_for(options.merge({:query => 'string'}))
+ end
+
+ def test_trailing_slash_with_params
+ url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => 'cont', :action => 'act', :p1 => 'cafe', :p2 => 'link')
+ params = extract_params(url)
+ assert_equal params[0], { :p1 => 'cafe' }.to_query
+ assert_equal params[1], { :p2 => 'link' }.to_query
+ end
+
+ def test_relative_url_root_is_respected
+ orig_relative_url_root = ActionController::Base.relative_url_root
+ ActionController::Base.relative_url_root = '/subdir'
+
+ add_host!
+ assert_equal('https://www.basecamphq.com/subdir/c/a/i',
+ W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
+ )
+ ensure
+ ActionController::Base.relative_url_root = orig_relative_url_root
+ end
+
+ def test_named_routes
+ with_routing do |set|
+ set.draw do |map|
+ match 'this/is/verbose', :to => 'home#index', :as => :no_args
+ match 'home/sweet/home/:user', :to => 'home#index', :as => :home
+ end
+
+ # We need to create a new class in order to install the new named route.
+ kls = Class.new { include AbstractController::UrlFor }
+ controller = kls.new
+ assert controller.respond_to?(:home_url)
+ assert_equal 'http://www.basecamphq.com/home/sweet/home/again',
+ controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
+
+ assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
+ assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
+ assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
+ end
+ end
+
+ def test_relative_url_root_is_respected_for_named_routes
+ orig_relative_url_root = ActionController::Base.relative_url_root
+ ActionController::Base.relative_url_root = '/subdir'
+
+ with_routing do |set|
+ set.draw do |map|
+ match '/home/sweet/home/:user', :to => 'home#index', :as => :home
+ end
+
+ kls = Class.new { include AbstractController::UrlFor }
+ controller = kls.new
+
+ assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
+ controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
+ end
+ ensure
+ ActionController::Base.relative_url_root = orig_relative_url_root
+ end
+
+ def test_only_path
+ with_routing do |set|
+ set.draw do |map|
+ match 'home/sweet/home/:user', :to => 'home#index', :as => :home
+ match ':controller/:action/:id'
+ end
+
+ # We need to create a new class in order to install the new named route.
+ kls = Class.new { include AbstractController::UrlFor }
+ controller = kls.new
+ assert controller.respond_to?(:home_url)
+ assert_equal '/brave/new/world',
+ controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true)
+
+ assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
+ assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
+ end
+ end
+
+ def test_one_parameter
+ assert_equal('/c/a?param=val',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :param => 'val')
+ )
+ end
+
+ def test_two_parameters
+ url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :p1 => 'X1', :p2 => 'Y2')
+ params = extract_params(url)
+ assert_equal params[0], { :p1 => 'X1' }.to_query
+ assert_equal params[1], { :p2 => 'Y2' }.to_query
+ end
+
+ def test_hash_parameter
+ url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:name => 'Bob', :category => 'prof'})
+ params = extract_params(url)
+ assert_equal params[0], { 'query[category]' => 'prof' }.to_query
+ assert_equal params[1], { 'query[name]' => 'Bob' }.to_query
+ end
+
+ def test_array_parameter
+ url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => ['Bob', 'prof'])
+ params = extract_params(url)
+ assert_equal params[0], { 'query[]' => 'Bob' }.to_query
+ assert_equal params[1], { 'query[]' => 'prof' }.to_query
+ end
+
+ def test_hash_recursive_parameters
+ url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:person => {:name => 'Bob', :position => 'prof'}, :hobby => 'piercing'})
+ params = extract_params(url)
+ assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
+ assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
+ assert_equal params[2], { 'query[person][position]' => 'prof' }.to_query
+ end
+
+ def test_hash_recursive_and_array_parameters
+ url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
+ assert_match %r(^/c/a/101), url
+ params = extract_params(url)
+ assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
+ assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
+ assert_equal params[2], { 'query[person][position][]' => 'art director' }.to_query
+ assert_equal params[3], { 'query[person][position][]' => 'prof' }.to_query
+ end
+
+ def test_path_generation_for_symbol_parameter_keys
+ assert_generates("/image", :controller=> :image)
+ end
+
+ def test_named_routes_with_nil_keys
+ with_routing do |set|
+ set.draw do |map|
+ match 'posts.:format', :to => 'posts#index', :as => :posts
+ match '/', :to => 'posts#index', :as => :main
+ end
+
+ # We need to create a new class in order to install the new named route.
+ kls = Class.new { include AbstractController::UrlFor }
+ kls.default_url_options[:host] = 'www.basecamphq.com'
+
+ controller = kls.new
+ params = {:action => :index, :controller => :posts, :format => :xml}
+ assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
+ params[:format] = nil
+ assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
+ end
+ end
+
+ def test_multiple_includes_maintain_distinct_options
+ first_class = Class.new { include AbstractController::UrlFor }
+ second_class = Class.new { include AbstractController::UrlFor }
+
+ first_host, second_host = 'firsthost.com', 'secondhost.com'
+
+ first_class.default_url_options[:host] = first_host
+ second_class.default_url_options[:host] = second_host
+
+ assert_equal first_class.default_url_options[:host], first_host
+ assert_equal second_class.default_url_options[:host], second_host
+ end
+
+ private
+ def extract_params(url)
+ url.split('?', 2).last.split('&').sort
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 8c65087898..3f7a5c89b9 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -19,8 +19,6 @@ require 'action_view'
require 'action_view/base'
require 'action_dispatch'
require 'fixture_template'
-require 'active_support/test_case'
-require 'action_view/test_case'
require 'active_support/dependencies'
activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)
@@ -96,7 +94,6 @@ class ActiveSupport::TestCase
end
class MockLogger
- attr_reader :logged
attr_accessor :level
def initialize
@@ -108,12 +105,15 @@ class MockLogger
@logged << args.first
@logged << blk.call if block_given?
end
+
+ def logged
+ @logged.compact.map { |l| l.to_s.strip }
+ end
end
class ActionController::IntegrationTest < ActiveSupport::TestCase
def self.build_app(routes = nil)
ActionDispatch::MiddlewareStack.new { |middleware|
- middleware.use "ActionDispatch::StringCoercion"
middleware.use "ActionDispatch::ShowExceptions"
middleware.use "ActionDispatch::Callbacks"
middleware.use "ActionDispatch::ParamsParser"
diff --git a/actionpack/test/active_record_unit.rb b/actionpack/test/active_record_unit.rb
index 9a094cf66b..4f2b052720 100644
--- a/actionpack/test/active_record_unit.rb
+++ b/actionpack/test/active_record_unit.rb
@@ -17,7 +17,6 @@ unless defined?(ActiveRecord) && defined?(Fixtures)
raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
$LOAD_PATH.unshift PATH_TO_AR
require 'active_record'
- require 'active_record/fixtures'
rescue LoadError => e
$stderr.print "Failed to load Active Record. Skipping Active Record assertion tests: #{e}"
ActiveRecordTestConnector.able_to_connect = false
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb
index 0f534da14b..9525dd8307 100644
--- a/actionpack/test/activerecord/controller_runtime_test.rb
+++ b/actionpack/test/activerecord/controller_runtime_test.rb
@@ -23,9 +23,11 @@ class ARLoggingTest < ActionController::TestCase
end
def test_log_with_active_record
+ # Wait pending notifications to be published
+ wait
get :show
wait
- assert_match /ActiveRecord runtime/, logs[3]
+ assert_match /ActiveRecord runtime/, @controller.logger.logged[3]
end
private
@@ -33,7 +35,4 @@ class ARLoggingTest < ActionController::TestCase
@controller.logger = MockLogger.new
end
- def logs
- @logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip}
- end
end
diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb
index ad744421db..ea82758cf5 100644
--- a/actionpack/test/activerecord/polymorphic_routes_test.rb
+++ b/actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -26,7 +26,7 @@ class Series < ActiveRecord::Base
end
class PolymorphicRoutesTest < ActionController::TestCase
- include ActionController::UrlWriter
+ include ActionController::UrlFor
self.default_url_options[:host] = 'example.com'
def setup
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 65118f9bc9..1510a6a7e0 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -6,6 +6,7 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up
module Submodule
class ContainedEmptyController < ActionController::Base
end
+
class ContainedNonEmptyController < ActionController::Base
def public_action
render :nothing => true
@@ -20,12 +21,15 @@ module Submodule
end
hide_action :another_hidden_action
end
+
class SubclassedController < ContainedNonEmptyController
hide_action :public_action # Hiding it here should not affect the superclass.
end
end
+
class EmptyController < ActionController::Base
end
+
class NonEmptyController < ActionController::Base
def public_action
render :nothing => true
@@ -37,7 +41,6 @@ class NonEmptyController < ActionController::Base
end
class MethodMissingController < ActionController::Base
-
hide_action :shouldnt_be_called
def shouldnt_be_called
raise "NO WAY!"
@@ -48,16 +51,15 @@ protected
def method_missing(selector)
render :text => selector.to_s
end
-
end
class DefaultUrlOptionsController < ActionController::Base
- def default_url_options_action
- render :nothing => true
+ def from_view
+ render :inline => "<%= #{params[:route]} %>"
end
def default_url_options(options = nil)
- { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
+ { :host => 'www.override.com', :action => 'new', :locale => 'en' }
end
end
@@ -68,6 +70,7 @@ class ControllerClassTests < Test::Unit::TestCase
assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
end
+
def test_controller_name
assert_equal 'empty', EmptyController.controller_name
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
@@ -86,41 +89,16 @@ class ControllerInstanceTests < Test::Unit::TestCase
def test_action_methods
@empty_controllers.each do |c|
- hide_mocha_methods_from_controller(c)
assert_equal Set.new, c.class.__send__(:action_methods), "#{c.controller_path} should be empty!"
end
+
@non_empty_controllers.each do |c|
- hide_mocha_methods_from_controller(c)
assert_equal Set.new(%w(public_action)), c.class.__send__(:action_methods), "#{c.controller_path} should not be empty!"
end
end
-
- protected
- # Mocha adds some public instance methods to Object that would be
- # considered actions, so explicitly hide_action them.
- def hide_mocha_methods_from_controller(controller)
- mocha_methods = [
- :expects, :mocha, :mocha_inspect, :reset_mocha, :stubba_object,
- :stubba_method, :stubs, :verify, :__metaclass__, :__is_a__, :to_matcher,
- ]
- controller.class.__send__(:hide_action, *mocha_methods)
- end
end
-
class PerformActionTest < ActionController::TestCase
- class MockLogger
- attr_reader :logged
-
- def initialize
- @logged = []
- end
-
- def method_missing(method, *args)
- @logged << args.first.to_s
- end
- end
-
def use_controller(controller_class)
@controller = controller_class.new
@@ -128,9 +106,8 @@ class PerformActionTest < ActionController::TestCase
# a more accurate simulation of what happens in "real life".
@controller.logger = Logger.new(nil)
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
@request.host = "www.nextangle.com"
rescue_action_in_public!
@@ -145,8 +122,7 @@ class PerformActionTest < ActionController::TestCase
def test_method_missing_is_not_an_action_name
use_controller MethodMissingController
-
- assert ! @controller.__send__(:action_method?, 'method_missing')
+ assert !@controller.__send__(:action_method?, 'method_missing')
get :method_missing
assert_response :success
@@ -172,16 +148,43 @@ class DefaultUrlOptionsTest < ActionController::TestCase
def test_default_url_options_are_used_if_set
with_routing do |set|
set.draw do |map|
- match 'default_url_options', :to => 'default_url_options#default_url_options_action', :as => :default_url_options
+ match 'from_view', :to => 'default_url_options#from_view', :as => :from_view
match ':controller/:action'
end
- get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
+ get :from_view, :route => "from_view_url"
- assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
- assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
+ assert_equal 'http://www.override.com/from_view?locale=en', @response.body
+ assert_equal 'http://www.override.com/from_view?locale=en', @controller.send(:from_view_url)
+ assert_equal 'http://www.override.com/default_url_options/new?locale=en', @controller.url_for(:controller => 'default_url_options')
end
end
+
+ def test_default_url_options_are_used_in_non_positional_parameters
+ with_routing do |set|
+ set.draw do |map|
+ scope("/:locale") do
+ resources :descriptions
+ end
+ match ':controller/:action'
+ end
+
+ get :from_view, :route => "description_path(1)"
+
+ assert_equal '/en/descriptions/1', @response.body
+ assert_equal '/en/descriptions', @controller.send(:descriptions_path)
+ assert_equal '/pl/descriptions', @controller.send(:descriptions_path, "pl")
+ assert_equal '/pl/descriptions', @controller.send(:descriptions_path, :locale => "pl")
+ assert_equal '/pl/descriptions.xml', @controller.send(:descriptions_path, "pl", "xml")
+ assert_equal '/en/descriptions.xml', @controller.send(:descriptions_path, :format => "xml")
+ assert_equal '/en/descriptions/1', @controller.send(:description_path, 1)
+ assert_equal '/pl/descriptions/1', @controller.send(:description_path, "pl", 1)
+ assert_equal '/pl/descriptions/1', @controller.send(:description_path, 1, :locale => "pl")
+ assert_equal '/pl/descriptions/1.xml', @controller.send(:description_path, "pl", 1, "xml")
+ assert_equal '/en/descriptions/1.xml', @controller.send(:description_path, 1, :format => "xml")
+ end
+ end
+
end
class EmptyUrlOptionsTest < ActionController::TestCase
@@ -197,15 +200,12 @@ class EmptyUrlOptionsTest < ActionController::TestCase
get :public_action
assert_equal "http://www.example.com/non_empty/public_action", @controller.url_for
end
-end
-class EnsureNamedRoutesWorksTicket22BugTest < ActionController::TestCase
- def test_named_routes_still_work
+ def test_named_routes_with_path_without_doing_a_request_first
with_routing do |set|
set.draw do |map|
resources :things
end
- EmptyController.send :include, ActionController::UrlWriter
assert_equal '/things', EmptyController.new.send(:things_path)
end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 679eaf7b38..5a8dc0c358 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -630,17 +630,17 @@ class FragmentCachingTest < ActionController::TestCase
end
def test_fragment_for_logging
- fragment_computed = false
- events = []
- ActiveSupport::Notifications.subscribe { |*args| events << args }
+ # Wait pending notifications to be published
+ ActiveSupport::Notifications.notifier.wait
+ @controller.logger = MockLogger.new
- buffer = 'generated till now -> '
- @controller.fragment_for(buffer, 'expensive') { fragment_computed = true }
+ fragment_computed = false
+ @controller.fragment_for('buffer', 'expensive') { fragment_computed = true }
+ ActiveSupport::Notifications.notifier.wait
assert fragment_computed
- assert_equal 'generated till now -> ', buffer
- ActiveSupport::Notifications.notifier.wait
- assert_equal [:exist_fragment?, :write_fragment], events.map(&:first)
+ assert_match /Exist fragment\? "views\/expensive"/, @controller.logger.logged[0]
+ assert_match /Write fragment "views\/expensive"/, @controller.logger.logged[1]
end
end
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 4206dffa7e..594cf17312 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -19,6 +19,7 @@ class LoggingTest < ActionController::TestCase
def setup
super
+ wait # Wait pending notifications to be published
set_logger
end
@@ -75,6 +76,6 @@ class LoggingTest < ActionController::TestCase
end
def logs
- @logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip}
+ @logs ||= @controller.logger.logged
end
end
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index 428f40b9f8..c2b8cd85d8 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -100,286 +100,3 @@ class UrlRewriterTests < ActionController::TestCase
end
end
-class UrlWriterTests < ActionController::TestCase
- class W
- include ActionController::UrlWriter
- end
-
- def teardown
- W.default_url_options.clear
- end
-
- def add_host!
- W.default_url_options[:host] = 'www.basecamphq.com'
- end
-
- def test_exception_is_thrown_without_host
- assert_raise RuntimeError do
- W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
- end
- end
-
- def test_anchor
- assert_equal('/c/a#anchor',
- W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor')
- )
- end
-
- def test_anchor_should_call_to_param
- assert_equal('/c/a#anchor',
- W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anchor'))
- )
- end
-
- def test_anchor_should_be_cgi_escaped
- assert_equal('/c/a#anc%2Fhor',
- W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anc/hor'))
- )
- end
-
- def test_default_host
- add_host!
- assert_equal('http://www.basecamphq.com/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i')
- )
- end
-
- def test_host_may_be_overridden
- add_host!
- assert_equal('http://37signals.basecamphq.com/c/a/i',
- W.new.url_for(:host => '37signals.basecamphq.com', :controller => 'c', :action => 'a', :id => 'i')
- )
- end
-
- def test_port
- add_host!
- assert_equal('http://www.basecamphq.com:3000/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :port => 3000)
- )
- end
-
- def test_protocol
- add_host!
- assert_equal('https://www.basecamphq.com/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
- )
- end
-
- def test_protocol_with_and_without_separator
- add_host!
- assert_equal('https://www.basecamphq.com/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
- )
- assert_equal('https://www.basecamphq.com/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://')
- )
- end
-
- def test_trailing_slash
- add_host!
- options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'}
- assert_equal('http://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
- end
-
- def test_trailing_slash_with_protocol
- add_host!
- options = { :trailing_slash => true,:protocol => 'https', :controller => 'foo', :action => 'bar', :id => '33'}
- assert_equal('https://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
- assert_equal 'https://www.basecamphq.com/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string'}))
- end
-
- def test_trailing_slash_with_only_path
- options = {:controller => 'foo', :trailing_slash => true}
- assert_equal '/foo/', W.new.url_for(options.merge({:only_path => true}))
- options.update({:action => 'bar', :id => '33'})
- assert_equal '/foo/bar/33/', W.new.url_for(options.merge({:only_path => true}))
- assert_equal '/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string',:only_path => true}))
- end
-
- def test_trailing_slash_with_anchor
- options = {:trailing_slash => true, :controller => 'foo', :action => 'bar', :id => '33', :only_path => true, :anchor=> 'chapter7'}
- assert_equal '/foo/bar/33/#chapter7', W.new.url_for(options)
- assert_equal '/foo/bar/33/?query=string#chapter7', W.new.url_for(options.merge({:query => 'string'}))
- end
-
- def test_trailing_slash_with_params
- url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => 'cont', :action => 'act', :p1 => 'cafe', :p2 => 'link')
- params = extract_params(url)
- assert_equal params[0], { :p1 => 'cafe' }.to_query
- assert_equal params[1], { :p2 => 'link' }.to_query
- end
-
- def test_relative_url_root_is_respected
- orig_relative_url_root = ActionController::Base.relative_url_root
- ActionController::Base.relative_url_root = '/subdir'
-
- add_host!
- assert_equal('https://www.basecamphq.com/subdir/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
- )
- ensure
- ActionController::Base.relative_url_root = orig_relative_url_root
- end
-
- def test_named_routes
- with_routing do |set|
- set.draw do |map|
- match 'this/is/verbose', :to => 'home#index', :as => :no_args
- match 'home/sweet/home/:user', :to => 'home#index', :as => :home
- end
-
- # We need to create a new class in order to install the new named route.
- kls = Class.new { include ActionController::UrlWriter }
- controller = kls.new
- assert controller.respond_to?(:home_url)
- assert_equal 'http://www.basecamphq.com/home/sweet/home/again',
- controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
-
- assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused'))
- assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com'))
- assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com'))
- end
- end
-
- def test_relative_url_root_is_respected_for_named_routes
- orig_relative_url_root = ActionController::Base.relative_url_root
- ActionController::Base.relative_url_root = '/subdir'
-
- with_routing do |set|
- set.draw do |map|
- match '/home/sweet/home/:user', :to => 'home#index', :as => :home
- end
-
- kls = Class.new { include ActionController::UrlWriter }
- controller = kls.new
-
- assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again',
- controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
- end
- ensure
- ActionController::Base.relative_url_root = orig_relative_url_root
- end
-
- def test_only_path
- with_routing do |set|
- set.draw do |map|
- match 'home/sweet/home/:user', :to => 'home#index', :as => :home
- match ':controller/:action/:id'
- end
-
- # We need to create a new class in order to install the new named route.
- kls = Class.new { include ActionController::UrlWriter }
- controller = kls.new
- assert controller.respond_to?(:home_url)
- assert_equal '/brave/new/world',
- controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true)
-
- assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
- assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
- end
- end
-
- def test_one_parameter
- assert_equal('/c/a?param=val',
- W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :param => 'val')
- )
- end
-
- def test_two_parameters
- url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :p1 => 'X1', :p2 => 'Y2')
- params = extract_params(url)
- assert_equal params[0], { :p1 => 'X1' }.to_query
- assert_equal params[1], { :p2 => 'Y2' }.to_query
- end
-
- def test_hash_parameter
- url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:name => 'Bob', :category => 'prof'})
- params = extract_params(url)
- assert_equal params[0], { 'query[category]' => 'prof' }.to_query
- assert_equal params[1], { 'query[name]' => 'Bob' }.to_query
- end
-
- def test_array_parameter
- url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => ['Bob', 'prof'])
- params = extract_params(url)
- assert_equal params[0], { 'query[]' => 'Bob' }.to_query
- assert_equal params[1], { 'query[]' => 'prof' }.to_query
- end
-
- def test_hash_recursive_parameters
- url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :query => {:person => {:name => 'Bob', :position => 'prof'}, :hobby => 'piercing'})
- params = extract_params(url)
- assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
- assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
- assert_equal params[2], { 'query[person][position]' => 'prof' }.to_query
- end
-
- def test_hash_recursive_and_array_parameters
- url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'})
- assert_match %r(^/c/a/101), url
- params = extract_params(url)
- assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query
- assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query
- assert_equal params[2], { 'query[person][position][]' => 'art director' }.to_query
- assert_equal params[3], { 'query[person][position][]' => 'prof' }.to_query
- end
-
- def test_path_generation_for_symbol_parameter_keys
- assert_generates("/image", :controller=> :image)
- end
-
- def test_named_routes_with_nil_keys
- with_routing do |set|
- set.draw do |map|
- match 'posts.:format', :to => 'posts#index', :as => :posts
- match '/', :to => 'posts#index', :as => :main
- end
-
- # We need to create a new class in order to install the new named route.
- kls = Class.new { include ActionController::UrlWriter }
- kls.default_url_options[:host] = 'www.basecamphq.com'
-
- controller = kls.new
- params = {:action => :index, :controller => :posts, :format => :xml}
- assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
- params[:format] = nil
- assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
- end
- end
-
- def test_formatted_url_methods_are_deprecated
- with_routing do |set|
- set.draw do |map|
- resources :posts
- end
- # We need to create a new class in order to install the new named route.
- kls = Class.new { include ActionController::UrlWriter }
- controller = kls.new
- params = {:id => 1, :format => :xml}
- assert_deprecated do
- assert_equal("/posts/1.xml", controller.send(:formatted_post_path, params))
- end
- assert_deprecated do
- assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml))
- end
- end
- end
-
- def test_multiple_includes_maintain_distinct_options
- first_class = Class.new { include ActionController::UrlWriter }
- second_class = Class.new { include ActionController::UrlWriter }
-
- first_host, second_host = 'firsthost.com', 'secondhost.com'
-
- first_class.default_url_options[:host] = first_host
- second_class.default_url_options[:host] = second_host
-
- assert_equal first_class.default_url_options[:host], first_host
- assert_equal second_class.default_url_options[:host], second_host
- end
-
- private
- def extract_params(url)
- url.split('?', 2).last.split('&').sort
- end
-end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index c4b0b9cdbf..32e2717789 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -29,6 +29,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match 'account/modulo/:name', :to => redirect("/%{name}s")
match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" }
+ match 'account/google' => redirect('http://www.google.com/')
match 'openid/login', :via => [:get, :post], :to => "openid#login"
@@ -65,7 +66,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
resources :people do
nested do
- namespace ":access_token" do
+ scope "/:access_token" do
resource :avatar
end
end
@@ -432,12 +433,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
with_test_routes do
get '/account/subscription'
assert_equal 'subscriptions#show', @response.body
+ assert_equal '/account/subscription', account_subscription_path
get '/account/credit'
assert_equal 'credits#show', @response.body
+ assert_equal '/account/credit', account_credit_path
get '/account/credit_card'
assert_equal 'credit_cards#show', @response.body
+ assert_equal '/account/credit_card', account_credit_card_path
end
end
@@ -472,7 +476,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'projects#index', @response.body
end
end
-
+
def test_index
with_test_routes do
assert_equal '/info', info_path
@@ -488,7 +492,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'projects#info', @response.body
end
end
-
+
def test_convention_match_with_no_scope
with_test_routes do
assert_equal '/account/overview', account_overview_path
@@ -497,6 +501,27 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_redirect_with_complete_url
+ with_test_routes do
+ get '/account/google'
+ assert_equal 301, @response.status
+ assert_equal 'http://www.google.com/', @response.headers['Location']
+ assert_equal 'Moved Permanently', @response.body
+ end
+ end
+
+ def test_redirect_with_port
+ previous_host, self.host = self.host, 'www.example.com:3000'
+ with_test_routes do
+ get '/account/login'
+ assert_equal 301, @response.status
+ assert_equal 'http://www.example.com:3000/login', @response.headers['Location']
+ assert_equal 'Moved Permanently', @response.body
+ end
+ ensure
+ self.host = previous_host
+ end
+
private
def with_test_routes
real_routes, temp_routes = ActionController::Routing::Routes, Routes
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index 9f6a93756c..951fb4a22e 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -104,4 +104,27 @@ class ShowExceptionsTest < ActionController::IntegrationTest
assert_response 405
assert_match /ActionController::MethodNotAllowed/, body
end
+
+ test "publishes notifications" do
+ # Wait pending notifications to be published
+ ActiveSupport::Notifications.notifier.wait
+
+ @app, event = ProductionApp, nil
+ self.remote_addr = '127.0.0.1'
+
+ ActiveSupport::Notifications.subscribe('action_dispatch.show_exception') do |*args|
+ event = args
+ end
+
+ get "/"
+ assert_response 500
+ assert_match /puke/, body
+
+ ActiveSupport::Notifications.notifier.wait
+
+ assert_equal 'action_dispatch.show_exception', event.first
+ assert_kind_of Hash, event.last[:env]
+ assert_equal 'GET', event.last[:env]["REQUEST_METHOD"]
+ assert_kind_of RuntimeError, event.last[:exception]
+ end
end
diff --git a/actionpack/test/dispatch/string_coercion_test.rb b/actionpack/test/dispatch/string_coercion_test.rb
deleted file mode 100644
index d79b17b932..0000000000
--- a/actionpack/test/dispatch/string_coercion_test.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'abstract_unit'
-
-class StringCoercionTest < ActiveSupport::TestCase
- test "body responds to each" do
- original_body = []
- body = ActionDispatch::StringCoercion::UglyBody.new(original_body)
-
- assert original_body.respond_to?(:each)
- assert body.respond_to?(:each)
- end
-
- test "body responds to to_path" do
- original_body = []
- def original_body.to_path; end
- body = ActionDispatch::StringCoercion::UglyBody.new(original_body)
-
- assert original_body.respond_to?(:to_path)
- assert body.respond_to?(:to_path)
- end
-
- test "body does not responds to to_path" do
- original_body = []
- body = ActionDispatch::StringCoercion::UglyBody.new(original_body)
-
- assert !original_body.respond_to?(:to_path)
- assert !body.respond_to?(:to_path)
- end
-
- test "calls to_s on body parts" do
- app = lambda { |env|
- [200, {'Content-Type' => 'html'}, [1, 2, 3]]
- }
- app = ActionDispatch::StringCoercion.new(app)
- parts = []
- status, headers, body = app.call({})
- body.each { |part| parts << part }
-
- assert_equal %w( 1 2 3 ), parts
- end
-end
diff --git a/actionpack/test/template/active_model_helper_i18n_test.rb b/actionpack/test/template/active_model_helper_i18n_test.rb
index 2465444fc5..4eb2f262bd 100644
--- a/actionpack/test/template/active_model_helper_i18n_test.rb
+++ b/actionpack/test/template/active_model_helper_i18n_test.rb
@@ -16,27 +16,27 @@ class ActiveModelHelperI18nTest < Test::Unit::TestCase
stubs(:content_tag).returns 'content_tag'
- I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
- I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).returns 'There were problems with the following fields:'
+ I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
+ I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
end
def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').never
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').never
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
end
def test_error_messages_for_given_no_header_option_it_translates_header_message
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').returns 'header message'
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns 'header message'
error_messages_for(:object => @object, :locale => 'en')
end
def test_error_messages_for_given_a_message_option_it_does_not_translate_message
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).never
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).never
error_messages_for(:object => @object, :message => 'message', :locale => 'en')
end
def test_error_messages_for_given_no_message_option_it_translates_message
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).returns 'There were problems with the following fields:'
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
error_messages_for(:object => @object, :locale => 'en')
end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index b1e9fe99a2..acadbd0cd0 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -16,8 +16,8 @@ class FormHelperTest < ActionView::TestCase
}
}
},
- :views => {
- :labels => {
+ :helpers => {
+ :label => {
:post => {
:body => "Write entire text here"
}
diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb
index 91e370efa7..4972ea6511 100644
--- a/actionpack/test/template/form_options_helper_i18n_test.rb
+++ b/actionpack/test/template/form_options_helper_i18n_test.rb
@@ -6,7 +6,7 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
def setup
@prompt_message = 'Select!'
I18n.backend.send(:init_translations)
- I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message } }
+ I18n.backend.store_translations :en, :helpers => { :select => { :prompt => @prompt_message } }
end
def teardown
@@ -14,7 +14,7 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
end
def test_select_with_prompt_true_translates_prompt_message
- I18n.expects(:translate).with('support.select.prompt', { :default => 'Please select' })
+ I18n.expects(:translate).with('helpers.select.prompt', { :default => 'Please select' })
select('post', 'category', [], :prompt => true)
end
@@ -24,4 +24,4 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
select('post', 'category', [], :prompt => true)
)
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 08143ba680..088c07b8bb 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -360,6 +360,20 @@ class TextHelperTest < ActionView::TestCase
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
end
+ def test_auto_link_other_protocols
+ silence_warnings do
+ begin
+ old_re_value = ActionView::Helpers::TextHelper::AUTO_LINK_RE
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, %r{(ftp://)[^\s<]+}
+ link_raw = 'ftp://example.com/file.txt'
+ link_result = generate_result(link_raw)
+ assert_equal %(Download #{link_result}), auto_link("Download #{link_raw}")
+ ensure
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, old_re_value
+ end
+ end
+ end
+
def test_auto_link_already_linked
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')