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

Changeset 5018

Show
Ignore:
Timestamp:
09/05/06 18:54:24 (2 years ago)
Author:
david
Message:

Backed out of new_record? to new? transformation as it would screw up existing models that did boolean calls on "new" attributes [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r5017 r5018  
    11*SVN* 
    2  
    3 * Deprecated ActiveRecord::Base.new_record? in favor of ActiveRecord::Base.new? (old version still works until Rails 2.0) [DHH] 
    42 
    53* Rename AR::Base#quote so people can use that name in their models. #3628 [Koz] 
  • trunk/activerecord/lib/active_record/aggregations.rb

    r5017 r5018  
    88      self.class.reflect_on_all_aggregations.to_a.each do |assoc| 
    99        instance_variable_set "@#{assoc.name}", nil 
    10       end unless self.new
     10      end unless self.new_record
    1111    end 
    1212 
  • trunk/activerecord/lib/active_record/associations.rb

    r5017 r5018  
    6666      self.class.reflect_on_all_associations.to_a.each do |assoc| 
    6767        instance_variable_set "@#{assoc.name}", nil 
    68       end unless self.new
     68      end unless self.new_record
    6969    end 
    7070     
     
    132132    # 
    133133    # * Assigning an object to a has_one association automatically saves that object and the object being replaced (if there is one), in 
    134     #   order to update their primary keys - except if the parent object is unsaved (new? == true). 
     134    #   order to update their primary keys - except if the parent object is unsaved (new_record? == true). 
    135135    # * If either of these saves fail (due to one of the objects being invalid) the assignment statement returns false and the assignment 
    136136    #   is cancelled. 
     
    145145    # * If saving any of the objects being added to a collection (via #push or similar) fails, then #push returns false. 
    146146    # * You can add an object to a collection without automatically saving it by using the #collection.build method (documented below). 
    147     # * All unsaved (new? == true) members of the collection are automatically saved when the parent is saved. 
     147    # * All unsaved (new_record? == true) members of the collection are automatically saved when the parent is saved. 
    148148    # 
    149149    # === Association callbacks 
     
    592592          after_save <<-EOF 
    593593            association = instance_variable_get("@#{reflection.name}") 
    594             if !association.nil? && (new? || association.new? || association["#{reflection.primary_key_name}"] != id) 
     594            if !association.nil? && (new_record? || association.new_record? || association["#{reflection.primary_key_name}"] != id) 
    595595              association["#{reflection.primary_key_name}"] = id 
    596596              association.save(true) 
     
    656656      #   belongs_to :attachable, :polymorphic => true 
    657657      def belongs_to(association_id, options = {}) 
     658        if options.include?(:class_name) && !options.include?(:foreign_key) 
     659          ::ActiveSupport::Deprecation.warn( 
     660          "The inferred foreign_key name will change in Rails 2.0 to use the association name instead of its class name when they differ.  When using :class_name in belongs_to, use the :foreign_key option to explicitly set the key name to avoid problems in the transition.", 
     661          caller) 
     662        end 
     663         
    658664        reflection = create_belongs_to_reflection(association_id, options) 
    659665         
     
    665671              association = instance_variable_get("@#{reflection.name}") 
    666672              if association && association.target 
    667                 if association.new
     673                if association.new_record
    668674                  association.save(true) 
    669675                end 
     
    685691              association = instance_variable_get("@#{reflection.name}") 
    686692              if !association.nil?  
    687                 if association.new
     693                if association.new_record
    688694                  association.save(true) 
    689695                end 
     
    925931            association = instance_variable_get("@#{association_name}") 
    926932            if association.respond_to?(:loaded?) 
    927               if new
     933              if new_record
    928934                association 
    929935              else 
    930                 association.select { |record| record.new? } 
     936                association.select { |record| record.new_record? } 
    931937              end.each do |record| 
    932938                errors.add "#{association_name}" unless record.valid? 
     
    936942 
    937943          validate method_name 
    938           before_save("@new_record_before_save = new?; true") 
     944          before_save("@new_record_before_save = new_record?; true") 
    939945 
    940946          after_callback = <<-end_eval 
     
    945951                records_to_save = association 
    946952              else 
    947                 records_to_save = association.select { |record| record.new? } 
     953                records_to_save = association.select { |record| record.new_record? } 
    948954              end 
    949955              records_to_save.each { |record| association.send(:insert_record, record) } 
     
    992998          if reflection.options[:exclusively_dependent] 
    993999            reflection.options[:dependent] = :delete_all 
    994             #warn "The :exclusively_dependent option is deprecated.  Please use :dependent => :delete_all instead."
     1000            ::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
    9951001          end 
    9961002 
     
    14521458                          aliased_join_table_name, polymorphic_foreign_key, 
    14531459                          parent.aliased_table_name, parent.primary_key, 
    1454                           aliased_join_table_name, polymorphic_foreign_type, klass.quote(parent.active_record.base_class.name)] + 
     1460                          aliased_join_table_name, polymorphic_foreign_type, klass.quote_value(parent.active_record.base_class.name)] + 
    14551461                        " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias, 
    14561462                          aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key 
     
    14671473                            aliased_join_table_name, options[:foreign_key] || primary_key, 
    14681474                            aliased_table_name, "#{source_reflection.options[:as]}_type",  
    1469                             klass.quote(source_reflection.active_record.base_class.name) 
     1475                            klass.quote_value(source_reflection.active_record.base_class.name) 
    14701476                          ] 
    14711477                        else 
     
    14961502                        parent.aliased_table_name, parent.primary_key, 
    14971503                        aliased_table_name, "#{reflection.options[:as]}_type", 
    1498                         klass.quote(parent.active_record.base_class.name) 
     1504                        klass.quote_value(parent.active_record.base_class.name) 
    14991505                      ] 
    15001506                    when reflection.macro == :has_one && reflection.options[:as] 
     
    15041510                        parent.aliased_table_name, parent.primary_key, 
    15051511                        aliased_table_name, "#{reflection.options[:as]}_type", 
    1506                         klass.quote(reflection.active_record.base_class.name) 
     1512                        klass.quote_value(reflection.active_record.base_class.name) 
    15071513                      ] 
    15081514                    else 
     
    15251531                aliased_table_name,  
    15261532                reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),  
    1527                 klass.quote(klass.name.demodulize)] unless klass.descends_from_active_record? 
     1533                klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record? 
    15281534              join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions] 
    15291535              join 
  • trunk/activerecord/lib/active_record/associations/association_collection.rb

    r5017 r5018  
    2424            raise_on_type_mismatch(record) 
    2525            callback(:before_add, record) 
    26             result &&= insert_record(record) unless @owner.new
     26            result &&= insert_record(record) unless @owner.new_record
    2727            @target << record 
    2828            callback(:after_add, record) 
     
    5252        records = flatten_deeper(records) 
    5353        records.each { |record| raise_on_type_mismatch(record) } 
    54         records.reject! { |record| @target.delete(record) if record.new? } 
     54        records.reject! { |record| @target.delete(record) if record.new_record? } 
    5555        return if records.empty? 
    5656         
     
    9292        else 
    9393          record = build(attributes) 
    94           record.save unless @owner.new
     94          record.save unless @owner.new_record
    9595          record 
    9696        end 
     
    104104          @target.size 
    105105        elsif !loaded? && !@reflection.options[:uniq] && @target.is_a?(Array) 
    106           unsaved_records = Array(@target.detect { |r| r.new? }) 
     106          unsaved_records = Array(@target.detect { |r| r.new_record? }) 
    107107          unsaved_records.size + count_records 
    108108        else 
  • trunk/activerecord/lib/active_record/associations/association_proxy.rb

    r5017 r5018  
    100100        def set_belongs_to_association_for(record) 
    101101          if @reflection.options[:as] 
    102             record["#{@reflection.options[:as]}_id"]   = @owner.id unless @owner.new
     102            record["#{@reflection.options[:as]}_id"]   = @owner.id unless @owner.new_record
    103103            record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s 
    104104          else 
    105             record[@reflection.primary_key_name] = @owner.id unless @owner.new
     105            record[@reflection.primary_key_name] = @owner.id unless @owner.new_record
    106106          end 
    107107        end 
     
    126126 
    127127        def load_target 
    128           if !loaded? and (!@owner.new? || foreign_key_present) 
     128          if !loaded? and (!@owner.new_record? || foreign_key_present) 
    129129            @target = find_target 
    130130          end 
  • trunk/activerecord/lib/active_record/associations/belongs_to_association.rb

    r5017 r5018  
    1414 
    1515        if record.nil? 
    16           if counter_cache_name && @owner[counter_cache_name] && !@owner.new
     16          if counter_cache_name && @owner[counter_cache_name] && !@owner.new_record
    1717            @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] 
    1818          end 
     
    2222          raise_on_type_mismatch(record) 
    2323 
    24           if counter_cache_name && !@owner.new
     24          if counter_cache_name && !@owner.new_record
    2525            @reflection.klass.increment_counter(counter_cache_name, record.id) 
    2626            @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] 
     
    2828 
    2929          @target = (AssociationProxy === record ? record.target : record) 
    30           @owner[@reflection.primary_key_name] = record.id unless record.new
     30          @owner[@reflection.primary_key_name] = record.id unless record.new_record
    3131          @updated = true 
    3232        end 
  • trunk/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb

    r5017 r5018  
    88          @target = (AssociationProxy === record ? record.target : record) 
    99 
    10           unless record.new
     10          unless record.new_record
    1111            @owner[@reflection.primary_key_name] = record.id 
    1212            @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s 
  • trunk/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb

    r5017 r5018  
    2020        else 
    2121          record = build(attributes) 
    22           insert_record(record) unless @owner.new
     22          insert_record(record) unless @owner.new_record
    2323          record 
    2424        end 
     
    7676 
    7777        callback(:before_add, record) 
    78         insert_record(record) unless @owner.new
     78        insert_record(record) unless @owner.new_record
    7979        @target << record 
    8080        callback(:after_add, record) 
     
    102102 
    103103        def insert_record(record) 
    104           if record.new
     104          if record.new_record
    105105            return false unless record.save 
    106106          end 
     
    119119                else 
    120120                  if record.attributes.has_key?(column.name) 
    121                     value = @owner.send(:quote, record[column.name], column) 
     121                    value = @owner.send(:quote_value, record[column.name], column) 
    122122                    attributes[column.name] = value unless value.nil? 
    123123                  end 
  • trunk/activerecord/lib/active_record/associations/has_many_association.rb

    r5017 r5018  
    112112 
    113113        def load_target 
    114           if !@owner.new? || foreign_key_present 
     114          if !@owner.new_record? || foreign_key_present 
    115115            begin 
    116116              if !loaded? 
     
    185185              @finder_sql =  
    186186                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +  
    187                 "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}" 
     187                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}" 
    188188              @finder_sql << " AND (#{conditions})" if conditions 
    189189             
  • trunk/activerecord/lib/active_record/associations/has_many_through_association.rb

    r5017 r5018  
    5050        return if records.empty? 
    5151        through = @reflection.through_reflection 
    52         raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new
     52        raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new_record
    5353 
    5454        load_target 
     
    5858          flatten_deeper(records).each do |associate| 
    5959            raise_on_type_mismatch(associate) 
    60             raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) unless associate.respond_to?(:new?) && !associate.new
     60            raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) unless associate.respond_to?(:new_record?) && !associate.new_record
    6161 
    6262            @owner.send(@reflection.through_reflection.name).proxy_target << klass.with_scope(:create => construct_join_attributes(associate)) { klass.create! } 
     
    128128          if as = reflection.options[:as] 
    129129            { "#{as}_id" => @owner.quoted_id, 
    130               "#{as}_type" => reflection.klass.quote
     130              "#{as}_type" => reflection.klass.quote_value
    131131                @owner.class.base_class.name.to_s, 
    132132                reflection.klass.columns_hash["#{as}_type"]) } 
     
    165165              polymorphic_join = "AND %s.%s = %s" % [ 
    166166                @reflection.table_name, "#{@reflection.source_reflection.options[:as]}_type", 
    167                 @owner.class.quote(@reflection.through_reflection.klass.name) 
     167                @owner.class.quote_value(@reflection.through_reflection.klass.name) 
    168168              ] 
    169169            end 
  • trunk/activerecord/lib/active_record/associations/has_one_association.rb

    r5017 r5018  
    1919          replace(record, true)  
    2020        else 
    21           record[@reflection.primary_key_name] = @owner.id unless @owner.new
     21          record[@reflection.primary_key_name] = @owner.id unless @owner.new_record
    2222          self.target = record 
    2323        end 
     
    3131        unless @target.nil? 
    3232          if dependent? && !dont_save && @target != obj 
    33             @target.destroy unless @target.new
     33            @target.destroy unless @target.new_record
    3434            @owner.clear_association_cache 
    3535          else 
    3636            @target[@reflection.primary_key_name] = nil 
    37             @target.save unless @owner.new? || @target.new
     37            @target.save unless @owner.new_record? || @target.new_record
    3838          end 
    3939        end 
     
    4949        @loaded = true 
    5050 
    51         unless @owner.new? or obj.nil? or dont_save 
     51        unless @owner.new_record? or obj.nil? or dont_save 
    5252          return (obj.save ? self : false) 
    5353        else 
     
    7070              @finder_sql =  
    7171                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " +  
    72                 "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"           
     72                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"           
    7373            else 
    7474              @finder_sql = "#{@reflection.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}" 
  • trunk/activerecord/lib/active_record/base.rb

    r5017 r5018  
    184184  #   # No 'Winter' tag exists 
    185185  #   winter = Tag.find_or_initialize_by_name("Winter") 
    186   #   winter.new? # true 
     186  #   winter.new_record? # true 
    187187  # 
    188188  # == Saving arrays, hashes, and other non-mappable objects in text columns 
     
    15191519 
    15201520      # Returns true if this object hasn't been saved yet -- that is, a record for the object doesn't exist yet. 
    1521       def new
     1521      def new_record
    15221522        @new_record 
    1523       end 
    1524        
    1525       # Deprecated alias for new? 
    1526       def new_record? 
    1527         ActiveSupport::Deprecation.warn( 
    1528           "ActiveRecord::Base.new_record? has been deprecated and will be removed with Rails 2.0." + 
    1529           "Please use ActiveRecord::Base.new? instead.", caller 
    1530         ) 
    1531          
    1532         new? 
    15331523      end 
    15341524 
     
    15491539      # be made (since they can't be persisted). 
    15501540      def destroy 
    1551         unless new
     1541        unless new_record
    15521542          connection.delete <<-end_sql, "#{self.class.name} Destroy" 
    15531543            DELETE FROM #{self.class.table_name} 
     
    17181708          (comparison_object.instance_of?(self.class) &&  
    17191709            comparison_object.id == id &&  
    1720             !comparison_object.new?) 
     1710            !comparison_object.new_record?) 
    17211711      end 
    17221712 
     
    17741764    private 
    17751765      def create_or_update 
    1776         if new? then create else update end 
     1766        if new_record? then create else update end 
    17771767        true 
    17781768      end 
  • trunk/activerecord/lib/active_record/callbacks.rb

    r5017 r5018  
    294294    def valid_with_callbacks? #:nodoc: 
    295295      return false if callback(:before_validation) == false 
    296       if new? then result = callback(:before_validation_on_create) else result = callback(:before_validation_on_update) end 
     296      if new_record? then result = callback(:before_validation_on_create) else result = callback(:before_validation_on_update) end 
    297297      return false if result == false 
    298298 
     
    300300 
    301301      callback(:after_validation) 
    302       if new? then callback(:after_validation_on_create) else callback(:after_validation_on_update) end 
     302      if new_record? then callback(:after_validation_on_create) else callback(:after_validation_on_update) end 
    303303 
    304304      return result 
  • trunk/activerecord/lib/active_record/locking/pessimistic.rb

    r5017 r5018  
    7070      # the locked record. 
    7171      def lock!(lock = true) 
    72         reload(:lock => lock) unless new
     72        reload(:lock => lock) unless new_record
    7373        self 
    7474      end 
  • trunk/activerecord/lib/active_record/validations.rb

    r5017 r5018  
    334334 
    335335        validates_each(attr_names, configuration) do |record, attr_name, value| 
    336           record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation") 
     336          confirm = record.send("#{attr_name}_confirmation") 
     337          record.errors.add(attr_name, configuration[:message]) unless value.nil? || value == confirm 
    337338        end 
    338339      end 
     
    375376      # The first_name attribute must be in the object and it cannot be blank. 
    376377      #       
     378      # If you want to validate the presence of a boolean field (where the real values are true and false), 
     379      # you will want to use validates_inclusion_of :field_name, :in => [true, false] 
     380      # This is due to the way Object#blank? handles boolean values. false.blank? # => true 
     381      # 
    377382      # Configuration options: 
    378383      # * <tt>message</tt> - A custom error message (default is: "can't be blank") 
     
    539544            end 
    540545          end 
    541           unless record.new
     546          unless record.new_record
    542547            condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" 
    543548            condition_params << record.send(:id) 
     
    773778      validate 
    774779 
    775       if new
     780      if new_record
    776781        run_validations(:validate_on_create) 
    777782        validate_on_create 
  • trunk/activerecord/test/associations_test.rb

    r5017 r5018  
    179179    assert_equal [account_id], Account.destroyed_account_ids[firm.id] 
    180180  end 
    181    
     181 
    182182  def test_deprecated_exclusive_dependence 
    183183    assert_deprecated(/:exclusively_dependent.*:dependent => :delete_all/) do 
     
    185185    end 
    186186  end 
    187    
     187 
    188188  def test_exclusive_dependence 
    189189    num_accounts = Account.count 
     
    245245    account = firm.account.build("credit_limit" => 1000) 
    246246    assert_equal account, firm.account 
    247     assert account.new
     247    assert account.new_record
    248248    assert firm.save 
    249249    assert_equal account, firm.account 
    250     assert !account.new
     250    assert !account.new_record
    251251  end 
    252252 
     
    256256    firm.account = account = Account.new("credit_limit" => 1000) 
    257257    assert_equal account, firm.account 
    258     assert account.new
     258    assert account.new_record
    259259    assert firm.save 
    260260    assert_equal account, firm.account 
    261     assert !account.new
     261    assert !account.new_record
    262262  end 
    263263 
     
    296296    firm = Firm.new("name" => "GlobalMegaCorp") 
    297297    firm.account = a = Account.find(1) 
    298     assert firm.new
     298    assert firm.new_record
    299299    assert_equal a, firm.account 
    300300    assert firm.save 
     
    306306    firm = Firm.find(1) 
    307307    firm.account = a = Account.new("credit_limit" => 1000) 
    308     assert !a.new
     308    assert !a.new_record
    309309    assert_equal a, firm.account 
    310310    assert_equal a, firm.account 
     
    315315    firm = Firm.new("name" => "GlobalMegaCorp") 
    316316    firm.account = a = Account.new("credit_limit" => 1000) 
    317     assert firm.new
    318     assert a.new
     317    assert firm.new_record
     318    assert a.new_record
    319319    assert_equal a, firm.account 
    320320    assert firm.save 
    321     assert !firm.new
    322     assert !a.new
     321    assert !firm.new_record
     322    assert !a.new_record
    323323    assert_equal a, firm.account 
    324324    assert_equal a, firm.account(true) 
     
    351351  end 
    352352   
     353  def test_deprecated_inferred_foreign_key 
     354    assert_not_deprecated { Company.belongs_to :firm } 
     355    assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" } 
     356    assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" } 
     357    assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" } 
     358  end 
     359 
    353360end 
    354361 
     
    552559    new_firm.clients_of_firm.push Client.new("name" => "Natural Company") 
    553560    new_firm.clients_of_firm << (c = Client.new("name" => "Apple")) 
    554     assert new_firm.new
    555     assert c.new
     561    assert new_firm.new_record
     562    assert c.new_record
    556563    assert_equal 2, new_firm.clients_of_firm.size 
    557564    assert_equal no_of_firms, Firm.count      # Firm was not saved to database. 
    558565    assert_equal no_of_clients, Client.count  # Clients were not saved to database. 
    559566    assert new_firm.save 
    560     assert !new_firm.new
    561     assert !c.new
     567    assert !new_firm.new_record
     568    assert !c.new_record
    562569    assert_equal new_firm, c.firm 
    563570    assert_equal no_of_firms+1, Firm.count      # Firm was saved to database. 
     
    570577    firm = Firm.find(1) 
    571578    assert !(firm.clients_of_firm << c = Client.new) 
    572     assert c.new
     579    assert c.new_record
    573580    assert !firm.valid? 
    574581    assert !firm.save 
    575     assert c.new
     582    assert c.new_record
    576583  end 
    577584 
     
    581588    new_firm = Firm.new("name" => "A New Firm, Inc") 
    582589    new_firm.clients_of_firm.concat([c = Client.new, Client.new("name" => "Apple")]) 
    583     assert c.new
     590    assert c.new_record
    584591    assert !c.valid? 
    585592    assert !new_firm.valid? 
    586593    assert !new_firm.save 
    587     assert c.new
    588     assert new_firm.new
     594    assert c.new_record
     595    assert new_firm.new_record
    589596  end 
    590597 
     
    592599    new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client") 
    593600    assert_equal "Another Client", new_client.name 
    594     assert new_client.new
     601    assert new_client.new_record
    595602    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    596603    assert companies(:first_firm).save 
    597     assert !new_client.new
     604    assert !new_client.new_record
    598605    assert_equal 2, companies(:first_firm).clients_of_firm(true).size 
    599606  end 
     
    638645  def test_invalid_build 
    639646    new_client = companies(:first_firm).clients_of_firm.build 
    640     assert new_client.new
     647    assert new_client.new_record
    641648    assert !new_client.valid? 
    642649    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    643650    assert !companies(:first_firm).save 
    644     assert new_client.new
     651    assert new_client.new_record
    645652    assert_equal 1, companies(:first_firm).clients_of_firm(true).size 
    646653  end 
     
    649656    force_signal37_to_load_all_clients_of_firm 
    650657    new_client = companies(:first_firm).clients_of_firm.create("name" => "Another Client") 
    651     assert !new_client.new
     658    assert !new_client.new_record
    652659    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    653660    assert_equal new_client, companies(:first_firm).clients_of_firm(true).last 
     
    10261033    client.firm = apple 
    10271034    assert_equal apple, client.firm 
    1028     assert apple.new
     1035    assert apple.new_record
    10291036    assert client.save 
    10301037    assert apple.save 
    1031     assert !apple.new
     1038    assert !apple.new_record
    10321039    assert_equal apple, client.firm 
    10331040    assert_equal apple, client.firm(true) 
     
    10381045    firm = Firm.find(1) 
    10391046    final_cut.firm = firm 
    1040     assert final_cut.new
     1047    assert final_cut.new_record
    10411048    assert final_cut.save 
    1042     assert !final_cut.new
    1043     assert !firm.new
     1049    assert !final_cut.new_record
     1050    assert !firm.new_record
    10441051    assert_equal firm, final_cut.firm 
    10451052    assert_equal firm, final_cut.firm(true) 
     
    10501057    apple = Firm.new("name" => "Apple") 
    10511058    final_cut.firm = apple 
    1052     assert final_cut.new
    1053     assert apple.new
     1059    assert final_cut.new_record
     1060    assert apple.new_record
    10541061    assert final_cut.save 
    1055     assert !final_cut.new
    1056     assert !apple.new
     1062    assert !final_cut.new_record
     1063    assert !apple.new_record
    10571064    assert_equal apple, final_cut.firm 
    10581065    assert_equal apple, final_cut.firm(true) 
     
    13681375    aredridel = Developer.new("name" => "Aredridel") 
    13691376    aredridel.projects.concat([Project.find(1), p = Project.new("name" => "Projekt")]) 
    1370     assert aredridel.new
    1371     assert p.new
     1377    assert aredridel.new_record
     1378    assert p.new_record
    13721379    assert aredridel.save 
    1373     assert !aredridel.new
     1380    assert !aredridel.new_record
    13741381    assert_equal no_of_devels+1, Developer.count 
    13751382    assert_equal no_of_projects+1, Project.count 
     
    13861393    p = Project.new("name" => "Foomatic") 
    13871394    ken.projects.push_with_attributes( p, :joined_on => now ) 
    1388     assert ken.new
    1389     assert p.new
     1395    assert ken.new_record
     1396    assert p.new_record
    13901397    assert ken.save 
    1391     assert !ken.new
     1398    assert !ken.new_record
    13921399    assert_equal no_of_devels+1, Developer.count 
    13931400    assert_equal no_of_projects+1, Project.count 
     
    14221429    proj = devel.projects.build("name" => "Projekt") 
    14231430    assert_equal devel.projects.last, proj 
    1424     assert proj.new
     1431    assert proj.new_record
    14251432    devel.save 
    1426     assert !proj.new
     1433    assert !proj.new_record
    14271434    assert_equal devel.projects.last, proj 
    14281435    assert_equal Developer.find(1).projects.sort_by(&:id).last, proj  # prove join table is updated 
     
    14341441    proj2 = devel.projects.build(:name => "Lie in it") 
    14351442    assert_equal devel.projects.last, proj2 
    1436     assert proj2.new
     1443    assert proj2.new_record
    14371444    devel.save 
    1438     assert !devel.new
    1439     assert !proj2.new
     1445    assert !devel.new_record
     1446    assert !proj2.new_record
    14401447    assert_equal devel.projects.last, proj2 
    14411448    assert_equal Developer.find_by_name("Marcel").projects.last, proj2  # prove join table is updated 
     
    14461453    proj = devel.projects.create("name" => "Projekt") 
    14471454    assert_equal devel.projects.last, proj 
    1448     assert !proj.new
     1455    assert !proj.new_record
    14491456    assert_equal Developer.find(1).projects.sort_by(&:id).last, proj  # prove join table is updated 
    14501457  end 
     
    14551462    proj2 = devel.projects.create(:name => "Lie in it") 
    14561463    assert_equal devel.projects.last, proj2 
    1457     assert proj2.new
     1464    assert proj2.new_record
    14581465    devel.save 
    1459     assert !devel.new
    1460     assert !proj2.new
     1466    assert !devel.new_record
     1467    assert !proj2.new_record
    14611468    assert_equal devel.projects.last, proj2 
    14621469    assert_equal Developer.find_by_name("Marcel").projects.last, proj2  # prove join table is updated 
  • trunk/activerecord/test/base_test.rb

    r5017 r5018  
    808808    assert_nothing_raised { cloned_topic = topic.clone } 
    809809    assert_equal topic.title, cloned_topic.title 
    810     assert cloned_topic.new
     810    assert cloned_topic.new_record
    811811 
    812812    # test if the attributes have been cloned 
     
    823823 
    824824    cloned_topic.save 
    825     assert !cloned_topic.new
     825    assert !cloned_topic.new_record
    826826    assert cloned_topic.id != topic.id 
    827827  end 
     
    835835    assert_kind_of DeveloperSalary, clone.salary 
    836836    assert_equal dev.salary.amount, clone.salary.amount 
    837     assert clone.new
     837    assert clone.new_record
    838838 
    839839    # test if the attributes have been cloned 
     
    843843 
    844844    assert clone.save 
    845     assert !clone.new
     845    assert !clone.new_record
    846846    assert clone.id != dev.id 
    847847  end 
     
    13401340    xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies) 
    13411341    assert xml.include?(%(<replies><reply>)) 
     1342  end 
     1343 
     1344  def test_array_to_xml_including_methods 
     1345    xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :methods => [ :topic_id ]) 
     1346    assert xml.include?(%(<topic-id type="integer">#{topics(:first).topic_id}</topic-id>)) 
     1347    assert xml.include?(%(<topic-id type="integer">#{topics(:second).topic_id}</topic-id>)) 
    13421348  end 
    13431349   
  • trunk/activerecord/test/finder_test.rb

    r5017 r5018  
    346346    assert_equal number_of_companies + 1, Company.count 
    347347    assert_equal sig38, Company.find_or_create_by_name("38signals") 
    348     assert !sig38.new
     348    assert !sig38.new_record
    349349  end 
    350350 
     
    354354    assert_equal number_of_topics + 1, Topic.count 
    355355    assert_equal another, Topic.find_or_create_by_title_and_author_name("Another topic", "John") 
    356     assert !another.new
     356    assert !another.new_record
    357357  end 
    358358   
     
    360360    sig38 = Company.find_or_initialize_by_name("38signals") 
    361361    assert_equal "38signals", sig38.name 
    362     assert sig38.new
     362    assert sig38.new_record
    363363  end 
    364364   
     
    367367    assert_equal "Another topic", another.title 
    368368    assert_equal "John", another.author_name 
    369     assert another.new
     369    assert another.new_record
    370370  end 
    371371