From 0420fb56475409c209193fbd45f9afffe8cd35eb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 20 Aug 2010 10:15:52 -0700 Subject: adding FOUND_ROWS to the connect flags for mysql2 --- activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 96cf2d09db..b5bf7f46ef 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -6,6 +6,11 @@ module ActiveRecord class Base def self.mysql2_connection(config) config[:username] = 'root' if config[:username].nil? + + if Mysql2::Client.const_defined? :FOUND_ROWS + config[:flags] = Mysql2::Client::FOUND_ROWS + end + client = Mysql2::Client.new(config.symbolize_keys) options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0] ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config) -- cgit v1.2.3 From 7c9bf45b0dd7ad7a1d99a14566bfaeadc77b4665 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 20 Aug 2010 17:33:33 +0100 Subject: Support routing constraints in functional tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend assert_recognizes and assert_generates to support passing full urls as the path argument. This allows testing of routing constraints such as subdomain and host within functional tests. [#5005 state:resolved] Signed-off-by: José Valim --- .../lib/action_dispatch/routing/route_set.rb | 4 +- .../action_dispatch/testing/assertions/routing.rb | 51 ++++++++++++++++------ actionpack/test/controller/routing_test.rb | 2 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index d23b580d97..b531cc1a8e 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -494,7 +494,7 @@ module ActionDispatch def recognize_path(path, environment = {}) method = (environment[:method] || "GET").to_s.upcase - path = Rack::Mount::Utils.normalize_path(path) + path = Rack::Mount::Utils.normalize_path(path) unless path =~ %r{://} begin env = Rack::MockRequest.env_for(path, {:method => method}) @@ -502,7 +502,7 @@ module ActionDispatch raise ActionController::RoutingError, e.message end - req = Rack::Request.new(env) + req = @request_class.new(env) @set.recognize(req) do |route, matches, params| params.each do |key, value| if value.is_a?(String) diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 9338fa9e70..5a3ffda255 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -1,3 +1,4 @@ +require 'uri' require 'active_support/core_ext/hash/diff' require 'active_support/core_ext/hash/indifferent_access' @@ -40,14 +41,7 @@ module ActionDispatch # # Check a Simply RESTful generated route # assert_recognizes list_items_url, 'items/list' def assert_recognizes(expected_options, path, extras={}, message=nil) - if path.is_a? Hash - request_method = path[:method] - path = path[:path] - else - request_method = nil - end - - request = recognized_request_for(path, request_method) + request = recognized_request_for(path) expected_options = expected_options.clone extras.each_key { |key| expected_options.delete key } unless extras.nil? @@ -77,7 +71,16 @@ module ActionDispatch # # Asserts that the generated route gives us our custom route # assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" } def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) - expected_path = "/#{expected_path}" unless expected_path[0] == ?/ + if expected_path =~ %r{://} + begin + uri = URI.parse(expected_path) + expected_path = uri.path.to_s.empty? ? "/" : uri.path + rescue URI::InvalidURIError => e + raise ActionController::RoutingError, e.message + end + else + expected_path = "/#{expected_path}" unless expected_path.first == '/' + end # Load routes.rb if it hasn't been loaded. generated_path, extra_keys = @routes.generate_extras(options, defaults) @@ -177,15 +180,35 @@ module ActionDispatch private # Recognizes the route for a given path. - def recognized_request_for(path, request_method = nil) - path = "/#{path}" unless path.first == '/' + def recognized_request_for(path) + if path.is_a?(Hash) + method = path[:method] + path = path[:path] + else + method = :get + end # Assume given controller request = ActionController::TestRequest.new - request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method - request.path = path - params = @routes.recognize_path(path, { :method => request.method }) + if path =~ %r{://} + begin + uri = URI.parse(path) + request.env["rack.url_scheme"] = uri.scheme || "http" + request.host = uri.host if uri.host + request.port = uri.port if uri.port + request.path = uri.path.to_s.empty? ? "/" : uri.path + rescue URI::InvalidURIError => e + raise ActionController::RoutingError, e.message + end + else + path = "/#{path}" unless path.first == "/" + request.path = path + end + + request.request_method = method if method + + params = @routes.recognize_path(path, { :method => method }) request.path_parameters = params.with_indifferent_access request diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index fc85b01394..a8c74a6064 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -956,7 +956,7 @@ class RouteSetTest < ActiveSupport::TestCase params = set.recognize_path("/people", :method => :put) assert_equal("update", params[:action]) - assert_raise(ActionController::RoutingError) { + assert_raise(ActionController::UnknownHttpMethod) { set.recognize_path("/people", :method => :bacon) } -- cgit v1.2.3 From 2277c51555249cc8b0478e175bcb744841634db5 Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Fri, 20 Aug 2010 15:58:23 -0500 Subject: Fix hash modification during iteration in Mapper [#5420] Signed-off-by: Santiago Pastorino --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 800c6b469e..00f8fb99bb 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -774,7 +774,7 @@ module ActionDispatch return true end - options.each do |k,v| + options.keys.each do |k| (options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp) end -- cgit v1.2.3 From 63bb6390363b5866fb31674da0582cd8b5ffb3dc Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 21 Aug 2010 02:22:21 +0200 Subject: requires horo 1.0.2 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 32dc75588d..e220b261c4 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem "rails", :path => File.dirname(__FILE__) gem "rake", ">= 0.8.7" gem "mocha", ">= 0.9.8" gem "rdoc", ">= 2.5.10" -gem "horo", ">= 1.0.1" +gem "horo", ">= 1.0.2" # AS gem "memcache-client", ">= 1.8.5" -- cgit v1.2.3 From 3cd9627bd827265229781013bfa1cbbfff2a0a6c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 21 Aug 2010 02:23:04 +0200 Subject: prevent RDoc from autolinking "Rails" in the API home page --- README.rdoc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.rdoc b/README.rdoc index 2e5e72c0e4..b1a9e961f9 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,6 +1,6 @@ -== Welcome to Rails +== Welcome to \Rails -Rails is a web-application framework that includes everything needed to create +\Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Control pattern. This pattern splits the view (also called the presentation) into "dumb" @@ -11,7 +11,7 @@ persist themselves to a database. The controller handles the incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view. -In Rails, the model is handled by what's called an object-relational mapping +In \Rails, the model is handled by what's called an object-relational mapping layer entitled Active Record. This layer allows you to present the data from database rows as objects and embellish these data objects with business logic methods. You can read more about Active Record in @@ -22,17 +22,17 @@ layers by its two parts: Action View and Action Controller. These two layers are bundled in a single package due to their heavy interdependence. This is unlike the relationship between the Active Record and Action Pack that is much more separate. Each of these packages can be used independently outside of -Rails. You can read more about Action Pack in +\Rails. You can read more about Action Pack in link:files/vendor/rails/actionpack/README.html. == Getting Started -1. Install Rails at the command prompt if you haven't yet: +1. Install \Rails at the command prompt if you haven't yet: gem install rails -2. At the command prompt, create a new Rails application: +2. At the command prompt, create a new \Rails application: rails new myapp @@ -58,10 +58,10 @@ the following resources handy: == Contributing -We encourage you to contribute to Ruby on Rails! Please check out the {Contributing to Rails +We encourage you to contribute to Ruby on \Rails! Please check out the {Contributing to \Rails guide}[http://edgeguides.rubyonrails.org/contributing_to_rails.html] for guidelines about how to proceed. {Join us}[http://contributors.rubyonrails.org]! == License -Ruby on Rails is released under the MIT license. +Ruby on \Rails is released under the MIT license. -- cgit v1.2.3 From c211d904ba358d3d1ae85d56fa3a805ea505c23a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 20 Aug 2010 18:55:02 -0700 Subject: Revert "Just add connection management middleware if running in a concurrent environment." This reverts commit 6b29dc876fe185881d46731c3ae170478a3828fe. --- activerecord/lib/active_record/railtie.rb | 13 +++++-------- railties/test/application/initializers/frameworks_test.rb | 12 +----------- railties/test/application/middleware_test.rb | 1 + 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 78fdb77216..94dda4e413 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -16,7 +16,11 @@ module ActiveRecord config.generators.orm :active_record, :migration => true, :timestamps => true - config.app_middleware.insert_after "::ActionDispatch::Callbacks", "ActiveRecord::QueryCache" + config.app_middleware.insert_after "::ActionDispatch::Callbacks", + "ActiveRecord::QueryCache" + + config.app_middleware.insert_after "::ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement" rake_tasks do load "active_record/railties/databases.rake" @@ -74,13 +78,6 @@ module ActiveRecord end end - initializer "active_record.add_concurrency_middleware" do |app| - if app.config.allow_concurrency - app.config.middleware.insert_after "::ActionDispatch::Callbacks", - "ActiveRecord::ConnectionAdapters::ConnectionManagement" - end - end - config.after_initialize do ActiveSupport.on_load(:active_record) do instantiate_observers diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index d8e916f45f..4ff10091b1 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -98,17 +98,7 @@ module ApplicationTests require "#{app_path}/config/environment" - expects = [ActiveRecord::QueryCache, ActiveRecord::SessionStore] - middleware = Rails.application.config.middleware.map { |m| m.klass } - assert_equal expects, middleware & expects - end - - test "database middleware initializes when allow concurrency is true" do - add_to_config "config.threadsafe!" - - require "#{app_path}/config/environment" - - expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache] + expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] middleware = Rails.application.config.middleware.map { |m| m.klass } assert_equal expects, middleware & expects end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 1f127cee78..ed8f70dc44 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -28,6 +28,7 @@ module ApplicationTests "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", "ActiveRecord::QueryCache", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", -- cgit v1.2.3 From 82e389ed30fd979d4a627b1edbda52c6dde34ae6 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Fri, 20 Aug 2010 19:46:30 -0700 Subject: reload bob after his journy to a new timezone --- activerecord/test/cases/migration_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 186bb55c01..96b97fdd8a 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -566,6 +566,7 @@ if ActiveRecord::Base.connection.supports_migrations? if bob.moment_of_truth.is_a?(DateTime) with_env_tz 'US/Eastern' do + bob.reload assert_equal DateTime.local_offset, bob.moment_of_truth.offset assert_not_equal 0, bob.moment_of_truth.offset assert_not_equal "Z", bob.moment_of_truth.zone -- cgit v1.2.3 From 7a090b02165603cc6c18b3153539b4bce96ba065 Mon Sep 17 00:00:00 2001 From: Raphomet Date: Fri, 20 Aug 2010 23:31:32 -0700 Subject: Trifling typos Signed-off-by: Santiago Pastorino --- activesupport/test/core_ext/kernel_test.rb | 4 ++-- railties/lib/rails/commands/plugin.rb | 2 +- railties/lib/rails/generators.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 228b644c1a..904d56a87e 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -54,14 +54,14 @@ class KernelTest < Test::Unit::TestCase end end -class KernelSupressTest < Test::Unit::TestCase +class KernelSuppressTest < Test::Unit::TestCase def test_reraise assert_raise(LoadError) do suppress(ArgumentError) { raise LoadError } end end - def test_supression + def test_suppression suppress(ArgumentError) { raise ArgumentError } suppress(LoadError) { raise LoadError } suppress(LoadError, ArgumentError) { raise LoadError } diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 96b6f9c372..7bb4a1c054 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -375,7 +375,7 @@ module Commands "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout } o.on( "-e", "--export", "Use svn export to grab the plugin.", - "Exports the plugin, allowing you to check it into your local repository. Does not enable updates, or add an svn:externals entry.") { |v| @method = :export } + "Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export } o.on( "-q", "--quiet", "Suppresses the output from installation.", "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true } diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 8794392a7d..76ef598d68 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -218,11 +218,11 @@ module Rails puts "Usage: rails #{command} GENERATOR [args] [options]" puts puts "General options:" - puts " -h, [--help] # Print generators options and usage" + puts " -h, [--help] # Print generator's options and usage" puts " -p, [--pretend] # Run but do not make any changes" puts " -f, [--force] # Overwrite files that already exist" puts " -s, [--skip] # Skip files that already exist" - puts " -q, [--quiet] # Supress status output" + puts " -q, [--quiet] # Suppress status output" puts puts "Please choose a generator below." puts -- cgit v1.2.3 From 1d888d465b27e6257ebd3af9b4e73e9f49a45de1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 21 Aug 2010 22:36:51 -0300 Subject: Move encoding settings for testing purposes to abstract_unit file --- actionpack/test/abstract_unit.rb | 6 +++++- actionpack/test/template/template_test.rb | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index fb6961d4a3..23b6330805 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -12,8 +12,12 @@ $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') -if defined?(Encoding.default_internal) +require 'active_support/core_ext/string/encoding' +if "ruby".encoding_aware? + # These are the normal settings that will be set up by Railties + # TODO: Have these tests support other combinations of these values Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" end require 'test/unit' diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 18e0e83ec3..fbc9350c69 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -1,12 +1,5 @@ require "abstract_unit" -if "ruby".encoding_aware? - # These are the normal settings that will be set up by Railties - # TODO: Have these tests support other combinations of these values - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" -end - class TestERBTemplate < ActiveSupport::TestCase ERBHandler = ActionView::Template::Handlers::ERB @@ -136,4 +129,4 @@ class TestERBTemplate < ActiveSupport::TestCase Encoding.default_external = old end end -end \ No newline at end of file +end -- cgit v1.2.3 From 3c0158955ab0ac230d2f90c3b213adcee6f63117 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 21 Aug 2010 22:53:04 -0300 Subject: Set default_internal and default_external on AM for testing purposes --- actionmailer/test/abstract_unit.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index ea15709b45..d91c81886d 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -11,6 +11,13 @@ ensure $VERBOSE = old end +require 'active_support/core_ext/string/encoding' +if "ruby".encoding_aware? + # These are the normal settings that will be set up by Railties + # TODO: Have these tests support other combinations of these values + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" +end require 'active_support/core_ext/kernel/reporting' silence_warnings do @@ -67,4 +74,4 @@ end def restore_delivery_method ActionMailer::Base.delivery_method = @old_delivery_method -end \ No newline at end of file +end -- cgit v1.2.3 From d79a010976785ec42ed2b567c0f8a2e0fa7d15bf Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 22 Aug 2010 02:23:13 -0300 Subject: Set default_internal and default_external on AS for testing purposes --- activesupport/test/abstract_unit.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 6db21f9e12..83b25de332 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -10,6 +10,14 @@ end lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) +require 'active_support/core_ext/string/encoding' +if "ruby".encoding_aware? + # These are the normal settings that will be set up by Railties + # TODO: Have these tests support other combinations of these values + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" +end + require 'test/unit' require 'active_support/core_ext/kernel/reporting' require 'empty_bool' -- cgit v1.2.3 From ae2c60734a0f71593709608710a0c7507bb8699e Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 22 Aug 2010 18:48:26 +0100 Subject: Cache the symbolized path parameters using a instance variable in the request object rather than the environment hash. This it to prevent stale parameters in later routing constraints/redirects as only the normal path parameters are set by Rack::Mount. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also if a constraint proc arity is more than one, pass the symbolized path parameters as the first argument to match redirect proc args and provide easier access. [#5157 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_dispatch/http/parameters.rb | 4 ++-- actionpack/lib/action_dispatch/routing/mapper.rb | 7 ++++++- actionpack/test/dispatch/routing_test.rb | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index add8cab2ab..5e1a2405f7 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -15,14 +15,14 @@ module ActionDispatch alias :params :parameters def path_parameters=(parameters) #:nodoc: - @env.delete("action_dispatch.request.symbolized_path_parameters") + @_symbolized_path_params = nil @env.delete("action_dispatch.request.parameters") @env["action_dispatch.request.path_parameters"] = parameters end # The same as path_parameters with explicitly symbolized keys. def symbolized_path_parameters - @env["action_dispatch.request.symbolized_path_parameters"] ||= path_parameters.symbolize_keys + @_symbolized_path_params ||= path_parameters.symbolize_keys end # Returns a hash with the \parameters used to form the \path of the request. diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 00f8fb99bb..23b13d1d5d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -26,13 +26,18 @@ module ActionDispatch @constraints.each { |constraint| if constraint.respond_to?(:matches?) && !constraint.matches?(req) return [ 404, {'X-Cascade' => 'pass'}, [] ] - elsif constraint.respond_to?(:call) && !constraint.call(req) + elsif constraint.respond_to?(:call) && !constraint.call(*constraint_args(constraint, req)) return [ 404, {'X-Cascade' => 'pass'}, [] ] end } @app.call(env) end + + private + def constraint_args(constraint, request) + constraint.arity == 1 ? [request] : [request.symbolized_path_parameters, request] + end end class Mapping #:nodoc: diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 44b83f3afc..c529db4771 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -427,6 +427,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get :preview, :on => :member end + scope '/countries/:country', :constraints => lambda { |params, req| %[all France].include?(params[:country]) } do + match '/', :to => 'countries#index' + match '/cities', :to => 'countries#cities' + end + + match '/countries/:country/(*other)', :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : '/countries/all' } + match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/ end end @@ -2013,6 +2020,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_symbolized_path_parameters_is_not_stale + get '/countries/France' + assert_equal 'countries#index', @response.body + + get '/countries/France/cities' + assert_equal 'countries#cities', @response.body + + get '/countries/UK' + verify_redirect 'http://www.example.com/countries/all' + + get '/countries/UK/cities' + verify_redirect 'http://www.example.com/countries/all/cities' + end + private def with_test_routes yield -- cgit v1.2.3 From 8d1ee434da3348089daa497980d1e24837ee8be6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 22 Aug 2010 18:43:31 -0300 Subject: Silence warnings for Encoding.default_external= and Encoding.default_internal= --- actionmailer/test/abstract_unit.rb | 9 ++++++--- actionpack/test/abstract_unit.rb | 8 ++++++-- activesupport/test/abstract_unit.rb | 9 ++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index d91c81886d..b430dffdf8 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -11,15 +11,18 @@ ensure $VERBOSE = old end +require 'active_support/core_ext/kernel/reporting' + require 'active_support/core_ext/string/encoding' if "ruby".encoding_aware? # These are the normal settings that will be set up by Railties # TODO: Have these tests support other combinations of these values - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" + silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" + end end -require 'active_support/core_ext/kernel/reporting' silence_warnings do # These external dependencies have warnings :/ require 'text/format' diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 23b6330805..869842fc9c 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -12,12 +12,16 @@ $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers') ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') +require 'active_support/core_ext/kernel/reporting' + require 'active_support/core_ext/string/encoding' if "ruby".encoding_aware? # These are the normal settings that will be set up by Railties # TODO: Have these tests support other combinations of these values - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" + silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" + end end require 'test/unit' diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 83b25de332..0382739871 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -10,16 +10,19 @@ end lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) +require 'active_support/core_ext/kernel/reporting' + require 'active_support/core_ext/string/encoding' if "ruby".encoding_aware? # These are the normal settings that will be set up by Railties # TODO: Have these tests support other combinations of these values - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" + silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" + end end require 'test/unit' -require 'active_support/core_ext/kernel/reporting' require 'empty_bool' silence_warnings { require 'mocha' } -- cgit v1.2.3