Skip to content

Commit

Permalink
worked vows into sensible shape for translator
Browse files Browse the repository at this point in the history
  • Loading branch information
shackbarth committed Sep 4, 2012
1 parent c736e95 commit 63692b3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
14 changes: 1 addition & 13 deletions lib/ext/dictionary_route.js
Expand Up @@ -136,17 +136,6 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
);
},

testSave: function (xtr, callback) {
var DictionaryModel = this.get("model"),
dictionaryInstance = new DictionaryModel();

dictionaryInstance.lexicon = [];
dictionaryInstance.xTupleVersion = "4.0";
dictionaryInstance.languageName = "French";
dictionaryInstance.languageVersion = 1;
dictionaryInstance.save(callback);
},

/**
Saves a revision to a dictionary by comparing the translator's
submission with the previous existing dictionary and giving
Expand Down Expand Up @@ -190,7 +179,6 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */

maxVersionId = latestDictionary.languageVersion;
previousLexicon = latestDictionary.lexicon;

for (i = 0; i < previousLexicon.length; i++) {
previousEntry = previousLexicon[i];
key = previousEntry.key;
Expand Down Expand Up @@ -221,7 +209,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
if (error) {
return xtr.error({isError: true, reason: error});
} else {
xtr.write("Dictionary " + (maxVersionId + 1) + " save successful").close();
xtr.write(dictionaryInstance).close();
if (callback) {
callback(null, xtr);
}
Expand Down
63 changes: 50 additions & 13 deletions vows/dictionary_test.js
Expand Up @@ -87,51 +87,88 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
}
},

'after a dictionary instance is saved': {
'after a test dictionary instance is saved': {
topic: function () {
var seed = {
"lexicon": [],
"languageName": "French",
"languageVersion": 1,
"xTupleVersion": "4.0"
};
var jsonData = {languageName: "French", xTupleVersion: "4.0"},
var jsonData = {
languageName: "French",
xTupleVersion: "4.0",
lexicon: [
{key: "_order", translation: "Ordre", translator: "Seed"},
{key: "_number", translation: "", translator: "Seed"}
]
},
jsonFunction = function () { return jsonData; },
xtr = {
json: jsonFunction,
error: function (error) { this.errorLog += error.reason; },
errorLog: '',
write: function (data) { this.written += data; },
written: ''
};
X.dictionaryRoute.testSave(xtr, this.callback);
//var instance = dictionaryUtils.jsonToDictionaryInstance(seed);
//instance.save(this.callback);
},

DictionaryModel = X.dictionaryCache.model("Dictionary"),
dictionaryInstance = new DictionaryModel();

DictionaryModel.find({}).remove(); // clear out collection
// still figuring out where to do this kind of stuff if vows

dictionaryInstance.lexicon = xtr.json().lexicon;
dictionaryInstance.xTupleVersion = xtr.json().xTupleVersion;
dictionaryInstance.languageName = xtr.json().languageName;
dictionaryInstance.languageVersion = 1;
dictionaryInstance.save(this.callback);
},

'I can submit a valid update': {
topic: function (dictionary) {
// monkeypatch xtr
var jsonData = {languageName: "French", xTupleVersion: "4.0"},
var jsonData = {
languageName: "French",
xTupleVersion: "4.0",
lexicon: [
{key: "_order", translation: "Ordre"},
{key: "_number", translation: "Nombre"}
]
},
jsonFunction = function () { return jsonData; },
xtr = {
json: jsonFunction,
error: function (error) { this.errorLog += error.reason; },
errorLog: '',
write: function (data) {
this.written += data;
this.written = data;
return {close: function () {}};
},
written: ''
written: null
};

X.dictionaryRoute.save(xtr, this.callback);
},

'and when I do I get somewhere at least': function (error, result) {
assert.isNull(error);
assert.equal(result.errorLog, '');
assert.notEqual(result.written.length, 0);
'then we merge the dictionaries such that': {
'no error occurs': function (topic) {
assert.equal(topic.errorLog, '');
assert.isNotNull(topic.written);
},
'the lexicon keeps the unchanged translations with the old name but updates the new': function (topic) {
var lexicon = topic.written.lexicon,
order = X._.find(lexicon, function (entry) { return entry.key === '_order'; }),
number = X._.find(lexicon, function (entry) { return entry.key === '_number'; });

assert.equal(order.translator, 'Seed');
assert.equal(order.translation, 'Ordre');
assert.equal(number.translator, 'TranslatorNameFromSession');
assert.equal(number.translation, 'Nombre');
},
'the language version has been incremented': function (topic) {
assert.equal(topic.written.languageVersion, 2);
}
}
}
},
Expand Down

0 comments on commit 63692b3

Please sign in to comment.