Permalink
Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
jeremy committed Mar 28, 2010
2 parents d1f3437 + c99194c commit 7e3b4c1f2f0c435f1fa5f8f093ce6934d6a1207d
Showing with 147 additions and 6 deletions.
  1. +1 −0 actionmailer/lib/action_mailer/base.rb
  2. +1 −0 actionmailer/lib/action_mailer/old_api.rb
  3. +1 −0 actionpack/lib/action_controller/metal/http_authentication.rb
  4. +1 −0 actionpack/lib/action_controller/metal/renderers.rb
  5. +2 −0 actionpack/lib/action_controller/railties/log_subscriber.rb
  6. +1 −0 actionpack/lib/action_controller/test_case.rb
  7. +2 −0 actionpack/lib/action_dispatch/http/cache.rb
  8. +1 −0 actionpack/lib/action_dispatch/http/filter_parameters.rb
  9. +1 −0 actionpack/lib/action_dispatch/http/mime_type.rb
  10. +1 −0 actionpack/lib/action_dispatch/http/response.rb
  11. +2 −0 actionpack/lib/action_dispatch/http/upload.rb
  12. +1 −0 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
  13. +1 −0 actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
  14. +2 −0 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
  15. +1 −0 actionpack/lib/action_dispatch/routing/mapper.rb
  16. +3 −1 actionpack/lib/action_dispatch/testing/performance_test.rb
  17. +2 −0 actionpack/lib/action_dispatch/testing/test_request.rb
  18. +2 −0 actionpack/lib/action_view/helpers/capture_helper.rb
  19. +1 −0 actionpack/lib/action_view/helpers/form_helper.rb
  20. +1 −0 actionpack/lib/action_view/helpers/form_options_helper.rb
  21. +1 −0 actionpack/lib/action_view/helpers/form_tag_helper.rb
  22. +1 −0 actionpack/lib/action_view/helpers/number_helper.rb
  23. +1 −0 actionpack/lib/action_view/helpers/prototype_helper.rb
  24. +1 −0 actionpack/lib/action_view/helpers/tag_helper.rb
  25. +1 −0 actionpack/lib/action_view/helpers/text_helper.rb
  26. +2 −0 actionpack/lib/action_view/render/partials.rb
  27. +1 −0 actionpack/lib/action_view/test_case.rb
  28. +3 −0 activemodel/lib/active_model/dirty.rb
  29. +1 −0 activemodel/lib/active_model/errors.rb
  30. +1 −0 activemodel/lib/active_model/validator.rb
  31. +38 −2 activerecord/lib/active_record/associations.rb
  32. +1 −0 activerecord/lib/active_record/associations/has_many_through_association.rb
  33. +2 −0 activerecord/lib/active_record/attribute_methods/dirty.rb
  34. +2 −0 activerecord/lib/active_record/attribute_methods/query.rb
  35. +2 −0 activerecord/lib/active_record/base.rb
  36. +2 −0 activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  37. +1 −0 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  38. +1 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  39. +1 −0 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  40. +1 −0 activerecord/lib/active_record/fixtures.rb
  41. +1 −0 activerecord/lib/active_record/named_scope.rb
  42. +1 −0 activerecord/lib/active_record/nested_attributes.rb
  43. +2 −0 activerecord/lib/active_record/query_cache.rb
  44. +2 −0 activerecord/lib/active_record/relation.rb
  45. +2 −0 activerecord/lib/active_record/relation/batches.rb
  46. +2 −0 activerecord/lib/active_record/relation/calculations.rb
  47. +2 −0 activerecord/lib/active_record/relation/finder_methods.rb
  48. +2 −0 activerecord/lib/active_record/relation/query_methods.rb
  49. +2 −0 activerecord/lib/active_record/relation/spawn_methods.rb
  50. +2 −0 activerecord/lib/active_record/schema.rb
  51. +7 −1 activerecord/test/cases/associations/belongs_to_associations_test.rb
  52. +8 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  53. +9 −1 activerecord/test/cases/associations/has_one_associations_test.rb
  54. +5 −0 activerecord/test/models/company.rb
  55. +1 −0 activeresource/lib/active_resource/base.rb
  56. +2 −0 activeresource/lib/active_resource/custom_methods.rb
  57. +1 −0 activeresource/lib/active_resource/validations.rb
  58. +1 −0 activesupport/lib/active_support/xml_mini/libxmlsax.rb
  59. +1 −0 activesupport/lib/active_support/xml_mini/nokogirisax.rb
  60. +1 −1 railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
  61. +1 −0 railties/lib/rails/generators/rails/resource/resource_generator.rb
@@ -2,6 +2,7 @@
require 'action_mailer/tmail_compat'
require 'action_mailer/collector'
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/object/blank'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
@@ -1,4 +1,5 @@
require 'active_support/core_ext/object/try'
+require 'active_support/core_ext/object/blank'
module ActionMailer
module OldApi #:nodoc:
@@ -1,4 +1,5 @@
require 'active_support/base64'
+require 'active_support/core_ext/object/blank'
module ActionController
module HttpAuthentication
@@ -1,4 +1,5 @@
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/object/blank'
module ActionController
def self.add_renderer(key, &block)
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionController
module Railties
class LogSubscriber < Rails::LogSubscriber
@@ -1,4 +1,5 @@
require 'rack/session/abstract/id'
+require 'active_support/core_ext/object/blank'
module ActionController
module TemplateAssertions
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Http
module Cache
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/object/duplicable'
module ActionDispatch
module Http
@@ -1,5 +1,6 @@
require 'set'
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/object/blank'
module Mime
class Mimes < Array
@@ -1,5 +1,6 @@
require 'digest/md5'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/object/blank'
module ActionDispatch # :nodoc:
# Represents an HTTP response generated by a controller action. One can use
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Http
module UploadedFile
@@ -1,5 +1,6 @@
require 'rack/utils'
require 'rack/request'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Session
@@ -1,4 +1,5 @@
require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Session
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Routing
class RouteSet
@@ -1,4 +1,5 @@
require 'active_support/core_ext/hash/except'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Routing
@@ -1,7 +1,7 @@
require 'active_support/testing/performance'
require 'active_support/testing/default'
-if defined?(ActiveSupport::Testing::Performance)
+begin
module ActionDispatch
# An integration test that runs a code profiler on your test methods.
# Profiling output for combinations of each test method, measurement, and
@@ -14,4 +14,6 @@ class PerformanceTest < ActionDispatch::IntegrationTest
include ActiveSupport::Testing::Default
end
end
+rescue NameError
+ $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks."
end
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
class TestRequest < Request
DEFAULT_ENV = Rack::MockRequest.env_for('/')
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionView
module Helpers
# CaptureHelper exposes methods to let you extract generated markup which
@@ -4,6 +4,7 @@
require 'action_view/helpers/form_tag_helper'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/hash/slice'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
@@ -1,6 +1,7 @@
require 'cgi'
require 'erb'
require 'action_view/helpers/form_helper'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
@@ -1,6 +1,7 @@
require 'cgi'
require 'action_view/helpers/tag_helper'
require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
@@ -1,5 +1,6 @@
require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/float/rounding'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers #:nodoc:
@@ -1,6 +1,7 @@
require 'set'
require 'active_support/json'
require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'set'
module ActionView
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'action_view/helpers/tag_helper'
module ActionView
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionView
# There's also a convenience method for rendering sub templates within the current controller that depends on a
# single object (we call this kind of sub templates for partials). It relies on the fact that partials should
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'action_controller/test_case'
require 'action_view'
@@ -1,4 +1,7 @@
+require 'active_model/attribute_methods'
+require 'active_support/concern'
require 'active_support/hash_with_indifferent_access'
+require 'active_support/core_ext/object/duplicable'
module ActiveModel
# <tt>ActiveModel::Dirty</tt> provides a way to track changes in your
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/inflections'
+require 'active_support/core_ext/object/blank'
require 'active_support/ordered_hash'
module ActiveModel
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require "active_support/core_ext/module/anonymous"
+require 'active_support/core_ext/object/blank'
module ActiveModel #:nodoc:
# A simple base class that can be used along with
@@ -1,5 +1,6 @@
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/enumerable'
+require 'active_support/core_ext/object/blank'
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
@@ -85,6 +86,15 @@ def initialize(reflection)
end
end
+ # This error is raised when trying to destroy a parent instance in a N:1, 1:1 assosications
+ # (has_many, has_one) when there is at least 1 child assosociated instance.
+ # ex: if @project.tasks.size > 0, DeleteRestrictionError will be raised when trying to destroy @project
+ class DeleteRestrictionError < ActiveRecordError #:nodoc:
+ def initialize(reflection)
+ super("Cannot delete record because of dependent #{reflection.name}")
+ end
+ end
+
# See ActiveRecord::Associations::ClassMethods for documentation.
module Associations # :nodoc:
extend ActiveSupport::Concern
@@ -830,6 +840,8 @@ module ClassMethods
# objects are deleted *without* calling their +destroy+ method. If set to <tt>:nullify</tt> all associated
# objects' foreign keys are set to +NULL+ *without* calling their +save+ callbacks. *Warning:* This option is ignored when also using
# the <tt>:through</tt> option.
+ # the <tt>:through</tt> option. If set to <tt>:restrict</tt>
+ # this object cannot be deleted if it has any associated object.
# [:finder_sql]
# Specify a complete SQL statement to fetch the association. This is a good way to go for complex
# associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added.
@@ -1468,9 +1480,15 @@ def add_touch_callbacks(reflection, touch_attribute)
# Creates before_destroy callback methods that nullify, delete or destroy
# has_many associated objects, according to the defined :dependent rule.
+ # If the association is marked as :dependent => :restrict, create a callback
+ # that prevents deleting entirely.
#
# See HasManyAssociation#delete_records. Dependent associations
# delete children, otherwise foreign key is set to NULL.
+ # See HasManyAssociation#delete_records. Dependent associations
+ # delete children if the option is set to :destroy or :delete_all, set the
+ # foreign key to NULL if the option is set to :nullify, and do not touch the
+ # child records if the option is set to :restrict.
#
# The +extra_conditions+ parameter, which is not used within the main
# Active Record codebase, is meant to allow plugins to define extra
@@ -1530,14 +1548,24 @@ def configure_dependency_for_has_many(reflection, extra_conditions = nil)
%@#{dependent_conditions}@)
end
CALLBACK
+ when :restrict
+ method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym
+ define_method(method_name) do
+ unless send(reflection.name).empty?
+ raise DeleteRestrictionError.new(reflection)
+ end
+ end
+ before_destroy method_name
else
- raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, or :nullify (#{reflection.options[:dependent].inspect})"
+ raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, :nullify or :restrict (#{reflection.options[:dependent].inspect})"
end
end
end
# Creates before_destroy callback methods that nullify, delete or destroy
# has_one associated objects, according to the defined :dependent rule.
+ # If the association is marked as :dependent => :restrict, create a callback
+ # that prevents deleting entirely.
def configure_dependency_for_has_one(reflection)
if reflection.options.include?(:dependent)
name = reflection.options[:dependent]
@@ -1558,8 +1586,16 @@ def #{method_name}
association.update_attribute(#{reflection.primary_key_name.inspect}, nil) if association
end
eoruby
+ when :restrict
+ method_name = "has_one_dependent_restrict_for_#{reflection.name}".to_sym
+ define_method(method_name) do
+ unless send(reflection.name).nil?
+ raise DeleteRestrictionError.new(reflection)
+ end
+ end
+ before_destroy method_name
else
- raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify (#{reflection.options[:dependent].inspect})"
+ raise ArgumentError, "The :dependent option expects either :destroy, :delete, :nullify or :restrict (#{reflection.options[:dependent].inspect})"
end
before_destroy method_name
@@ -1,4 +1,5 @@
require "active_record/associations/through_association_scope"
+require 'active_support/core_ext/object/blank'
module ActiveRecord
module Associations
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
module AttributeMethods
module Dirty
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
module AttributeMethods
module Query
@@ -13,6 +13,8 @@
require 'active_support/core_ext/string/behavior'
require 'active_support/core_ext/object/singleton_class'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/object/duplicable'
+require 'active_support/core_ext/object/blank'
require 'arel'
require 'active_record/errors'
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/duplicable'
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
module QueryCache
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'date'
require 'set'
require 'bigdecimal'
@@ -1,5 +1,6 @@
require 'active_record/connection_adapters/abstract_adapter'
require 'active_support/core_ext/kernel/requires'
+require 'active_support/core_ext/object/blank'
require 'set'
module MysqlCompat #:nodoc:
@@ -1,5 +1,6 @@
require 'active_record/connection_adapters/abstract_adapter'
require 'active_support/core_ext/kernel/requires'
+require 'active_support/core_ext/object/blank'
begin
require_library_or_gem 'pg'
@@ -4,6 +4,7 @@
require 'zlib'
require 'active_support/dependencies'
require 'active_support/core_ext/logger'
+require 'active_support/core_ext/object/blank'
if RUBY_VERSION < '1.9'
module YAML #:nodoc:
@@ -1,6 +1,7 @@
require 'active_support/core_ext/array'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/object/singleton_class'
+require 'active_support/core_ext/object/blank'
module ActiveRecord
module NamedScope
@@ -1,5 +1,6 @@
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/object/try'
+require 'active_support/core_ext/object/blank'
module ActiveRecord
module NestedAttributes #:nodoc:
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
class QueryCache
module ClassMethods
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
class Relation
JoinOperation = Struct.new(:relation, :join_class, :on)
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
module Batches # :nodoc:
# Yields each record that was found by the find +options+. The find is
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveRecord
module Calculations
# Count operates using three different approaches.
Oops, something went wrong.

0 comments on commit 7e3b4c1

Please sign in to comment.