Permalink
Browse files

Merge commit 'origin/master'

Conflicts:
	actionpack/lib/action_controller/abstract/base.rb
	actionpack/lib/action_controller/routing.rb
  • Loading branch information...
2 parents da65320 + c286952 commit b6bac73b282c7e500c43810f2a937fc0047e5979 Yehuda Katz + Carl Lerche committed May 15, 2009
View
34 actionpack/examples/minimal.rb
@@ -0,0 +1,34 @@
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'action_controller'
+require 'action_controller/new_base' if ENV['NEW']
+require 'benchmark'
+
+class BaseController < ActionController::Base
+ def index
+ render :text => ''
+ end
+end
+
+n = (ENV['N'] || 10000).to_i
+input = StringIO.new('')
+
+def call_index(controller, input, n)
+ n.times do
+ controller.action(:index).call({ 'rack.input' => input })
+ end
+
+ puts controller.name
+ status, headers, body = controller.action(:index).call({ 'rack.input' => input })
+
+ puts status
+ puts headers.to_yaml
+ puts '---'
+ body.each do |part|
+ puts part
+ end
+ puts '---'
+end
+
+elapsed = Benchmark.realtime { call_index BaseController, input, n }
+
+puts "%dms elapsed, %d requests/sec" % [1000 * elapsed, n / elapsed]
View
2 actionpack/lib/action_controller/abstract/base.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/attr_internal'
+
module AbstractController
class Error < StandardError; end
View
4 actionpack/lib/action_controller/abstract/logger.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/class/attribute_accessors'
+
module AbstractController
module Logger
extend ActiveSupport::DependencyModule
@@ -39,4 +41,4 @@ def request_origin
@request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
end
end
-end
+end
View
5 actionpack/lib/action_controller/new_base/http.rb
@@ -1,3 +1,6 @@
+require 'action_controller/abstract'
+require 'active_support/core_ext/module/delegation'
+
module ActionController
class Http < AbstractController::Base
abstract!
@@ -52,7 +55,7 @@ def call(name, env)
def self.action(name)
@actions ||= {}
- @actions[name] ||= proc do |env|
+ @actions[name.to_s] ||= proc do |env|
new.call(name, env)
end
end
View
3 actionpack/lib/action_controller/routing.rb
@@ -1,6 +1,9 @@
require 'cgi'
require 'uri'
require 'set'
+
+require 'active_support/core_ext/module/aliasing'
+require 'active_support/core_ext/module/attribute_accessors'
require 'action_controller/routing/optimisations'
require 'action_controller/routing/routing_ext'
require 'action_controller/routing/route'
View
6 actionpack/lib/action_dispatch/http/status_codes.rb
@@ -1,3 +1,5 @@
+require 'active_support/inflector'
+
module ActionDispatch
module StatusCodes #:nodoc:
STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({
@@ -16,7 +18,7 @@ module StatusCodes #:nodoc:
# :created or :not_implemented) into its corresponding HTTP status
# code (like 200 or 501).
SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)|
- hash[message.gsub(/ /, "").underscore.to_sym] = code
+ hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
hash
}.freeze
@@ -37,4 +39,4 @@ def interpret_status(status)
end
end
end
-end
+end
View
1 actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -1,4 +1,5 @@
require 'active_record_unit'
+require 'fixtures/project'
class Task < ActiveRecord::Base
set_table_name 'projects'
View
6 activerecord/lib/active_record/attribute_methods.rb
@@ -105,8 +105,8 @@ def define_attribute_methods
def instance_method_already_implemented?(method_name)
method_name = method_name.to_s
return true if method_name =~ /^id(=$|\?$|$)/
- @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map(&:to_s).to_set
- @@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map(&:to_s).to_set
+ @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveRecord::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map {|m| m.to_s }.to_set
+ @@_defined_activerecord_methods ||= (ActiveRecord::Base.public_instance_methods(false) | ActiveRecord::Base.private_instance_methods(false) | ActiveRecord::Base.protected_instance_methods(false)).map{|m| m.to_s }.to_set
raise DangerousAttributeError, "#{method_name} is defined by ActiveRecord" if @@_defined_activerecord_methods.include?(method_name)
@_defined_class_methods.include?(method_name)
end
@@ -124,7 +124,7 @@ def cache_attributes(*attribute_names)
# with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached.
def cached_attributes
@cached_attributes ||=
- columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set
+ columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map{|col| col.name}.to_set
end
# Returns +true+ if the provided attribute is being cached.
View
13 activerecord/lib/active_record/base.rb
@@ -697,14 +697,9 @@ def find_by_sql(sql)
# Person.exists?(['name LIKE ?', "%#{query}%"])
# Person.exists?
def exists?(id_or_conditions = {})
- connection.select_all(
- construct_finder_sql(
- :select => "#{quoted_table_name}.#{primary_key}",
- :conditions => expand_id_conditions(id_or_conditions),
- :limit => 1
- ),
- "#{name} Exists"
- ).size > 0
+ find_initial(
+ :select => "#{quoted_table_name}.#{primary_key}",
+ :conditions => expand_id_conditions(id_or_conditions)) ? true : false
end
# Creates an object (or multiple objects) and saves it to the database, if validations pass.
@@ -1040,7 +1035,7 @@ def decrement_counter(counter_name, id)
# To start from an all-closed default and enable attributes as needed,
# have a look at +attr_accessible+.
def attr_protected(*attributes)
- write_inheritable_attribute(:attr_protected, Set.new(attributes.map(&:to_s)) + (protected_attributes || []))
+ write_inheritable_attribute(:attr_protected, Set.new(attributes.map {|a| a.to_s}) + (protected_attributes || []))
end
# Returns an array of all the attributes that have been protected from mass-assignment.
View
6 activerecord/test/cases/finder_test.rb
@@ -119,6 +119,12 @@ def test_exists_with_aggregate_having_three_mappings_with_one_difference
Address.new(existing_address.street + "1", existing_address.city, existing_address.country))
end
+ def test_exists_with_scoped_include
+ Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do
+ assert Developer.exists?
+ end
+ end
+
def test_find_by_array_of_one_id
assert_kind_of(Array, Topic.find([ 1 ]))
assert_equal(1, Topic.find([ 1 ]).length)
View
1 activesupport/lib/active_support/memoizable.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/object/metaclass'
+require 'active_support/core_ext/module/aliasing'
module ActiveSupport
module SafelyMemoizable

0 comments on commit b6bac73

Please sign in to comment.