Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changes write to export. #4

Closed
wants to merge 1 commit into from

2 participants

Jerad Bitner Veselin Todorov
Jerad Bitner

Exports after every save.
Export uses path and defaults to /data/todo.txt

Jerad Bitner sirkitree Changes write to export.
Exports after every save.
Export uses path and defaults to /data/todo.txt
731111e
Jerad Bitner

I'll see if i can throw in some tests now.

Veselin Todorov
Owner

Thanks, man. I really appreciate it.

Jerad Bitner

So, I'll admit, I'm struggling here with the test. I can't seem to find a sine command for testing file creation. Can you give me a little direction on what exactly you think this should test? I've not gotten very far :( https://gist.github.com/1747985

Veselin Todorov
Owner

https://github.com/vesln/box/blob/master/test/storage.test.js#L85 This test is pretty similar. I hope it will give you some directions.

Jerad Bitner

Thanks that helped, and I'm close I think.

https://gist.github.com/1747985

However I'm still getting an error about the file not existing:
error

It seems I need to able to add in the file path as the argument to the .stub() but I'm not quite sure how. I tried using stub.withArgs() with no success.

Any more pointers?

Veselin Todorov vesln closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2012
  1. Jerad Bitner

    Changes write to export.

    sirkitree authored
    Exports after every save.
    Export uses path and defaults to /data/todo.txt
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 8 deletions.
  1. +1 −1  lib/app.js
  2. +1 −1  lib/cli.js
  3. +9 −6 lib/commands.js
2  lib/app.js
View
@@ -33,7 +33,7 @@ app.use(flatiron.plugins.cli, {
' todo undo 1 - Marks #1 item as not done yet.',
' todo clear - Clears the whole list.',
' todo version - Lib version.',
- ' todo write - Write items to file.',
+ ' todo export - Export items to file.',
'',
'Author: Veselin Todorov <hi@vesln.com>'
]
2  lib/cli.js
View
@@ -38,7 +38,7 @@ app.cmd(/undo (.+)/, commands.undo);
app.cmd(/rm (.+)/, commands.delete);
// Writes todo to file.
-app.cmd(/write (.+)/, commands.write);
+app.cmd(/export (.+)/, commands.export);
// Adds new todo item.
app.cmd(/(.+)/, commands.add);
15 lib/commands.js
View
@@ -43,7 +43,8 @@ var formatter = require('./formatter');
/**
* File writing.
*/
-var fs = require('fs');
+var fs = require('fs'),
+ path = require('path');
/**
* Prints current version.
@@ -112,6 +113,7 @@ commands.toggle = function(num, state) {
storage.set('items', items, function() {
storage.save(function(err) {
if (err) throw err;
+ commands.export();
});
});
});
@@ -131,6 +133,7 @@ commands.delete = function(num) {
storage.set('items', items, function() {
storage.save(function(err) {
if (err) throw err;
+ commands.export();
});
});
});
@@ -146,6 +149,7 @@ commands.clear = function(num) {
storage.set('items', [], function(err, items) {
storage.save(function(err) {
if (err) throw err;
+ commands.export();
});
});
};
@@ -163,6 +167,7 @@ commands.add = function(item) {
storage.set('items', items, function(err) {
storage.save(function(err) {
if (err) throw err;
+ commands.export();
});
});
});
@@ -174,10 +179,10 @@ commands.add = function(item) {
* @param {String} File location/name
* @api public
*/
-commands.write = function(filename) {
+commands.export = function(filename) {
var data = '';
if (!filename) {
- var filename = "~/todo.txt";
+ var filename = path.join(__dirname, '..', 'data', 'todo.txt');
}
var out = [];
storage.get('items', function(err, items) {
@@ -189,12 +194,10 @@ commands.write = function(filename) {
out.push('') && out.unshift('');
out.map(function(line) {
- console.log(line);
data += line +"\n";
});
fs.writeFile(filename, data, 'utf8', function(err, written) {
- if (err) return console.log(err);
-
+ if (err) throw err;
});
});
};
Something went wrong with that request. Please try again.