Ticket #10537: add_new_record_method_to_ares.diff
| File add_new_record_method_to_ares.diff, 2.0 kB (added by EmmanuelOga, 8 months ago) |
|---|
-
test/base_test.rb
old new 301 301 assert_equal true, rick.save 302 302 assert_equal '5', rick.id 303 303 end 304 305 def test_new_record 306 rick = Person.new 307 308 # new_record? is an alias for new? to improve compatibility with ActionRecord 309 assert rick.new? && (rick.new? == rick.new_record?) 310 311 assert_equal true, rick.save 312 assert !rick.new? && (rick.new? == rick.new_record?) 313 end 304 314 305 315 def test_id_from_response 306 316 p = Person.new … … 350 360 end 351 361 assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') } 352 362 end 353 363 354 364 def test_update 355 365 matz = Person.find(:first) 356 366 matz.name = "David" -
lib/active_resource/base.rb
old new 553 553 def new? 554 554 id.nil? 555 555 end 556 557 # Alias for +new?+ 558 # 559 # This method is added for compatibility with ActiveRecord. 560 def new_record? 561 new? 562 end 556 563 557 564 # Get the +id+ attribute of the resource. 558 565 def id -
README
old new 123 123 ryan.new? #=> false 124 124 ryan.id #=> 2 125 125 126 In the previous example, +new?+ is used to verify the state of the record before and after saving it. 127 The same could be accomplished by using the +new_record?+ method instead. 128 +new_record?+ is an alias for +new?+ included for compatibility with ActiveRecord. 129 130 ryan = Person.new(:first => 'Ryan') 131 ryan.new_record? #=> true 132 ryan.save #=> true 133 ryan.new_record? #=> false 134 ryan.id #=> 2 135 126 136 ==== Update 127 137 128 138 'save' is also used to update an existing resource - and follows the same protocol as creating a resource