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

Changeset 5017

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

Deprecated ActiveRecord::Base.new_record? in favor of ActiveRecord::Base.new? (old version still works until Rails 2.0) [DHH]

Files:

Legend:

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

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

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

    r5007 r5017  
    6666      self.class.reflect_on_all_associations.to_a.each do |assoc| 
    6767        instance_variable_set "@#{assoc.name}", nil 
    68       end unless self.new_record
     68      end unless self.new
    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_record? == true). 
     134    #   order to update their primary keys - except if the parent object is unsaved (new? == 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_record? == true) members of the collection are automatically saved when the parent is saved. 
     147    # * All unsaved (new? == 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_record? || association.new_record? || association["#{reflection.primary_key_name}"] != id) 
     594            if !association.nil? && (new? || association.new? || 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          
    664658        reflection = create_belongs_to_reflection(association_id, options) 
    665659         
     
    671665              association = instance_variable_get("@#{reflection.name}") 
    672666              if association && association.target 
    673                 if association.new_record
     667                if association.new
    674668                  association.save(true) 
    675669                end 
     
    691685              association = instance_variable_get("@#{reflection.name}") 
    692686              if !association.nil?  
    693                 if association.new_record
     687                if association.new
    694688                  association.save(true) 
    695689                end 
     
    931925            association = instance_variable_get("@#{association_name}") 
    932926            if association.respond_to?(:loaded?) 
    933               if new_record
     927              if new
    934928                association 
    935929              else 
    936                 association.select { |record| record.new_record? } 
     930                association.select { |record| record.new? } 
    937931              end.each do |record| 
    938932                errors.add "#{association_name}" unless record.valid? 
     
    942936 
    943937          validate method_name 
    944           before_save("@new_record_before_save = new_record?; true") 
     938          before_save("@new_record_before_save = new?; true") 
    945939 
    946940          after_callback = <<-end_eval 
     
    951945                records_to_save = association 
    952946              else 
    953                 records_to_save = association.select { |record| record.new_record? } 
     947                records_to_save = association.select { |record| record.new? } 
    954948              end 
    955949              records_to_save.each { |record| association.send(:insert_record, record) } 
     
    998992          if reflection.options[:exclusively_dependent] 
    999993            reflection.options[:dependent] = :delete_all 
    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
     994            #warn "The :exclusively_dependent option is deprecated.  Please use :dependent => :delete_all instead."
    1001995          end 
    1002996 
     
    14581452                          aliased_join_table_name, polymorphic_foreign_key, 
    14591453                          parent.aliased_table_name, parent.primary_key, 
    1460                           aliased_join_table_name, polymorphic_foreign_type, klass.quote_value(parent.active_record.base_class.name)] + 
     1454                          aliased_join_table_name, polymorphic_foreign_type, klass.quote(parent.active_record.base_class.name)] + 
    14611455                        " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias, 
    14621456                          aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key 
     
    14731467                            aliased_join_table_name, options[:foreign_key] || primary_key, 
    14741468                            aliased_table_name, "#{source_reflection.options[:as]}_type",  
    1475                             klass.quote_value(source_reflection.active_record.base_class.name) 
     1469                            klass.quote(source_reflection.active_record.base_class.name) 
    14761470                          ] 
    14771471                        else 
     
    15021496                        parent.aliased_table_name, parent.primary_key, 
    15031497                        aliased_table_name, "#{reflection.options[:as]}_type", 
    1504                         klass.quote_value(parent.active_record.base_class.name) 
     1498                        klass.quote(parent.active_record.base_class.name) 
    15051499                      ] 
    15061500                    when reflection.macro == :has_one && reflection.options[:as] 
     
    15101504                        parent.aliased_table_name, parent.primary_key, 
    15111505                        aliased_table_name, "#{reflection.options[:as]}_type", 
    1512                         klass.quote_value(reflection.active_record.base_class.name) 
     1506                        klass.quote(reflection.active_record.base_class.name) 
    15131507                      ] 
    15141508                    else 
     
    15311525                aliased_table_name,  
    15321526                reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),  
    1533                 klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record? 
     1527                klass.quote(klass.name.demodulize)] unless klass.descends_from_active_record? 
    15341528              join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions] 
    15351529              join 
  • trunk/activerecord/lib/active_record/associations/association_collection.rb

    r4791 r5017  
    2424            raise_on_type_mismatch(record) 
    2525            callback(:before_add, record) 
    26             result &&= insert_record(record) unless @owner.new_record
     26            result &&= insert_record(record) unless @owner.new
    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_record? } 
     54        records.reject! { |record| @target.delete(record) if record.new? } 
    5555        return if records.empty? 
    5656         
     
    9292        else 
    9393          record = build(attributes) 
    94           record.save unless @owner.new_record
     94          record.save unless @owner.new
    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_record? }) 
     106          unsaved_records = Array(@target.detect { |r| r.new? }) 
    107107          unsaved_records.size + count_records 
    108108        else 
  • trunk/activerecord/lib/active_record/associations/association_proxy.rb

    r4893 r5017  
    100100        def set_belongs_to_association_for(record) 
    101101          if @reflection.options[:as] 
    102             record["#{@reflection.options[:as]}_id"]   = @owner.id unless @owner.new_record
     102            record["#{@reflection.options[:as]}_id"]   = @owner.id unless @owner.new
    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_record
     105            record[@reflection.primary_key_name] = @owner.id unless @owner.new
    106106          end 
    107107        end 
     
    126126 
    127127        def load_target 
    128           if !loaded? and (!@owner.new_record? || foreign_key_present) 
     128          if !loaded? and (!@owner.new? || foreign_key_present) 
    129129            @target = find_target 
    130130          end 
  • trunk/activerecord/lib/active_record/associations/belongs_to_association.rb

    r3897 r5017  
    1414 
    1515        if record.nil? 
    16           if counter_cache_name && @owner[counter_cache_name] && !@owner.new_record
     16          if counter_cache_name && @owner[counter_cache_name] && !@owner.new
    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_record
     24          if counter_cache_name && !@owner.new
    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_record
     30          @owner[@reflection.primary_key_name] = record.id unless record.new
    3131          @updated = true 
    3232        end 
  • trunk/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb

    r3897 r5017  
    88          @target = (AssociationProxy === record ? record.target : record) 
    99 
    10           unless record.new_record
     10          unless record.new
    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

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

    r5007 r5017  
    112112 
    113113        def load_target 
    114           if !@owner.new_record? || foreign_key_present 
     114          if !@owner.new? || 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_value(@owner.class.base_class.name.to_s)}" 
     187                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @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

    r5007 r5017  
    5050        return if records.empty? 
    5151        through = @reflection.through_reflection 
    52         raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new_record
     52        raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) if @owner.new
    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_record?) && !associate.new_record
     60            raise ActiveRecord::HasManyThroughCantAssociateNewRecords.new(@owner, through) unless associate.respond_to?(:new?) && !associate.new
    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_value
     130              "#{as}_type" => reflection.klass.quote
    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_value(@reflection.through_reflection.klass.name) 
     167                @owner.class.quote(@reflection.through_reflection.klass.name) 
    168168              ] 
    169169            end 
  • trunk/activerecord/lib/active_record/associations/has_one_association.rb

    r5007 r5017  
    1919          replace(record, true)  
    2020        else 
    21           record[@reflection.primary_key_name] = @owner.id unless @owner.new_record
     21          record[@reflection.primary_key_name] = @owner.id unless @owner.new
    2222          self.target = record 
    2323        end 
     
    3131        unless @target.nil? 
    3232          if dependent? && !dont_save && @target != obj 
    33             @target.destroy unless @target.new_record
     33            @target.destroy unless @target.new
    3434            @owner.clear_association_cache 
    3535          else 
    3636            @target[@reflection.primary_key_name] = nil 
    37             @target.save unless @owner.new_record? || @target.new_record
     37            @target.save unless @owner.new? || @target.new
    3838          end 
    3939        end 
     
    4949        @loaded = true 
    5050 
    51         unless @owner.new_record? or obj.nil? or dont_save 
     51        unless @owner.new? 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_value(@owner.class.base_class.name.to_s)}"           
     72                "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @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

    r5007 r5017  
    184184  #   # No 'Winter' tag exists 
    185185  #   winter = Tag.find_or_initialize_by_name("Winter") 
    186   #   winter.new_record? # true 
     186  #   winter.new? # 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? 
     1522        @new_record 
     1523      end 
     1524       
     1525      # Deprecated alias for new? 
    15211526      def new_record? 
    1522         @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? 
    15231533      end 
    15241534 
     
    15391549      # be made (since they can't be persisted). 
    15401550      def destroy 
    1541         unless new_record
     1551        unless new
    15421552          connection.delete <<-end_sql, "#{self.class.name} Destroy" 
    15431553            DELETE FROM #{self.class.table_name} 
     
    17081718          (comparison_object.instance_of?(self.class) &&  
    17091719            comparison_object.id == id &&  
    1710             !comparison_object.new_record?) 
     1720            !comparison_object.new?) 
    17111721      end 
    17121722 
     
    17641774    private 
    17651775      def create_or_update 
    1766         if new_record? then create else update end 
     1776        if new? then create else update end 
    17671777        true 
    17681778      end 
  • trunk/activerecord/lib/active_record/callbacks.rb

    r4585 r5017  
    294294    def valid_with_callbacks? #:nodoc: 
    295295      return false if callback(:before_validation) == false 
    296       if new_record? then result = callback(:before_validation_on_create) else result = callback(:before_validation_on_update) end 
     296      if new? 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_record? then callback(:after_validation_on_create) else callback(:after_validation_on_update) end 
     302      if new? 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

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

    r4980 r5017  
    334334 
    335335        validates_each(attr_names, configuration) do |record, attr_name, value| 
    336           confirm = record.send("#{attr_name}_confirmation") 
    337           record.errors.add(attr_name, configuration[:message]) unless value.nil? || value == confirm 
     336          record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation") 
    338337        end 
    339338      end 
     
    376375      # The first_name attribute must be in the object and it cannot be blank. 
    377376      #       
    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       # 
    382377      # Configuration options: 
    383378      # * <tt>message</tt> - A custom error message (default is: "can't be blank") 
     
    544539            end 
    545540          end 
    546           unless record.new_record
     541          unless record.new
    547542            condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" 
    548543            condition_params << record.send(:id) 
     
    778773      validate 
    779774 
    780       if new_record
     775      if new
    781776        run_validations(:validate_on_create) 
    782777        validate_on_create 
  • trunk/activerecord/test/associations_test.rb

    r4992 r5017  
    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_record
     247    assert account.new
    248248    assert firm.save 
    249249    assert_equal account, firm.account 
    250     assert !account.new_record
     250    assert !account.new
    251251  end 
    252252 
     
    256256    firm.account = account = Account.new("credit_limit" => 1000) 
    257257    assert_equal account, firm.account 
    258     assert account.new_record
     258    assert account.new
    259259    assert firm.save 
    260260    assert_equal account, firm.account 
    261     assert !account.new_record
     261    assert !account.new
    262262  end 
    263263 
     
    296296    firm = Firm.new("name" => "GlobalMegaCorp") 
    297297    firm.account = a = Account.find(1) 
    298     assert firm.new_record
     298    assert firm.new
    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_record
     308    assert !a.new
    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_record
    318     assert a.new_record
     317    assert firm.new
     318    assert a.new
    319319    assert_equal a, firm.account 
    320320    assert firm.save 
    321     assert !firm.new_record
    322     assert !a.new_record
     321    assert !firm.new
     322    assert !a.new
    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  
    360353end 
    361354 
     
    559552    new_firm.clients_of_firm.push Client.new("name" => "Natural Company") 
    560553    new_firm.clients_of_firm << (c = Client.new("name" => "Apple")) 
    561     assert new_firm.new_record
    562     assert c.new_record
     554    assert new_firm.new
     555    assert c.new
    563556    assert_equal 2, new_firm.clients_of_firm.size 
    564557    assert_equal no_of_firms, Firm.count      # Firm was not saved to database. 
    565558    assert_equal no_of_clients, Client.count  # Clients were not saved to database. 
    566559    assert new_firm.save 
    567     assert !new_firm.new_record
    568     assert !c.new_record
     560    assert !new_firm.new
     561    assert !c.new
    569562    assert_equal new_firm, c.firm 
    570563    assert_equal no_of_firms+1, Firm.count      # Firm was saved to database. 
     
    577570    firm = Firm.find(1) 
    578571    assert !(firm.clients_of_firm << c = Client.new) 
    579     assert c.new_record
     572    assert c.new
    580573    assert !firm.valid? 
    581574    assert !firm.save 
    582     assert c.new_record
     575    assert c.new
    583576  end 
    584577 
     
    588581    new_firm = Firm.new("name" => "A New Firm, Inc") 
    589582    new_firm.clients_of_firm.concat([c = Client.new, Client.new("name" => "Apple")]) 
    590     assert c.new_record
     583    assert c.new
    591584    assert !c.valid? 
    592585    assert !new_firm.valid? 
    593586    assert !new_firm.save 
    594     assert c.new_record
    595     assert new_firm.new_record
     587    assert c.new
     588    assert new_firm.new
    596589  end 
    597590 
     
    599592    new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client") 
    600593    assert_equal "Another Client", new_client.name 
    601     assert new_client.new_record
     594    assert new_client.new
    602595    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    603596    assert companies(:first_firm).save 
    604     assert !new_client.new_record
     597    assert !new_client.new
    605598    assert_equal 2, companies(:first_firm).clients_of_firm(true).size 
    606599  end 
     
    645638  def test_invalid_build 
    646639    new_client = companies(:first_firm).clients_of_firm.build 
    647     assert new_client.new_record
     640    assert new_client.new
    648641    assert !new_client.valid? 
    649642    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    650643    assert !companies(:first_firm).save 
    651     assert new_client.new_record
     644    assert new_client.new
    652645    assert_equal 1, companies(:first_firm).clients_of_firm(true).size 
    653646  end 
     
    656649    force_signal37_to_load_all_clients_of_firm 
    657650    new_client = companies(:first_firm).clients_of_firm.create("name" => "Another Client") 
    658     assert !new_client.new_record
     651    assert !new_client.new
    659652    assert_equal new_client, companies(:first_firm).clients_of_firm.last 
    660653    assert_equal new_client, companies(:first_firm).clients_of_firm(true).last 
     
    10331026    client.firm = apple 
    10341027    assert_equal apple, client.firm 
    1035     assert apple.new_record
     1028    assert apple.new
    10361029    assert client.save 
    10371030    assert apple.save 
    1038     assert !apple.new_record
     1031    assert !apple.new
    10391032    assert_equal apple, client.firm 
    10401033    assert_equal apple, client.firm(true) 
     
    10451038    firm = Firm.find(1) 
    10461039    final_cut.firm = firm 
    1047     assert final_cut.new_record
     1040    assert final_cut.new
    10481041    assert final_cut.save 
    1049     assert !final_cut.new_record
    1050     assert !firm.new_record
     1042    assert !final_cut.new
     1043    assert !firm.new
    10511044    assert_equal firm, final_cut.firm 
    10521045    assert_equal firm, final_cut.firm(true) 
     
    10571050    apple = Firm.new("name" => "Apple") 
    10581051    final_cut.firm = apple 
    1059     assert final_cut.new_record
    1060     assert apple.new_record
     1052    assert final_cut.new
     1053    assert apple.new
    10611054    assert final_cut.save 
    1062     assert !final_cut.new_record
    1063     assert !apple.new_record
     1055    assert !final_cut.new
     1056    assert !apple.new
    10641057    assert_equal apple, final_cut.firm 
    10651058    assert_equal apple, final_cut.firm(true) 
     
    13751368    aredridel = Developer.new("name" => "Aredridel") 
    13761369    aredridel.projects.concat([Project.find(1), p = Project.new("name" => "Projekt")]) 
    1377     assert aredridel.new_record
    1378     assert p.new_record
     1370    assert aredridel.new
     1371    assert p.new
    13791372    assert aredridel.save 
    1380     assert !aredridel.new_record
     1373    assert !aredridel.new
    13811374    assert_equal no_of_devels+1, Developer.count 
    13821375    assert_equal no_of_projects+1, Project.count 
     
    13931386    p = Project.new("name" => "Foomatic") 
    13941387    ken.projects.push_with_attributes( p, :joined_on => now ) 
    1395     assert ken.new_record
    1396     assert p.new_record
     1388    assert ken.new
     1389    assert p.new
    13971390    assert ken.save 
    1398     assert !ken.new_record
     1391    assert !ken.new
    13991392    assert_equal no_of_devels+1, Developer.count 
    14001393    assert_equal no_of_projects+1, Project.count 
     
    14291422    proj = devel.projects.build("name" => "Projekt") 
    14301423    assert_equal devel.projects.last, proj 
    1431     assert proj.new_record
     1424    assert proj.new
    14321425    devel.save 
    1433     assert !proj.new_record
     1426    assert !proj.new
    14341427    assert_equal devel.projects.last, proj 
    14351428    assert_equal Developer.find(1).projects.sort_by(&:id).last, proj  # prove join table is updated 
     
    14411434    proj2 = devel.projects.build(:name => "Lie in it") 
    14421435    assert_equal devel.projects.last, proj2 
    1443     assert proj2.new_record
     1436    assert proj2.new
    14441437    devel.save 
    1445     assert !devel.new_record
    1446     assert !proj2.new_record
     1438    assert !devel.new
     1439    assert !proj2.new
    14471440    assert_equal devel.projects.last, proj2 
    14481441    assert_equal Developer.find_by_name("Marcel").projects.last, proj2  # prove join table is updated 
     
    14531446    proj = devel.projects.create("name" => "Projekt") 
    14541447    assert_equal devel.projects.last, proj 
    1455     assert !proj.new_record
     1448    assert !proj.new
    14561449    assert_equal Developer.find(1).projects.sort_by(&:id).last, proj  # prove join table is updated 
    14571450  end 
     
    14621455    proj2 = devel.projects.create(:name => "Lie in it") 
    14631456    assert_equal devel.projects.last, proj2 
    1464     assert proj2.new_record
     1457    assert proj2.new
    14651458    devel.save 
    1466     assert !devel.new_record
    1467     assert !proj2.new_record
     1459    assert !devel.new
     1460    assert !proj2.new
    14681461    assert_equal devel.projects.last, proj2 
    14691462    assert_equal Developer.find_by_name("Marcel").projects.last, proj2  # prove join table is updated 
  • trunk/activerecord/test/base_test.rb

    r4909 r5017  
    808808    assert_nothing_raised { cloned_topic = topic.clone } 
    809809    assert_equal topic.title, cloned_topic.title 
    810     assert cloned_topic.new_record
     810    assert cloned_topic.new
    811811 
    812812    # test if the attributes have been cloned 
     
    823823 
    824824    cloned_topic.save 
    825     assert !cloned_topic.new_record
     825    assert !cloned_topic.new
    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_record
     837    assert clone.new
    838838 
    839839    # test if the attributes have been cloned 
     
    843843 
    844844    assert clone.save 
    845     assert !clone.new_record
     845    assert !clone.new
    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>)) 
    13481342  end 
    13491343   
  • trunk/activerecord/test/finder_test.rb

    r4848 r5017  
    346346    assert_equal number_of_companies + 1, Company.count 
    347347    assert_equal sig38, Company.find_or_create_by_name("38signals") 
    348     assert !sig38.new_record
     348    assert !sig38.new
    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_record
     356    assert !another.new
    357357  end 
    358358   
     
    360360    sig38 = Company.find_or_initialize_by_name("38signals") 
    361361    assert_equal "38signals", sig38.name 
    362     assert sig38.new_record
     362    assert sig38.new
    363363  end 
    364364   
     
    367367    assert_equal "Another topic", another.title 
    368368    assert_equal "John", another.author_name 
    369     assert another.new_record
     369    assert another.new
    370370  end 
    371371