diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-14 17:38:30 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-14 17:38:30 -0700 |
commit | b6bac73b282c7e500c43810f2a937fc0047e5979 (patch) | |
tree | b234951c42e4c682ef723320287383ac3fff0cf1 | |
parent | da65320433088548bc4cff33758e5acd71fd137a (diff) | |
parent | c286952050e8fe16b0f6d64ba0687b52cc8f2ae1 (diff) | |
download | rails-b6bac73b282c7e500c43810f2a937fc0047e5979.tar.gz rails-b6bac73b282c7e500c43810f2a937fc0047e5979.tar.bz2 rails-b6bac73b282c7e500c43810f2a937fc0047e5979.zip |
Merge commit 'origin/master'
Conflicts:
actionpack/lib/action_controller/abstract/base.rb
actionpack/lib/action_controller/routing.rb
-rw-r--r-- | actionpack/examples/minimal.rb | 34 | ||||
-rw-r--r-- | actionpack/lib/action_controller/abstract/base.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/abstract/logger.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/new_base/http.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/status_codes.rb | 6 | ||||
-rw-r--r-- | actionpack/test/activerecord/polymorphic_routes_test.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 6 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 1 |
11 files changed, 65 insertions, 16 deletions
diff --git a/actionpack/examples/minimal.rb b/actionpack/examples/minimal.rb new file mode 100644 index 0000000000..84a8499daf --- /dev/null +++ b/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] diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index 483356a4be..f2db201063 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/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 diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb index d0603a4ad7..750a5c9fb6 100644 --- a/actionpack/lib/action_controller/abstract/logger.rb +++ b/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 @@ module AbstractController @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}" end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb index f3a60b3bf8..e9a1d5b12f 100644 --- a/actionpack/lib/action_controller/new_base/http.rb +++ b/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 @@ module ActionController def self.action(name) @actions ||= {} - @actions[name] ||= proc do |env| + @actions[name.to_s] ||= proc do |env| new.call(name, env) end end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 06a07a4d0a..ce59866531 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/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' diff --git a/actionpack/lib/action_dispatch/http/status_codes.rb b/actionpack/lib/action_dispatch/http/status_codes.rb index 830de2a6db..5bac842ec1 100644 --- a/actionpack/lib/action_dispatch/http/status_codes.rb +++ b/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 ActionDispatch # :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 @@ module ActionDispatch end end end -end
\ No newline at end of file +end diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 35139fbb7f..b9f5be2361 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/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' diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 55d9a4d15d..d5e215af9d 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -105,8 +105,8 @@ module ActiveRecord 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 @@ module ActiveRecord # 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. diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index b9ba727a3f..ca4f4fa6b6 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -697,14 +697,9 @@ module ActiveRecord #:nodoc: # 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 @@ module ActiveRecord #:nodoc: # 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. diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index ad4588db69..d0d7094e30 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -119,6 +119,12 @@ class FinderTest < ActiveRecord::TestCase 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) diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index edf626802a..fa6db683d4 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/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 |