Skip to content

Commit

Permalink
Fixed bug in SC.ObjectController that would sometimes not commit all …
Browse files Browse the repository at this point in the history
…pending

changes because the model object would clear the changes hash.  Also a test
for this was added.  Closes sproutcore#66.  (Thanks YoNoSoyTu!)
  • Loading branch information
Charles Jolley committed Jul 20, 2008
1 parent d010008 commit aea6f6d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
4 changes: 4 additions & 0 deletions HISTORY
@@ -1,4 +1,8 @@

- Fixed bug in SC.ObjectController that would sometimes not commit all pending
changes because the model object would clear the changes hash. Also a test
for this was added. Closes #66. (Thanks YoNoSoyTu!)

- default index.html now has text/javascript added to script tags. Closes #71
- server.js now handles namespaced prefixes. Closes #74

Expand Down
15 changes: 9 additions & 6 deletions controllers/object.js
Expand Up @@ -147,16 +147,19 @@ SC.ObjectController = SC.Controller.extend(
} else {

if (content.beginPropertyChanges) content.beginPropertyChanges() ;
for(var key in this._changes) {
if (!this._changes.hasOwnProperty(key)) continue;

// save the set of changes to apply them. Nothing should clear it but
// just in case.
var changes = this._changes ;
for(var key in changes) {
if (!changes.hasOwnProperty(key)) continue;

var oldValue = content.get ? content.get(key) : content[key];
var newValue = this._changes[key];
var newValue = changes[key];

if (oldValue == null && newValue == '') newValue = null;
if (newValue != oldValue)
{
(content.set) ? content.set('isDirty', true) : (content['isDirty'] = true);
if (newValue != oldValue) {
(content.set) ? content.set('isDirty', YES) : (content.isDirty=YES);
}

if (content.set) {
Expand Down
26 changes: 26 additions & 0 deletions tests/controllers/object.rhtml
Expand Up @@ -236,6 +236,32 @@ Test.context("SC.ObjectController", {
this.single.didCommitChanges.shouldEqual(YES) ;
},
"Should update both values when commitChanges() on content objects" : function() {
cc = SC.CollectionController.create({
allowsEmptySelection: false,
allowsMultipleSelection: false
});
var oc = SC.ObjectController.create({
contentBinding: 'cc.selection',
commitChangesImmediately: false
});
var Contact = SC.Record.extend({});
var rcrds = Contact.collection();
cc.set('content', rcrds);
rcrds.refresh();
var single = Contact.create({'test' : 'NAME1', 'value' : 0});
rcrds.count().shouldEqual(1);
oc.set('test', 'NAME2');
oc.set('value', 123);
$ok(oc.commitChanges()).shouldEqual(YES);
single.get('test').shouldEqual('NAME2');
single.get('value').shouldEqual(123);
},
"Support content objects that implement SC.Array but are not arrays": function() {
this.c.set('content', this.dummy_a) ;
Expand Down

0 comments on commit aea6f6d

Please sign in to comment.