Skip to content

Commit

Permalink
Merge commit 'rails/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Sep 14, 2009
2 parents 0489f0c + 181cd10 commit 24260dc
Show file tree
Hide file tree
Showing 250 changed files with 1,223 additions and 673 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,5 @@ railties/guides/output
*.rbc
*.swp
*.swo
actionpack/bin
*/vendor/gems
1 change: 0 additions & 1 deletion actionmailer/lib/actionmailer.rb

This file was deleted.

14 changes: 14 additions & 0 deletions 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
43 changes: 15 additions & 28 deletions actionpack/Rakefile
Expand Up @@ -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
Expand All @@ -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|
Expand Down
22 changes: 20 additions & 2 deletions actionpack/lib/action_controller/metal.rb
Expand Up @@ -79,6 +79,15 @@ def to_a
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
Expand All @@ -88,6 +97,16 @@ def call(env)
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.
Expand All @@ -98,8 +117,7 @@ def call(env)
# ==== 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
Expand Up @@ -49,7 +49,7 @@ def filter_parameter_logging(*filter_words, &block)
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
Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/action_controller/testing/integration.rb
Expand Up @@ -259,7 +259,6 @@ def process(method, path, parameters = nil, rack_environment = nil)
"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",
Expand Down
@@ -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
1 change: 1 addition & 0 deletions 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'
Expand Down
26 changes: 19 additions & 7 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -449,6 +449,15 @@ def apply_form_for_options!(object_or_array, options) #:nodoc:
# <% 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:
#
Expand Down Expand Up @@ -1037,18 +1046,21 @@ def nested_attributes_association?(association_name)

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

Expand Down
1 change: 1 addition & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/handlers/builder.rb
Expand Up @@ -6,7 +6,7 @@ class Builder < TemplateHandler
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 +
Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/actionpack.rb

This file was deleted.

@@ -1,4 +1,4 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
require 'abstract_unit2'

module AbstractController
module Testing
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down Expand Up @@ -235,4 +235,4 @@ class TestHalting < ActiveSupport::TestCase
end

end
end
end
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
21 changes: 0 additions & 21 deletions actionpack/test/abstract_controller/test_helper.rb

This file was deleted.

9 changes: 4 additions & 5 deletions 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'
Expand Down

0 comments on commit 24260dc

Please sign in to comment.