Commit 49e5efe64497d75f242c46e1f4669a889b63ca9c

Fixed a smart_save bug. It didn't update the internal state reference variable on create og update

Commit diff

lib/couch_object/persistable.rb

 
383383 # Reset the do_not_load_has_many_relations variable
384384 # to it's original state
385385 @do_not_load_has_many_relations = state_before_wants_to_load_relations
386
386
387387 perform_callback(:after_save)
388388
389389 return the_return_value
403403
404404 db = CouchObject::Database.open(location)
405405
406 unless (response = db.post("", self.to_json)).to_document["error"]
406 json_value = self.to_json
407
408 unless (response = db.post("", json_value)).to_document["error"]
407409 response_document = response.to_document
408410 @id = response_document.id
409411 @revision = response_document.revision
414414 @updated_at = Time.now if self.
415415 class::couch_object_timestamp_on_update?
416416
417 # If the user has activated smart_save, we should set the state
418 # to the new contents of this instance!
419 @couch_object_original_state = json_value if use_smart_save
420
417421 perform_callback(:after_create)
418422
419423 # Returns a hash with the ID and Revision
457457
458458 db = CouchObject::Database.open(location)
459459
460 unless (response = db.put(id, self.to_json)).to_document["error"]
460 json_value = self.to_json
461
462 unless (response = db.put(id, json_value)).to_document["error"]
461463
462464 @revision = response.to_document.revision
463465
466 # If the user has activated smart_save, we should set the state
467 # to the new contents of this instance!
468 @couch_object_original_state = json_value if use_smart_save
469
464470 perform_callback(:after_update)
465471
466472 # Returns a hash with the ID and Revision
toggle raw diff

spec/persistable/unsaved_changes.rb

 
102102
103103 end
104104
105 it "should not have unsaved_changes after having been saved" do
106 response = HTTPResponse.new(@content_motor_bike)
107
108 @db.should_receive(:get).with("123BAC").and_return(response)
109 @db.should_receive(:put).and_return(@document_response)
110
111 mbike = OtherMotorBike.get_by_id("123BAC", "foo")
112
113 mbike.unsaved_changes?.should == false
114 mbike.wheels = 3
115 mbike.unsaved_changes?.should == true
116 mbike.save
117 mbike.unsaved_changes?.should == false
118
119 end
120
121
105122 it "should only save relations that need to be saved" do
106123
107124 response = HTTPResponse.new(@apartment_building_content)
toggle raw diff