Permalink
Browse files

Mongo store: create collection if not existing. Added dev packages. F…

…ixed default locales
  • Loading branch information...
1 parent 164d29a commit fd31aa67fc1a25d22b80fcacb422b1664578cfcb @masylum committed Jun 11, 2011
Showing with 30 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +3 −1 lib/dialect.js
  3. +11 −3 lib/stores/mongodb.js
  4. +10 −2 package.json
  5. +0 −1 test/dialect.js
  6. +5 −0 test/stores/mongodb.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -221,7 +221,9 @@ module.exports = function (options) {
// defaults
_options.base_locale = _options.base_locale || 'en';
_options.current_locale = _options.current_locale || 'en';
- _options.locales = _options.locales || [_options.base_locale, _options.current_locale];
+ _options.locales = _options.locales || (_options.base_locale === _options.current_locale
+ ? [_options.base_locale]
+ : [_options.base_locale, _options.current_locale]);
return DIALECT;
};
View
@@ -49,17 +49,25 @@ module.exports = function (options) {
callback = _default(callback);
+ function connect(err, collection) {
+ _is_connected = true;
+ STORE.collection = collection;
+ callback(err, collection);
+ }
+
if (!_is_connected) {
STORE.db.open(function (err, db) {
if (err) {
callback(err, null);
} else {
STORE.db.collection(options.collection || 'translations', function (err, collection) {
if (collection) {
- _is_connected = true;
- STORE.collection = collection;
+ connect(err, collection);
+ } else {
+ STORE.db.createCollection(options.collection || 'translations', function (err, collection) {
+ connect(err, collection);
+ });
}
- callback(err, collection);
});
}
});
View
@@ -1,9 +1,17 @@
{
"name": "dialect",
"description": "Translations manager for nodejs",
- "version": "1.0.1",
+ "version": "1.0.2",
"author": "Pau Ramon <masylum@gmail.com>",
- "dependencies": {"mongodb": ">=0.9.4", "funk": "1.0.1"},
+ "dependencies": {
+ "mongodb": "0.9.4",
+ "sqlite": "1.0.4",
+ "funk": "1.0.1"
+ },
+ "devDependencies": {
+ "testosterone": "1.2.0",
+ "gently": "0.9.1"
+ },
"repository" : {"type": "git" , "url": "http://github.com/masylum/dialect.git" },
"main": "./",
"engines": { "node": ">= 0.4.0" }
View
@@ -6,7 +6,6 @@ var testosterone = require('testosterone')({title: 'Dialect core', sync: true}),
_stubIO = function () {
var io = {};
gently.expect(gently.hijacked['./helpers/io'], 'IO', function () {
- gently.restore(gently.hijacked['./helpers/io'], 'IO');
return io;
});
return io;
@@ -35,7 +35,12 @@ testosterone
cb(null, db);
});
+ // no collection yet
gently.expect(store.db, 'collection', function (coll, cb) {
+ cb('blah', null);
+ });
+
+ gently.expect(store.db, 'createCollection', function (coll, cb) {
cb('blah', 'bar');
});

0 comments on commit fd31aa6

Please sign in to comment.