aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-09-14 09:47:55 -0300
committerEmilio Tagua <miloops@gmail.com>2009-09-14 09:47:55 -0300
commit24260dc0c8338aef8e24407e00750fd72a0366ea (patch)
tree849b286decba65c1136947ef6f52235335df2383 /actionpack
parent0489f0c582d2ab70595296f058545b102466bebd (diff)
parent181cd109d9812d371e2d554a4846f0b2b25b1690 (diff)
downloadrails-24260dc0c8338aef8e24407e00750fd72a0366ea.tar.gz
rails-24260dc0c8338aef8e24407e00750fd72a0366ea.tar.bz2
rails-24260dc0c8338aef8e24407e00750fd72a0366ea.zip
Merge commit 'rails/master'
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/Gemfile14
-rw-r--r--actionpack/Rakefile43
-rw-r--r--actionpack/lib/action_controller/metal.rb22
-rw-r--r--actionpack/lib/action_controller/metal/filter_parameter_logging.rb2
-rw-r--r--actionpack/lib/action_controller/testing/integration.rb1
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb75
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb1
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb26
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb1
-rw-r--r--actionpack/lib/action_view/template/handlers/builder.rb2
-rw-r--r--actionpack/lib/actionpack.rb1
-rw-r--r--actionpack/test/abstract_controller/abstract_controller_test.rb2
-rw-r--r--actionpack/test/abstract_controller/callbacks_test.rb4
-rw-r--r--actionpack/test/abstract_controller/helper_test.rb2
-rw-r--r--actionpack/test/abstract_controller/layouts_test.rb2
-rw-r--r--actionpack/test/abstract_controller/test_helper.rb21
-rw-r--r--actionpack/test/abstract_unit.rb9
-rw-r--r--actionpack/test/abstract_unit2.rb (renamed from actionpack/test/new_base/test_helper.rb)15
-rw-r--r--actionpack/test/active_record_unit.rb (renamed from actionpack/test/lib/active_record_unit.rb)6
-rw-r--r--actionpack/test/bundler_helper.rb10
-rw-r--r--actionpack/test/controller/filter_params_test.rb1
-rw-r--r--actionpack/test/controller/rescue_test.rb1
-rw-r--r--actionpack/test/controller/resources_test.rb5
-rw-r--r--actionpack/test/lib/controller/fake_controllers.rb1
-rw-r--r--actionpack/test/new_base/base_test.rb4
-rw-r--r--actionpack/test/new_base/content_negotiation_test.rb4
-rw-r--r--actionpack/test/new_base/content_type_test.rb2
-rw-r--r--actionpack/test/new_base/etag_test.rb4
-rw-r--r--actionpack/test/new_base/metal_test.rb3
-rw-r--r--actionpack/test/new_base/middleware_test.rb77
-rw-r--r--actionpack/test/new_base/redirect_test.rb1
-rw-r--r--actionpack/test/new_base/render_action_test.rb4
-rw-r--r--actionpack/test/new_base/render_file_test.rb4
-rw-r--r--actionpack/test/new_base/render_implicit_action_test.rb4
-rw-r--r--actionpack/test/new_base/render_layout_test.rb4
-rw-r--r--actionpack/test/new_base/render_partial_test.rb4
-rw-r--r--actionpack/test/new_base/render_rjs_test.rb4
-rw-r--r--actionpack/test/new_base/render_template_test.rb4
-rw-r--r--actionpack/test/new_base/render_test.rb4
-rw-r--r--actionpack/test/new_base/render_text_test.rb4
-rw-r--r--actionpack/test/new_base/render_xml_test.rb4
-rw-r--r--actionpack/test/old_base/abstract_unit.rb46
-rwxr-xr-xactionpack/test/runner8
-rw-r--r--actionpack/test/template/form_helper_test.rb36
-rw-r--r--actionpack/test/template/form_options_helper_test.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb1
46 files changed, 288 insertions, 207 deletions
diff --git a/actionpack/Gemfile b/actionpack/Gemfile
new file mode 100644
index 0000000000..b1579b427b
--- /dev/null
+++ b/actionpack/Gemfile
@@ -0,0 +1,14 @@
+rails_root = Pathname.new(File.dirname(__FILE__)).join("..")
+
+gem "rack", "~> 1.0.0"
+gem "rack-test", "~> 0.4.2"
+gem "activesupport", "3.0.pre", :vendored_at => rails_root.join("activesupport")
+gem "activemodel", "3.0.pre", :vendored_at => rails_root.join("activemodel")
+
+only :test do
+ gem "mocha"
+ gem "sqlite3-ruby"
+ gem "RedCloth"
+end
+
+disable_system_gems
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 06f6905af0..0d8362ad0b 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -17,18 +17,25 @@ RUBY_FORGE_PROJECT = "actionpack"
RUBY_FORGE_USER = "webster132"
desc "Default Task"
-task :default => [ :test ]
+task :default => :test
+
+task :bundle do
+ puts "Checking if the bundled testing requirements are up to date..."
+ result = system "gem bundle"
+ unless result
+ puts "The gem bundler is not installed. Installing."
+ system "gem install bundler"
+ system "gem bundle"
+ end
+end
# Run the unit tests
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration, :test_new_base]
-test_lib_dirs = ENV["NEW"] ? ["test/new_base"] : []
-test_lib_dirs.push "test", "test/lib"
-# test_lib_dirs = [ENV["NEW"] ? "test/new_base" : "test", "test/lib"]
Rake::TestTask.new(:test_action_pack) do |t|
- t.libs.concat test_lib_dirs
+ t.libs << 'test'
# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
@@ -41,44 +48,24 @@ end
task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir.glob("test/{controller,dispatch,template}/**/*_test.rb").all? do |file|
- system(ruby, "-Ilib:#{test_lib_dirs * ':'}", file)
+ system(ruby, "-Itest", file)
end or raise "Failures"
end
desc 'ActiveRecord Integration Tests'
Rake::TestTask.new(:test_active_record_integration) do |t|
- t.libs.concat test_lib_dirs
+ t.libs << 'test'
t.test_files = Dir.glob("test/activerecord/*_test.rb")
t.verbose = true
end
desc 'New Controller Tests'
Rake::TestTask.new(:test_new_base) do |t|
- t.libs << "test/new_base" << "test/lib"
+ t.libs << 'test'
t.test_files = Dir.glob("test/{abstract_controller,new_base}/*_test.rb")
t.verbose = true
end
-desc 'Old Controller Tests on New Base'
-Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
- t.libs << "test/new_base" << "test/lib"
-
- t.verbose = true
- # ==== Not ported
- # * filters
-
- t.test_files = Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort + %w(
- action_pack_assertions addresses_render assert_select
- base benchmark caching capture content_type cookie dispatcher
- filter_params flash helper http_basic_authentication
- http_digest_authentication integration layout logging mime_responds
- record_identifier redirect render render_js render_json
- render_other render_xml request_forgery_protection rescue
- resources routing selector send_file test url_rewriter
- verification view_paths webservice
- ).map { |name| "test/controller/#{name}_test.rb" }
-end
-
# Genereate the RDoc documentation
Rake::RDocTask.new { |rdoc|
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 51fbba3661..6aa4fe6019 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -79,6 +79,15 @@ module ActionController
end
class ActionEndpoint
+ @@endpoints = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
+
+ def self.for(controller, action, stack)
+ @@endpoints[controller][action][stack] ||= begin
+ endpoint = new(controller, action)
+ stack.build(endpoint)
+ end
+ end
+
def initialize(controller, action)
@controller, @action = controller, action
end
@@ -88,6 +97,16 @@ module ActionController
end
end
+ extlib_inheritable_accessor(:middleware_stack) { ActionDispatch::MiddlewareStack.new }
+
+ def self.use(*args)
+ middleware_stack.use(*args)
+ end
+
+ def self.middleware
+ middleware_stack
+ end
+
# Return a rack endpoint for the given action. Memoize the endpoint, so
# multiple calls into MyController.action will return the same object
# for the same action.
@@ -98,8 +117,7 @@ module ActionController
# ==== Returns
# Proc:: A rack application
def self.action(name)
- @actions ||= {}
- @actions[name.to_s] ||= ActionEndpoint.new(self, name)
+ ActionEndpoint.for(self, name, middleware_stack)
end
end
end
diff --git a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
index 065e62a37f..4259d9de19 100644
--- a/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
+++ b/actionpack/lib/action_controller/metal/filter_parameter_logging.rb
@@ -49,7 +49,7 @@ module ActionController
end
elsif block_given?
key = key.dup
- value = value.dup if value
+ value = value.dup if value.duplicable?
yield key, value
filtered_parameters[key] = value
else
diff --git a/actionpack/lib/action_controller/testing/integration.rb b/actionpack/lib/action_controller/testing/integration.rb
index e7104e5c3d..791f936f51 100644
--- a/actionpack/lib/action_controller/testing/integration.rb
+++ b/actionpack/lib/action_controller/testing/integration.rb
@@ -259,7 +259,6 @@ module ActionController
"rack.url_scheme" => https? ? "https" : "http",
"REQUEST_URI" => path,
- "PATH_INFO" => path,
"HTTP_HOST" => host,
"REMOTE_ADDR" => remote_addr,
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
diff --git a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
index 1d9efc2b36..be1d5a43a2 100644
--- a/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
@@ -1,52 +1,47 @@
-require "active_support/core_ext/kernel/requires"
-begin
- require_library_or_gem 'memcache'
+module ActionDispatch
+ module Session
+ class MemCacheStore < AbstractStore
+ def initialize(app, options = {})
+ require 'memcache'
- module ActionDispatch
- module Session
- class MemCacheStore < AbstractStore
- def initialize(app, options = {})
- # Support old :expires option
- options[:expire_after] ||= options[:expires]
+ # Support old :expires option
+ options[:expire_after] ||= options[:expires]
- super
+ super
- @default_options = {
- :namespace => 'rack:session',
- :memcache_server => 'localhost:11211'
- }.merge(@default_options)
+ @default_options = {
+ :namespace => 'rack:session',
+ :memcache_server => 'localhost:11211'
+ }.merge(@default_options)
- @pool = options[:cache] || MemCache.new(@default_options[:memcache_server], @default_options)
- unless @pool.servers.any? { |s| s.alive? }
- raise "#{self} unable to find server during initialization."
- end
- @mutex = Mutex.new
-
- super
+ @pool = options[:cache] || MemCache.new(@default_options[:memcache_server], @default_options)
+ unless @pool.servers.any? { |s| s.alive? }
+ raise "#{self} unable to find server during initialization."
end
+ @mutex = Mutex.new
- private
- def get_session(env, sid)
- sid ||= generate_sid
- begin
- session = @pool.get(sid) || {}
- rescue MemCache::MemCacheError, Errno::ECONNREFUSED
- session = {}
- end
- [sid, session]
- end
+ super
+ end
- def set_session(env, sid, session_data)
- options = env['rack.session.options']
- expiry = options[:expire_after] || 0
- @pool.set(sid, session_data, expiry)
- return true
+ private
+ def get_session(env, sid)
+ sid ||= generate_sid
+ begin
+ session = @pool.get(sid) || {}
rescue MemCache::MemCacheError, Errno::ECONNREFUSED
- return false
+ session = {}
end
- end
+ [sid, session]
+ end
+
+ def set_session(env, sid, session_data)
+ options = env['rack.session.options']
+ expiry = options[:expire_after] || 0
+ @pool.set(sid, session_data, expiry)
+ return true
+ rescue MemCache::MemCacheError, Errno::ECONNREFUSED
+ return false
+ end
end
end
-rescue LoadError
- # MemCache wasn't available so neither can the store be
end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 6b00e7afb5..95f00cda39 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -1,3 +1,4 @@
+require 'thread'
require 'cgi'
require 'action_view/helpers/url_helper'
require 'action_view/helpers/tag_helper'
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 81029102b1..32b9c4a7dd 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -449,6 +449,15 @@ module ActionView
# <% end %>
# <% end %>
#
+ # Or a collection to be used:
+ #
+ # <% form_for @person, :url => { :action => "update" } do |person_form| %>
+ # ...
+ # <% person_form.fields_for :projects, @active_projects do |project_fields| %>
+ # Name: <%= project_fields.text_field :name %>
+ # <% end %>
+ # <% end %>
+ #
# When projects is already an association on Person you can use
# +accepts_nested_attributes_for+ to define the writer method for you:
#
@@ -1037,18 +1046,21 @@ module ActionView
def fields_for_with_nested_attributes(association_name, args, block)
name = "#{object_name}[#{association_name}_attributes]"
- association = @object.send(association_name)
- explicit_object = args.first.to_model if args.first.respond_to?(:to_model)
+ association = args.first.to_model if args.first.respond_to?(:to_model)
+
+ if association.respond_to?(:new_record?)
+ association = [association] if @object.send(association_name).is_a?(Array)
+ elsif !association.is_a?(Array)
+ association = @object.send(association_name)
+ end
if association.is_a?(Array)
- children = explicit_object ? [explicit_object] : association
explicit_child_index = args.last[:child_index] if args.last.is_a?(Hash)
-
- children.map do |child|
+ association.map do |child|
fields_for_nested_model("#{name}[#{explicit_child_index || nested_child_index(name)}]", child, args, block)
end.join
- else
- fields_for_nested_model(name, explicit_object || association, args, block)
+ elsif association
+ fields_for_nested_model(name, association, args, block)
end
end
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index b07304e361..204d4d71e1 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -1,4 +1,5 @@
require 'action_view/helpers/javascript_helper'
+require 'active_support/core_ext/array/access'
require 'active_support/core_ext/hash/keys'
module ActionView
diff --git a/actionpack/lib/action_view/template/handlers/builder.rb b/actionpack/lib/action_view/template/handlers/builder.rb
index 5f381f7bf0..ba0d17b5af 100644
--- a/actionpack/lib/action_view/template/handlers/builder.rb
+++ b/actionpack/lib/action_view/template/handlers/builder.rb
@@ -6,7 +6,7 @@ module ActionView
self.default_format = Mime::XML
def compile(template)
- require 'builder'
+ require 'active_support/vendor/builder'
"xml = ::Builder::XmlMarkup.new(:indent => 2);" +
"self.output_buffer = xml.target!;" +
template.source +
diff --git a/actionpack/lib/actionpack.rb b/actionpack/lib/actionpack.rb
deleted file mode 100644
index 2fe2832f81..0000000000
--- a/actionpack/lib/actionpack.rb
+++ /dev/null
@@ -1 +0,0 @@
-require 'action_pack'
diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb
index 3b4046a424..0e6cfba5b5 100644
--- a/actionpack/test/abstract_controller/abstract_controller_test.rb
+++ b/actionpack/test/abstract_controller/abstract_controller_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module AbstractController
module Testing
diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb
index 8f62adce8c..98656c0c70 100644
--- a/actionpack/test/abstract_controller/callbacks_test.rb
+++ b/actionpack/test/abstract_controller/callbacks_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module AbstractController
module Testing
@@ -235,4 +235,4 @@ module AbstractController
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb
index 34a10cecc9..4c013137f9 100644
--- a/actionpack/test/abstract_controller/helper_test.rb
+++ b/actionpack/test/abstract_controller/helper_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module AbstractController
module Testing
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb
index 995aac7fad..bee3b5c556 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/actionpack/test/abstract_controller/layouts_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
require 'active_support/core_ext/class/removal'
module AbstractControllerTests
diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb
deleted file mode 100644
index ba4302d914..0000000000
--- a/actionpack/test/abstract_controller/test_helper.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-
-require 'rubygems'
-require 'test/unit'
-require 'active_support'
-require 'active_support/test_case'
-require 'abstract_controller'
-require 'action_view'
-require 'action_view/base'
-require 'action_dispatch'
-require 'fixture_template'
-
-begin
- require 'ruby-debug'
- Debugger.settings[:autoeval] = true
- Debugger.start
-rescue LoadError
- # Debugging disabled. `gem install ruby-debug` to enable.
-end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index a5222fc96d..7776bd0704 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -1,20 +1,19 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
$:.unshift(File.dirname(__FILE__) + '/../../activemodel/lib')
-$:.unshift(File.dirname(__FILE__) + '/lib')
+$:.unshift(File.dirname(__FILE__) + '/lib')
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
+require 'bundler_helper'
+ensure_requirable %w( rack rack/test sqlite3 )
+
ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
ENV['new_base'] = "true"
$stderr.puts "Running old tests on new_base"
-require 'rubygems'
-gem "rack", "~> 1.0.0"
-gem "rack-test", "~> 0.4.2"
-
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/abstract_unit2.rb
index 0833e1a11d..0a98d8edc2 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/abstract_unit2.rb
@@ -1,15 +1,20 @@
-$:.unshift(File.dirname(__FILE__) + '/../../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
+# TODO: Unify with abstract_unit
+
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
$:.unshift(File.dirname(__FILE__) + '/../lib')
+$:.unshift(File.dirname(__FILE__) + '/lib')
-require 'rubygems'
-gem "rack", "~> 1.0.0"
-gem "rack-test", "~> 0.4.2"
+require 'bundler_helper'
+ensure_requirable %w( rack rack/test )
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
+require 'abstract_controller'
require 'action_view'
+require 'action_view/base'
+require 'action_dispatch'
require 'fixture_template'
begin
diff --git a/actionpack/test/lib/active_record_unit.rb b/actionpack/test/active_record_unit.rb
index 1ba308e9d7..9e0c66055d 100644
--- a/actionpack/test/lib/active_record_unit.rb
+++ b/actionpack/test/active_record_unit.rb
@@ -16,7 +16,7 @@ if defined?(ActiveRecord) && defined?(Fixtures)
else
$stderr.print 'Attempting to load Active Record... '
begin
- PATH_TO_AR = "#{File.dirname(__FILE__)}/../../../activerecord/lib"
+ PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
$LOAD_PATH.unshift PATH_TO_AR
require 'active_record'
@@ -72,13 +72,13 @@ class ActiveRecordTestConnector
# Load actionpack sqlite tables
def load_schema
- File.read(File.dirname(__FILE__) + "/../fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
+ File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
ActiveRecord::Base.connection.execute(sql) unless sql.blank?
end
end
def require_fixture_models
- Dir.glob(File.dirname(__FILE__) + "/../fixtures/*.rb").each {|f| require f}
+ Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each {|f| require f}
end
end
end
diff --git a/actionpack/test/bundler_helper.rb b/actionpack/test/bundler_helper.rb
new file mode 100644
index 0000000000..f7357bdb41
--- /dev/null
+++ b/actionpack/test/bundler_helper.rb
@@ -0,0 +1,10 @@
+def ensure_requirable(libs)
+ bundler = File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment')
+ require bundler if File.exist?("#{bundler}.rb")
+
+ begin
+ libs.each { |lib| require lib }
+ rescue LoadError => e
+ abort e.message
+ end
+end
diff --git a/actionpack/test/controller/filter_params_test.rb b/actionpack/test/controller/filter_params_test.rb
index f7864745eb..19232c6bc9 100644
--- a/actionpack/test/controller/filter_params_test.rb
+++ b/actionpack/test/controller/filter_params_test.rb
@@ -35,6 +35,7 @@ class FilterParamTest < ActionController::TestCase
test_hashes = [[{},{},[]],
[{'foo'=>nil},{'foo'=>nil},[]],
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
+ [{'foo'=>1},{'foo'=>1},[]],
[{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
[{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
[{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 490a4ff3b3..23408712e9 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -359,6 +359,7 @@ class RescueTest < ActionController::IntegrationTest
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
+ reset!
yield
end
end
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index 0b639e363d..5b47de19ae 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -135,7 +135,7 @@ class ResourcesTest < ActionController::TestCase
def test_with_custom_conditions
with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
- assert_equal 'app', ActionController::Routing::Routes.named_routes.routes[:messages].conditions[:subdomain]
+ assert ActionController::Routing::Routes.recognize_path("/messages", :method => :get, :subdomain => 'app')
end
end
@@ -1130,7 +1130,8 @@ class ResourcesTest < ActionController::TestCase
map.resource :product
end
- assert_equal :get, set.named_routes.routes[:product].conditions[:method]
+ assert_routing '/product', :controller => 'products', :action => 'show'
+ assert set.recognize_path("/product", :method => :get)
end
end
diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb
index 22729188a2..5dcca2e148 100644
--- a/actionpack/test/lib/controller/fake_controllers.rb
+++ b/actionpack/test/lib/controller/fake_controllers.rb
@@ -17,6 +17,7 @@ class CController < ActionController::Base; end
class HiController < ActionController::Base; end
class BraveController < ActionController::Base; end
class ImageController < ActionController::Base; end
+class WeblogController < ActionController::Base; end
# For speed test
class SpeedController < ActionController::Base; end
diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb
index 1b2e917ced..3a559c9cb6 100644
--- a/actionpack/test/new_base/base_test.rb
+++ b/actionpack/test/new_base/base_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
# Tests the controller dispatching happy path
module Dispatching
@@ -65,4 +65,4 @@ module Dispatching
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/content_negotiation_test.rb b/actionpack/test/new_base/content_negotiation_test.rb
index d2f732738d..a2f9df597f 100644
--- a/actionpack/test/new_base/content_negotiation_test.rb
+++ b/actionpack/test/new_base/content_negotiation_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module ContentNegotiation
@@ -15,4 +15,4 @@ module ContentNegotiation
assert_body "Hello world */*!"
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/content_type_test.rb b/actionpack/test/new_base/content_type_test.rb
index ceee508224..7e95c715a0 100644
--- a/actionpack/test/new_base/content_type_test.rb
+++ b/actionpack/test/new_base/content_type_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module ContentType
class BaseController < ActionController::Base
diff --git a/actionpack/test/new_base/etag_test.rb b/actionpack/test/new_base/etag_test.rb
index 3a69e7dac4..64ae10b7a7 100644
--- a/actionpack/test/new_base/etag_test.rb
+++ b/actionpack/test/new_base/etag_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module Etags
class BasicController < ActionController::Base
@@ -43,4 +43,4 @@ module Etags
%("#{Digest::MD5.hexdigest(text)}")
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/metal_test.rb b/actionpack/test/new_base/metal_test.rb
index 2b7720863a..613d03446c 100644
--- a/actionpack/test/new_base/metal_test.rb
+++ b/actionpack/test/new_base/metal_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module MetalTest
class MetalMiddleware < ActionController::Middleware
@@ -41,4 +41,3 @@ module MetalTest
end
end
end
-
diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb
new file mode 100644
index 0000000000..ecca7e51eb
--- /dev/null
+++ b/actionpack/test/new_base/middleware_test.rb
@@ -0,0 +1,77 @@
+require 'abstract_unit2'
+
+module MiddlewareTest
+ class MyMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Test"] = "Success"
+ result[1]["Middleware-Order"] = "First"
+ result
+ end
+ end
+
+ class ExclaimerMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Order"] << "!"
+ result
+ end
+ end
+
+ class MyController < ActionController::Metal
+ use MyMiddleware
+
+ middleware.insert_before MyMiddleware, ExclaimerMiddleware
+
+ def index
+ self.response_body = "Hello World"
+ end
+ end
+
+ class InheritedController < MyController
+ end
+
+ module MiddlewareTests
+ extend ActiveSupport::Testing::Declarative
+
+ test "middleware that is 'use'd is called as part of the Rack application" do
+ result = @app.call(env_for("/"))
+ assert_equal "Hello World", result[2]
+ assert_equal "Success", result[1]["Middleware-Test"]
+ end
+
+ test "the middleware stack is exposed as 'middleware' in the controller" do
+ result = @app.call(env_for("/"))
+ assert_equal "First!", result[1]["Middleware-Order"]
+ end
+ end
+
+ class TestMiddleware < ActiveSupport::TestCase
+ include MiddlewareTests
+
+ def setup
+ @app = MyController.action(:index)
+ end
+
+ def env_for(url)
+ Rack::MockRequest.env_for(url)
+ end
+ end
+
+ class TestInheritedMiddleware < TestMiddleware
+ def setup
+ @app = InheritedController.action(:index)
+ end
+
+ test "middleware inherits" do
+ end
+ end
+end
diff --git a/actionpack/test/new_base/redirect_test.rb b/actionpack/test/new_base/redirect_test.rb
deleted file mode 100644
index e591ebd05f..0000000000
--- a/actionpack/test/new_base/redirect_test.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") \ No newline at end of file
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index dfa7cc2141..72a16e3b67 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderAction
# This has no layout and it works
@@ -317,4 +317,4 @@ module RenderActionWithBothLayouts
assert_status 200
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb
index 8d7f49dbc2..7067baca18 100644
--- a/actionpack/test/new_base/render_file_test.rb
+++ b/actionpack/test/new_base/render_file_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderFile
@@ -107,4 +107,4 @@ module RenderFile
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb
index fd96e1955f..03b9ff6eeb 100644
--- a/actionpack/test/new_base/render_implicit_action_test.rb
+++ b/actionpack/test/new_base/render_implicit_action_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderImplicitAction
class SimpleController < ::ApplicationController
@@ -25,4 +25,4 @@ module RenderImplicitAction
assert_status 200
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb
index 933eef58e7..0dfbae4e9d 100644
--- a/actionpack/test/new_base/render_layout_test.rb
+++ b/actionpack/test/new_base/render_layout_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module ControllerLayouts
class ImplicitController < ::ApplicationController
@@ -98,4 +98,4 @@ module ControllerLayouts
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_partial_test.rb b/actionpack/test/new_base/render_partial_test.rb
index bbb98a0c01..ff775dbfd7 100644
--- a/actionpack/test/new_base/render_partial_test.rb
+++ b/actionpack/test/new_base/render_partial_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderPartial
@@ -24,4 +24,4 @@ module RenderPartial
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_rjs_test.rb b/actionpack/test/new_base/render_rjs_test.rb
index 3d3e516905..eecc275b1e 100644
--- a/actionpack/test/new_base/render_rjs_test.rb
+++ b/actionpack/test/new_base/render_rjs_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderRjs
@@ -42,4 +42,4 @@ module RenderRjs
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb
index 967cbd07b0..5637565dac 100644
--- a/actionpack/test/new_base/render_template_test.rb
+++ b/actionpack/test/new_base/render_template_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderTemplate
class WithoutLayoutController < ActionController::Base
@@ -167,4 +167,4 @@ module RenderTemplate
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb
index 5783b4766a..94820f1c9c 100644
--- a/actionpack/test/new_base/render_test.rb
+++ b/actionpack/test/new_base/render_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module Render
class BlankRenderController < ActionController::Base
@@ -82,4 +82,4 @@ module Render
assert_body "Controller Name: blank_render"
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb
index 84f77432c9..23660ed101 100644
--- a/actionpack/test/new_base/render_text_test.rb
+++ b/actionpack/test/new_base/render_text_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderText
class SimpleController < ActionController::Base
@@ -134,4 +134,4 @@ module RenderText
assert_status 200
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/new_base/render_xml_test.rb b/actionpack/test/new_base/render_xml_test.rb
index a3890ddfb2..86a7d9c8a5 100644
--- a/actionpack/test/new_base/render_xml_test.rb
+++ b/actionpack/test/new_base/render_xml_test.rb
@@ -1,4 +1,4 @@
-require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+require 'abstract_unit2'
module RenderXml
@@ -8,4 +8,4 @@ module RenderXml
"render_xml/basic/with_render_erb" => "Hello world!"
)]
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/old_base/abstract_unit.rb b/actionpack/test/old_base/abstract_unit.rb
deleted file mode 100644
index b80050bd48..0000000000
--- a/actionpack/test/old_base/abstract_unit.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-if ENV['new_base']
- puts *caller
- raise 'new_base/abstract_unit already loaded'
-end
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
-$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
-
-require 'rubygems'
-gem "rack", "~> 1.0.0"
-gem "rack-test", "~> 0.4.2"
-
-require 'yaml'
-require 'stringio'
-require 'test/unit'
-
-begin
- require 'ruby-debug'
- Debugger.settings[:autoeval] = true
- Debugger.start
-rescue LoadError
- # Debugging disabled. `gem install ruby-debug` to enable.
-end
-
-require 'action_controller'
-require 'action_controller/testing/process'
-require 'action_view/test_case'
-
-$tags[:old_base] = true
-
-# Show backtraces for deprecated behavior for quicker cleanup.
-ActiveSupport::Deprecation.debug = true
-
-ActionController::Base.logger = nil
-ActionController::Routing::Routes.reload rescue nil
-
-ActionController::Base.session_store = nil
-
-# Register danish language for testing
-I18n.backend.store_translations 'da', {}
-I18n.backend.store_translations 'pt-BR', {}
-ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
-
-FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
-ActionController::Base.view_paths = FIXTURE_LOAD_PATH
diff --git a/actionpack/test/runner b/actionpack/test/runner
deleted file mode 100755
index c2bbe63c75..0000000000
--- a/actionpack/test/runner
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env ruby
-
-
-ARGV.each do |arg|
- Dir["#{Dir.pwd}/#{arg}/**/*_test.rb"].each do |file|
- require file
- end
-end \ No newline at end of file
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 8fd018f86d..be15b06372 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -784,6 +784,42 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_an_empty_supplied_attributes_collection
+ form_for(:post, @post) do |f|
+ concat f.text_field(:title)
+ f.fields_for(:comments, []) do |cf|
+ concat cf.text_field(:name)
+ end
+ end
+
+ expected = '<form action="http://www.example.com" method="post">' +
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '</form>'
+
+ assert_dom_equal expected, output_buffer
+ end
+
+ def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+
+ form_for(:post, @post) do |f|
+ concat f.text_field(:title)
+ f.fields_for(:comments, @post.comments) do |cf|
+ concat cf.text_field(:name)
+ end
+ end
+
+ expected = '<form action="http://www.example.com" method="post">' +
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' +
+ '</form>'
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_only_builder
@post.comments = [Comment.new(321), Comment.new]
yielded_comments = []
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index aa40e46aa8..f3cdab05bf 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'tzinfo'
+require 'active_support/vendor/tzinfo'
TZInfo::Timezone.cattr_reader :loaded_zones
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 44f1925653..447d520ef1 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -1,5 +1,6 @@
# encoding: utf-8
require 'abstract_unit'
+require 'controller/fake_controllers'
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)