Changeset 5017
- Timestamp:
- 09/05/06 18:48:10 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/aggregations.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (16 diffs)
- trunk/activerecord/lib/active_record/associations/association_collection.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/associations/association_proxy.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/associations/belongs_to_association.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/associations/has_many_association.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/associations/has_one_association.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/base.rb (modified) (5 diffs)
- trunk/activerecord/lib/active_record/callbacks.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/locking/pessimistic.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/validations.rb (modified) (4 diffs)
- trunk/activerecord/test/associations_test.rb (modified) (23 diffs)
- trunk/activerecord/test/base_test.rb (modified) (5 diffs)
- trunk/activerecord/test/finder_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r5007 r5017 1 1 *SVN* 2 3 * Deprecated ActiveRecord::Base.new_record? in favor of ActiveRecord::Base.new? (old version still works until Rails 2.0) [DHH] 2 4 3 5 * Rename AR::Base#quote so people can use that name in their models. #3628 [Koz] trunk/activerecord/lib/active_record/aggregations.rb
r4561 r5017 8 8 self.class.reflect_on_all_aggregations.to_a.each do |assoc| 9 9 instance_variable_set "@#{assoc.name}", nil 10 end unless self.new _record?10 end unless self.new? 11 11 end 12 12 trunk/activerecord/lib/active_record/associations.rb
r5007 r5017 66 66 self.class.reflect_on_all_associations.to_a.each do |assoc| 67 67 instance_variable_set "@#{assoc.name}", nil 68 end unless self.new _record?68 end unless self.new? 69 69 end 70 70 … … 132 132 # 133 133 # * 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). 135 135 # * If either of these saves fail (due to one of the objects being invalid) the assignment statement returns false and the assignment 136 136 # is cancelled. … … 145 145 # * If saving any of the objects being added to a collection (via #push or similar) fails, then #push returns false. 146 146 # * 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. 148 148 # 149 149 # === Association callbacks … … 592 592 after_save <<-EOF 593 593 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) 595 595 association["#{reflection.primary_key_name}"] = id 596 596 association.save(true) … … 656 656 # belongs_to :attachable, :polymorphic => true 657 657 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 end663 664 658 reflection = create_belongs_to_reflection(association_id, options) 665 659 … … 671 665 association = instance_variable_get("@#{reflection.name}") 672 666 if association && association.target 673 if association.new _record?667 if association.new? 674 668 association.save(true) 675 669 end … … 691 685 association = instance_variable_get("@#{reflection.name}") 692 686 if !association.nil? 693 if association.new _record?687 if association.new? 694 688 association.save(true) 695 689 end … … 931 925 association = instance_variable_get("@#{association_name}") 932 926 if association.respond_to?(:loaded?) 933 if new _record?927 if new? 934 928 association 935 929 else 936 association.select { |record| record.new _record? }930 association.select { |record| record.new? } 937 931 end.each do |record| 938 932 errors.add "#{association_name}" unless record.valid? … … 942 936 943 937 validate method_name 944 before_save("@new_record_before_save = new _record?; true")938 before_save("@new_record_before_save = new?; true") 945 939 946 940 after_callback = <<-end_eval … … 951 945 records_to_save = association 952 946 else 953 records_to_save = association.select { |record| record.new _record? }947 records_to_save = association.select { |record| record.new? } 954 948 end 955 949 records_to_save.each { |record| association.send(:insert_record, record) } … … 998 992 if reflection.options[:exclusively_dependent] 999 993 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.") 1001 995 end 1002 996 … … 1458 1452 aliased_join_table_name, polymorphic_foreign_key, 1459 1453 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)] + 1461 1455 " LEFT OUTER JOIN %s ON %s.%s = %s.%s " % [table_name_and_alias, 1462 1456 aliased_table_name, primary_key, aliased_join_table_name, options[:foreign_key] || reflection.klass.to_s.classify.foreign_key … … 1473 1467 aliased_join_table_name, options[:foreign_key] || primary_key, 1474 1468 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) 1476 1470 ] 1477 1471 else … … 1502 1496 parent.aliased_table_name, parent.primary_key, 1503 1497 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) 1505 1499 ] 1506 1500 when reflection.macro == :has_one && reflection.options[:as] … … 1510 1504 parent.aliased_table_name, parent.primary_key, 1511 1505 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) 1513 1507 ] 1514 1508 else … … 1531 1525 aliased_table_name, 1532 1526 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? 1534 1528 join << "AND #{interpolate_sql(sanitize_sql(reflection.options[:conditions]))} " if reflection.options[:conditions] 1535 1529 join trunk/activerecord/lib/active_record/associations/association_collection.rb
r4791 r5017 24 24 raise_on_type_mismatch(record) 25 25 callback(:before_add, record) 26 result &&= insert_record(record) unless @owner.new _record?26 result &&= insert_record(record) unless @owner.new? 27 27 @target << record 28 28 callback(:after_add, record) … … 52 52 records = flatten_deeper(records) 53 53 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? } 55 55 return if records.empty? 56 56 … … 92 92 else 93 93 record = build(attributes) 94 record.save unless @owner.new _record?94 record.save unless @owner.new? 95 95 record 96 96 end … … 104 104 @target.size 105 105 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? }) 107 107 unsaved_records.size + count_records 108 108 else trunk/activerecord/lib/active_record/associations/association_proxy.rb
r4893 r5017 100 100 def set_belongs_to_association_for(record) 101 101 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? 103 103 record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s 104 104 else 105 record[@reflection.primary_key_name] = @owner.id unless @owner.new _record?105 record[@reflection.primary_key_name] = @owner.id unless @owner.new? 106 106 end 107 107 end … … 126 126 127 127 def load_target 128 if !loaded? and (!@owner.new _record? || foreign_key_present)128 if !loaded? and (!@owner.new? || foreign_key_present) 129 129 @target = find_target 130 130 end trunk/activerecord/lib/active_record/associations/belongs_to_association.rb
r3897 r5017 14 14 15 15 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? 17 17 @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] 18 18 end … … 22 22 raise_on_type_mismatch(record) 23 23 24 if counter_cache_name && !@owner.new _record?24 if counter_cache_name && !@owner.new? 25 25 @reflection.klass.increment_counter(counter_cache_name, record.id) 26 26 @reflection.klass.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] … … 28 28 29 29 @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? 31 31 @updated = true 32 32 end trunk/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
r3897 r5017 8 8 @target = (AssociationProxy === record ? record.target : record) 9 9 10 unless record.new _record?10 unless record.new? 11 11 @owner[@reflection.primary_key_name] = record.id 12 12 @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 20 20 else 21 21 record = build(attributes) 22 insert_record(record) unless @owner.new _record?22 insert_record(record) unless @owner.new? 23 23 record 24 24 end … … 76 76 77 77 callback(:before_add, record) 78 insert_record(record) unless @owner.new _record?78 insert_record(record) unless @owner.new? 79 79 @target << record 80 80 callback(:after_add, record) … … 102 102 103 103 def insert_record(record) 104 if record.new _record?104 if record.new? 105 105 return false unless record.save 106 106 end … … 119 119 else 120 120 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) 122 122 attributes[column.name] = value unless value.nil? 123 123 end trunk/activerecord/lib/active_record/associations/has_many_association.rb
r5007 r5017 112 112 113 113 def load_target 114 if !@owner.new _record? || foreign_key_present114 if !@owner.new? || foreign_key_present 115 115 begin 116 116 if !loaded? … … 185 185 @finder_sql = 186 186 "#{@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}" 188 188 @finder_sql << " AND (#{conditions})" if conditions 189 189 trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r5007 r5017 50 50 return if records.empty? 51 51 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? 53 53 54 54 load_target … … 58 58 flatten_deeper(records).each do |associate| 59 59 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? 61 61 62 62 @owner.send(@reflection.through_reflection.name).proxy_target << klass.with_scope(:create => construct_join_attributes(associate)) { klass.create! } … … 128 128 if as = reflection.options[:as] 129 129 { "#{as}_id" => @owner.quoted_id, 130 "#{as}_type" => reflection.klass.quote _value(130 "#{as}_type" => reflection.klass.quote( 131 131 @owner.class.base_class.name.to_s, 132 132 reflection.klass.columns_hash["#{as}_type"]) } … … 165 165 polymorphic_join = "AND %s.%s = %s" % [ 166 166 @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) 168 168 ] 169 169 end trunk/activerecord/lib/active_record/associations/has_one_association.rb
r5007 r5017 19 19 replace(record, true) 20 20 else 21 record[@reflection.primary_key_name] = @owner.id unless @owner.new _record?21 record[@reflection.primary_key_name] = @owner.id unless @owner.new? 22 22 self.target = record 23 23 end … … 31 31 unless @target.nil? 32 32 if dependent? && !dont_save && @target != obj 33 @target.destroy unless @target.new _record?33 @target.destroy unless @target.new? 34 34 @owner.clear_association_cache 35 35 else 36 36 @target[@reflection.primary_key_name] = nil 37 @target.save unless @owner.new _record? || @target.new_record?37 @target.save unless @owner.new? || @target.new? 38 38 end 39 39 end … … 49 49 @loaded = true 50 50 51 unless @owner.new _record? or obj.nil? or dont_save51 unless @owner.new? or obj.nil? or dont_save 52 52 return (obj.save ? self : false) 53 53 else … … 70 70 @finder_sql = 71 71 "#{@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}" 73 73 else 74 74 @finder_sql = "#{@reflection.table_name}.#{@reflection.primary_key_name} = #{@owner.quoted_id}" trunk/activerecord/lib/active_record/base.rb
r5007 r5017 184 184 # # No 'Winter' tag exists 185 185 # winter = Tag.find_or_initialize_by_name("Winter") 186 # winter.new _record? # true186 # winter.new? # true 187 187 # 188 188 # == Saving arrays, hashes, and other non-mappable objects in text columns … … 1519 1519 1520 1520 # 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? 1521 1526 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? 1523 1533 end 1524 1534 … … 1539 1549 # be made (since they can't be persisted). 1540 1550 def destroy 1541 unless new _record?1551 unless new? 1542 1552 connection.delete <<-end_sql, "#{self.class.name} Destroy" 1543 1553 DELETE FROM #{self.class.table_name} … … 1708 1718 (comparison_object.instance_of?(self.class) && 1709 1719 comparison_object.id == id && 1710 !comparison_object.new _record?)1720 !comparison_object.new?) 1711 1721 end 1712 1722 … … 1764 1774 private 1765 1775 def create_or_update 1766 if new _record? then create else update end1776 if new? then create else update end 1767 1777 true 1768 1778 end trunk/activerecord/lib/active_record/callbacks.rb
r4585 r5017 294 294 def valid_with_callbacks? #:nodoc: 295 295 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) end296 if new? then result = callback(:before_validation_on_create) else result = callback(:before_validation_on_update) end 297 297 return false if result == false 298 298 … … 300 300 301 301 callback(:after_validation) 302 if new _record? then callback(:after_validation_on_create) else callback(:after_validation_on_update) end302 if new? then callback(:after_validation_on_create) else callback(:after_validation_on_update) end 303 303 304 304 return result trunk/activerecord/lib/active_record/locking/pessimistic.rb
r4462 r5017 70 70 # the locked record. 71 71 def lock!(lock = true) 72 reload(:lock => lock) unless new _record?72 reload(:lock => lock) unless new? 73 73 self 74 74 end trunk/activerecord/lib/active_record/validations.rb
r4980 r5017 334 334 335 335 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") 338 337 end 339 338 end … … 376 375 # The first_name attribute must be in the object and it cannot be blank. 377 376 # 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? # => true381 #382 377 # Configuration options: 383 378 # * <tt>message</tt> - A custom error message (default is: "can't be blank") … … 544 539 end 545 540 end 546 unless record.new _record?541 unless record.new? 547 542 condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" 548 543 condition_params << record.send(:id) … … 778 773 validate 779 774 780 if new _record?775 if new? 781 776 run_validations(:validate_on_create) 782 777 validate_on_create trunk/activerecord/test/associations_test.rb
r4992 r5017 179 179 assert_equal [account_id], Account.destroyed_account_ids[firm.id] 180 180 end 181 181 182 182 def test_deprecated_exclusive_dependence 183 183 assert_deprecated(/:exclusively_dependent.*:dependent => :delete_all/) do … … 185 185 end 186 186 end 187 187 188 188 def test_exclusive_dependence 189 189 num_accounts = Account.count … … 245 245 account = firm.account.build("credit_limit" => 1000) 246 246 assert_equal account, firm.account 247 assert account.new _record?247 assert account.new? 248 248 assert firm.save 249 249 assert_equal account, firm.account 250 assert !account.new _record?250 assert !account.new? 251 251 end 252 252 … … 256 256 firm.account = account = Account.new("credit_limit" => 1000) 257 257 assert_equal account, firm.account 258 assert account.new _record?258 assert account.new? 259 259 assert firm.save 260 260 assert_equal account, firm.account 261 assert !account.new _record?261 assert !account.new? 262 262 end 263 263 … … 296 296 firm = Firm.new("name" => "GlobalMegaCorp") 297 297 firm.account = a = Account.find(1) 298 assert firm.new _record?298 assert firm.new? 299 299 assert_equal a, firm.account 300 300 assert firm.save … … 306 306 firm = Firm.find(1) 307 307 firm.account = a = Account.new("credit_limit" => 1000) 308 assert !a.new _record?308 assert !a.new? 309 309 assert_equal a, firm.account 310 310 assert_equal a, firm.account … … 315 315 firm = Firm.new("name" => "GlobalMegaCorp") 316 316 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? 319 319 assert_equal a, firm.account 320 320 assert firm.save 321 assert !firm.new _record?322 assert !a.new _record?321 assert !firm.new? 322 assert !a.new? 323 323 assert_equal a, firm.account 324 324 assert_equal a, firm.account(true) … … 351 351 end 352 352 353 def test_deprecated_inferred_foreign_key354 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 end359 360 353 end 361 354 … … 559 552 new_firm.clients_of_firm.push Client.new("name" => "Natural Company") 560 553 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? 563 556 assert_equal 2, new_firm.clients_of_firm.size 564 557 assert_equal no_of_firms, Firm.count # Firm was not saved to database. 565 558 assert_equal no_of_clients, Client.count # Clients were not saved to database. 566 559 assert new_firm.save 567 assert !new_firm.new _record?568 assert !c.new _record?560 assert !new_firm.new? 561 assert !c.new? 569 562 assert_equal new_firm, c.firm 570 563 assert_equal no_of_firms+1, Firm.count # Firm was saved to database. … … 577 570 firm = Firm.find(1) 578 571 assert !(firm.clients_of_firm << c = Client.new) 579 assert c.new _record?572 assert c.new? 580 573 assert !firm.valid? 581 574 assert !firm.save 582 assert c.new _record?575 assert c.new? 583 576 end 584 577 … … 588 581 new_firm = Firm.new("name" => "A New Firm, Inc") 589 582 new_firm.clients_of_firm.concat([c = Client.new, Client.new("name" => "Apple")]) 590 assert c.new _record?583 assert c.new? 591 584 assert !c.valid? 592 585 assert !new_firm.valid? 593 586 assert !new_firm.save 594 assert c.new _record?595 assert new_firm.new _record?587 assert c.new? 588 assert new_firm.new? 596 589 end 597 590 … … 599 592 new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client") 600 593 assert_equal "Another Client", new_client.name 601 assert new_client.new _record?594 assert new_client.new? 602 595 assert_equal new_client, companies(:first_firm).clients_of_firm.last 603 596 assert companies(:first_firm).save 604 assert !new_client.new _record?597 assert !new_client.new? 605 598 assert_equal 2, companies(:first_firm).clients_of_firm(true).size 606 599 end … … 645 638 def test_invalid_build 646 639 new_client = companies(:first_firm).clients_of_firm.build 647 assert new_client.new _record?640 assert new_client.new? 648 641 assert !new_client.valid? 649 642 assert_equal new_client, companies(:first_firm).clients_of_firm.last 650 643 assert !companies(:first_firm).save 651 assert new_client.new _record?644 assert new_client.new? 652 645 assert_equal 1, companies(:first_firm).clients_of_firm(true).size 653 646 end … … 656 649 force_signal37_to_load_all_clients_of_firm 657 650 new_client = companies(:first_firm).clients_of_firm.create("name" => "Another Client") 658 assert !new_client.new _record?651 assert !new_client.new? 659 652 assert_equal new_client, companies(:first_firm).clients_of_firm.last 660 653 assert_equal new_client, companies(:first_firm).clients_of_firm(true).last … … 1033 1026 client.firm = apple 1034 1027 assert_equal apple, client.firm 1035 assert apple.new _record?1028 assert apple.new? 1036 1029 assert client.save 1037 1030 assert apple.save 1038 assert !apple.new _record?1031 assert !apple.new? 1039 1032 assert_equal apple, client.firm 1040 1033 assert_equal apple, client.firm(true) … … 1045 1038 firm = Firm.find(1) 1046 1039 final_cut.firm = firm 1047 assert final_cut.new _record?1040 assert final_cut.new? 1048 1041 assert final_cut.save 1049 assert !final_cut.new _record?1050 assert !firm.new _record?1042 assert !final_cut.new? 1043 assert !firm.new? 1051 1044 assert_equal firm, final_cut.firm 1052 1045 assert_equal firm, final_cut.firm(true) … … 1057 1050 apple = Firm.new("name" => "Apple") 1058 1051 final_cut.firm = apple 1059 assert final_cut.new _record?1060 assert apple.new _record?1052 assert final_cut.new? 1053 assert apple.new? 1061 1054 assert final_cut.save 1062 assert !final_cut.new _record?1063 assert !apple.new _record?1055 assert !final_cut.new? 1056 assert !apple.new? 1064 1057 assert_equal apple, final_cut.firm 1065 1058 assert_equal apple, final_cut.firm(true) … … 1375 1368 aredridel = Developer.new("name" => "Aredridel") 1376 1369 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? 1379 1372 assert aredridel.save 1380 assert !aredridel.new _record?1373 assert !aredridel.new? 1381 1374 assert_equal no_of_devels+1, Developer.count 1382 1375 assert_equal no_of_projects+1, Project.count … … 1393 1386 p = Project.new("name" => "Foomatic") 1394 1387 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? 1397 1390 assert ken.save 1398 assert !ken.new _record?1391 assert !ken.new? 1399 1392 assert_equal no_of_devels+1, Developer.count 1400 1393 assert_equal no_of_projects+1, Project.count … … 1429 1422 proj = devel.projects.build("name" => "Projekt") 1430 1423 assert_equal devel.projects.last, proj 1431 assert proj.new _record?1424 assert proj.new? 1432 1425 devel.save 1433 assert !proj.new _record?1426 assert !proj.new? 1434 1427 assert_equal devel.projects.last, proj 1435 1428 assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated … … 1441 1434 proj2 = devel.projects.build(:name => "Lie in it") 1442 1435 assert_equal devel.projects.last, proj2 1443 assert proj2.new _record?1436 assert proj2.new? 1444 1437 devel.save 1445 assert !devel.new _record?1446 assert !proj2.new _record?1438 assert !devel.new? 1439 assert !proj2.new? 1447 1440 assert_equal devel.projects.last, proj2 1448 1441 assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated … … 1453 1446 proj = devel.projects.create("name" => "Projekt") 1454 1447 assert_equal devel.projects.last, proj 1455 assert !proj.new _record?1448 assert !proj.new? 1456 1449 assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated 1457 1450 end … … 1462 1455 proj2 = devel.projects.create(:name => "Lie in it") 1463 1456 assert_equal devel.projects.last, proj2 1464 assert proj2.new _record?1457 assert proj2.new? 1465 1458 devel.save 1466 assert !devel.new _record?1467 assert !proj2.new _record?1459 assert !devel.new? 1460 assert !proj2.new? 1468 1461 assert_equal devel.projects.last, proj2 1469 1462 assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated trunk/activerecord/test/base_test.rb
r4909 r5017 808 808 assert_nothing_raised { cloned_topic = topic.clone } 809 809 assert_equal topic.title, cloned_topic.title 810 assert cloned_topic.new _record?810 assert cloned_topic.new? 811 811 812 812 # test if the attributes have been cloned … … 823 823 824 824 cloned_topic.save 825 assert !cloned_topic.new _record?825 assert !cloned_topic.new? 826 826 assert cloned_topic.id != topic.id 827 827 end … … 835 835 assert_kind_of DeveloperSalary, clone.salary 836 836 assert_equal dev.salary.amount, clone.salary.amount 837 assert clone.new _record?837 assert clone.new? 838 838 839 839 # test if the attributes have been cloned … … 843 843 844 844 assert clone.save 845 assert !clone.new _record?845 assert !clone.new? 846 846 assert clone.id != dev.id 847 847 end … … 1340 1340 xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies) 1341 1341 assert xml.include?(%(<replies><reply>)) 1342 end1343 1344 def test_array_to_xml_including_methods1345 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>))1348 1342 end 1349 1343 trunk/activerecord/test/finder_test.rb
r4848 r5017 346 346 assert_equal number_of_companies + 1, Company.count 347 347 assert_equal sig38, Company.find_or_create_by_name("38signals") 348 assert !sig38.new _record?348 assert !sig38.new? 349 349 end 350 350 … … 354 354 assert_equal number_of_topics + 1, Topic.count 355 355 assert_equal another, Topic.find_or_create_by_title_and_author_name("Another topic", "John") 356 assert !another.new _record?356 assert !another.new? 357 357 end 358 358 … … 360 360 sig38 = Company.find_or_initialize_by_name("38signals") 361 361 assert_equal "38signals", sig38.name 362 assert sig38.new _record?362 assert sig38.new? 363 363 end 364 364 … … 367 367 assert_equal "Another topic", another.title 368 368 assert_equal "John", another.author_name 369 assert another.new _record?369 assert another.new? 370 370 end 371 371