Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7402

Show
Ignore:
Timestamp:
09/03/07 00:17:09 (2 years ago)
Author:
nzkoz
Message:

Remove deprecated functionality from edge rails. Closes #9387 [lifofifo]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/associations.rb

    r7368 r7402  
    77require 'active_record/associations/has_many_through_association' 
    88require 'active_record/associations/has_and_belongs_to_many_association' 
    9 require 'active_record/deprecated_associations' 
    109 
    1110module ActiveRecord 
     
    626625      #   objects are deleted *without* calling their destroy method.  If set to <tt>:nullify</tt> all associated 
    627626      #   objects' foreign keys are set to +NULL+ *without* calling their save callbacks. 
    628       #   NOTE: <tt>:dependent => true</tt> is deprecated and has been replaced with <tt>:dependent => :destroy</tt>.  
    629627      #   May not be set if <tt>:exclusively_dependent</tt> is also set. 
    630       # * <tt>:exclusively_dependent</tt>   - Deprecated; equivalent to <tt>:dependent => :delete_all</tt>. If set to +true+ all 
    631       #   the associated objects are deleted in one SQL statement without having their 
    632       #   +before_destroy+ callback run. This should only be used on associations that depend solely on this class and don't need to do any 
    633       #   clean-up in +before_destroy+. The upside is that it's much faster, especially if there's a +counter_cache+ involved. 
    634       #   May not be set if <tt>:dependent</tt> is also set. 
    635628      # * <tt>:finder_sql</tt>  - specify a complete SQL statement to fetch the association. This is a good way to go for complex 
    636629      #   associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. 
     
    681674          collection_accessor_methods(reflection, HasManyAssociation) 
    682675        end 
    683  
    684         add_deprecated_api_for_has_many(reflection.name) 
    685676      end 
    686677 
     
    748739         
    749740        configure_dependency_for_has_one(reflection) 
    750  
    751         # deprecated api 
    752         deprecated_has_association_method(reflection.name) 
    753         deprecated_association_comparison_method(reflection.name, reflection.class_name) 
    754741      end 
    755742 
     
    839826            EOF 
    840827          end 
    841        
    842           # deprecated api 
    843           deprecated_has_association_method(reflection.name) 
    844           deprecated_association_comparison_method(reflection.name, reflection.class_name) 
    845828        end 
    846829 
     
    885868      # * <tt>collection<<(object, ...)</tt> - adds one or more objects to the collection by creating associations in the join table  
    886869      #   (<tt>collection.push</tt> and <tt>collection.concat</tt> are aliases to this method). 
    887       # * <tt>collection.push_with_attributes(object, join_attributes)</tt> - adds one to the collection by creating an association in the join table that 
    888       #   also holds the attributes from <tt>join_attributes</tt> (should be a hash with the column names as keys). This can be used to have additional 
    889       #   attributes on the join, which will be injected into the associated objects when they are retrieved through the collection. 
    890       #   (<tt>collection.concat_with_attributes</tt> is an alias to this method). This method is now deprecated. 
    891870      # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by removing their associations from the join table.   
    892871      #   This does not destroy the objects. 
     
    974953 
    975954        add_association_callbacks(reflection.name, options) 
    976          
    977         # deprecated api 
    978         deprecated_collection_count_method(reflection.name) 
    979         deprecated_add_association_relation(reflection.name) 
    980         deprecated_remove_association_relation(reflection.name) 
    981         deprecated_has_collection_method(reflection.name) 
    982955      end 
    983956 
     
    11421115 
    11431116        def configure_dependency_for_has_many(reflection) 
    1144           if reflection.options[:dependent] == true 
    1145             ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller) 
    1146           end 
    1147  
    1148           if reflection.options[:dependent] && reflection.options[:exclusively_dependent] 
    1149             raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.' 
    1150           end 
    1151  
    1152           if reflection.options[:exclusively_dependent] 
    1153             reflection.options[:dependent] = :delete_all 
    1154             ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller) 
    1155           end 
    1156  
    11571117          # See HasManyAssociation#delete_records.  Dependent associations 
    11581118          # delete children, otherwise foreign key is set to NULL. 
     
    11661126 
    11671127          case reflection.options[:dependent] 
    1168             when :destroy, true 
     1128            when :destroy 
    11691129              module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'" 
    11701130            when :delete_all 
     
    11721132            when :nullify 
    11731133              module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }" 
    1174             when nil, false 
     1134            when nil 
    11751135              # pass 
    11761136            else 
     
    11811141        def configure_dependency_for_has_one(reflection) 
    11821142          case reflection.options[:dependent] 
    1183             when :destroy, true 
     1143            when :destroy 
    11841144              module_eval "before_destroy '#{reflection.name}.destroy unless #{reflection.name}.nil?'" 
    11851145            when :delete 
     
    11871147            when :nullify 
    11881148              module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil) unless #{reflection.name}.nil?'" 
    1189             when nil, false 
     1149            when nil 
    11901150              # pass 
    11911151            else 
     
    11931153          end 
    11941154        end 
    1195          
    1196          
    1197         def add_deprecated_api_for_has_many(association_name) 
    1198           deprecated_collection_count_method(association_name) 
    1199           deprecated_add_association_relation(association_name) 
    1200           deprecated_remove_association_relation(association_name) 
    1201           deprecated_has_collection_method(association_name) 
    1202           deprecated_find_in_collection_method(association_name) 
    1203           deprecated_collection_create_method(association_name) 
    1204           deprecated_collection_build_method(association_name) 
    1205         end 
    12061155 
    12071156        def create_has_many_reflection(association_id, options, &extension) 
    12081157          options.assert_valid_keys( 
    12091158            :class_name, :table_name, :foreign_key, 
    1210             :exclusively_dependent, :dependent, 
     1159            :dependent, 
    12111160            :select, :conditions, :include, :order, :group, :limit, :offset, 
    12121161            :as, :through, :source, :source_type, 
  • trunk/activerecord/lib/active_record/validations.rb

    r7365 r7402  
    8383      end 
    8484    end 
    85  
    86     # Will add an error message to each of the attributes in +attributes+ that has a length outside of the passed boundary +range+. 
    87     # If the length is above the boundary, the too_long_msg message will be used. If below, the too_short_msg. 
    88     def add_on_boundary_breaking(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short]) 
    89       for attr in [attributes].flatten 
    90         value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s] 
    91         add(attr, too_short_msg % range.begin) if value && value.length < range.begin 
    92         add(attr, too_long_msg % range.end) if value && value.length > range.end 
    93       end 
    94     end 
    95  
    96     alias :add_on_boundry_breaking :add_on_boundary_breaking 
    97     deprecate :add_on_boundary_breaking => :validates_length_of, :add_on_boundry_breaking => :validates_length_of 
    9885 
    9986    # Returns true if the specified +attribute+ has errors associated with it. 
  • trunk/activerecord/test/associations_test.rb

    r7315 r7402  
    3131    firm.clients.each {|c|} # forcing to load all clients 
    3232    assert firm.clients.empty?, "New firm shouldn't have client objects" 
    33     assert_deprecated do 
    34       assert !firm.has_clients?, "New firm shouldn't have clients" 
    35     end 
    3633    assert_equal 0, firm.clients.size, "New firm should have 0 clients" 
    3734 
     
    4037 
    4138    assert firm.clients.empty?, "New firm should have cached no client objects" 
    42     assert_deprecated do 
    43       assert !firm.has_clients?, "New firm should have cached a no-clients response" 
    44     end 
    4539    assert_equal 0, firm.clients.size, "New firm should have cached 0 clients count" 
    4640 
     
    214208    assert_equal num_accounts - 1, Account.count 
    215209    assert_equal [account_id], Account.destroyed_account_ids[firm.id] 
    216   end 
    217  
    218   def test_deprecated_exclusive_dependence 
    219     assert_deprecated(/:exclusively_dependent.*:dependent => :delete_all/) do 
    220       Firm.has_many :deprecated_exclusively_dependent_clients, :class_name => 'Client', :exclusively_dependent => true 
    221     end 
    222210  end 
    223211 
  • trunk/activerecord/test/mixin_test.rb

    r7081 r7402  
    184184  fixtures :mixins 
    185185 
    186   def test_has_child 
    187     assert_deprecated 'has_children?' do 
    188       assert_equal true, mixins(:tree_1).has_children? 
    189       assert_equal true, mixins(:tree_2).has_children? 
    190       assert_equal false, mixins(:tree_3).has_children? 
    191       assert_equal false, mixins(:tree_4).has_children? 
    192     end 
    193   end 
    194  
    195186  def test_children 
    196187    assert_equal mixins(:tree_1).children, mixins(:tree_2, :tree_4) 
     
    198189    assert_equal mixins(:tree_3).children, [] 
    199190    assert_equal mixins(:tree_4).children, [] 
    200   end 
    201  
    202   def test_has_parent 
    203     assert_deprecated 'has_parent?' do 
    204       assert_equal false, mixins(:tree_1).has_parent? 
    205       assert_equal true, mixins(:tree_2).has_parent? 
    206       assert_equal true, mixins(:tree_3).has_parent? 
    207       assert_equal true, mixins(:tree_4).has_parent? 
    208     end 
    209191  end 
    210192 
  • trunk/activerecord/test/reflection_test.rb

    r7188 r7402  
    160160   
    161161  def test_reflection_of_all_associations 
    162     assert_equal 17, Firm.reflect_on_all_associations.size 
    163     assert_equal 15, Firm.reflect_on_all_associations(:has_many).size 
     162    assert_equal 16, Firm.reflect_on_all_associations.size 
     163    assert_equal 14, Firm.reflect_on_all_associations(:has_many).size 
    164164    assert_equal 2, Firm.reflect_on_all_associations(:has_one).size 
    165165    assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size 
  • trunk/activerecord/test/validations_test.rb

    r7365 r7402  
    652652    assert_equal 'tu est trops petit hombre 10', t.errors['title'] 
    653653  end 
    654    
    655   def test_add_on_boundary_breaking_is_deprecated 
    656     t = Topic.new('title' => 'noreplies', 'content' => 'whatever') 
    657     class << t 
    658       def validate 
    659         errors.add_on_boundary_breaking('title', 1..6) 
    660       end 
    661     end 
    662     assert_deprecated 'add_on_boundary_breaking' do 
    663       assert !t.valid? 
    664     end 
    665   end 
    666654 
    667655  def test_validates_size_of_association