From 348129692bf35e02495c3aa8b882cedfe79aefa6 Mon Sep 17 00:00:00 2001 From: kalle saas Date: Mon, 2 Jun 2014 14:41:32 +0200 Subject: [PATCH 1/2] add gruntjs for simplified test setup --- .gitignore | 1 + Gruntfile.js | 22 ++++++++++++++++++++++ README.md | 11 +++++++++++ package.json | 5 ++++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Gruntfile.js diff --git a/.gitignore b/.gitignore index daa6029..b7058f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ test.js +node_modules diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..4f4dca9 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,22 @@ +module.exports = function (grunt) { + grunt.initConfig({ + tape: { + options: { + pretty: false, + output: 'console' + }, + files: ['test/**/*.js'] + }, + watch: { + files: ['./supermodel.js', 'test/**/*.js'], + tasks: ['tape'], + } + }); + // Enable plugins + grunt.loadNpmTasks('grunt-tape'); + grunt.loadNpmTasks('grunt-contrib-watch'); + // register tasks + grunt.registerTask('test', ['tape']); + // default task + grunt.registerTask('default', ['test']); +}; diff --git a/README.md b/README.md index 1120c53..4e1a258 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,14 @@ Please see [pathable.github.com/supermodel][supermodel] for documentation. [supermodel]: http://pathable.github.com/supermodel [ci]: https://ci.testling.com/pathable/supermodel + + +## How to contribute + +* Fork this repository on GitHub +* Make sure you have [npm installed](https://www.npmjs.org/) +* Run `npm install` in the root directory +* Run the test suite with `grunt test` +* Write failing test +* Fix the test +* Submit a pull request diff --git a/package.json b/package.json index e58bb15..6904edd 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "uglify-js": "~2.4.11", "tape": "~2.4.2", "browserify": "~3.23.1", - "faucet": "0.0.0" + "faucet": "0.0.0", + "grunt": "~0.4.5", + "grunt-tape": "0.0.2", + "grunt-contrib-watch": "~0.6.1" }, "testling": { "files": "test/*.js", From 74fe5851fbfb49b32ac309e2d9137101ab1d0e1b Mon Sep 17 00:00:00 2001 From: kalle saas Date: Sun, 8 Jun 2014 16:29:52 +0200 Subject: [PATCH 2/2] adding failing test to validate issue #50 adding a model to an has.One and has.Many with an appropriate `source` attribute will result in an duplicated association length. --- test/has.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/has.js b/test/has.js index fa3ae5f..75c90e7 100644 --- a/test/has.js +++ b/test/has.js @@ -316,6 +316,13 @@ test('Many is initialized only once.', function(t) { t.end(); }); +test('has.One and has.Many should play nicly together', function(t) { + var user = User.create({id: 1}); + var memberships = user.memberships().add({id: 1, user_id: 1}) + t.is(user.memberships().length, 1); + t.end(); +}); + test('Source is removed after parsing.', function(t) { var user = User.create(); user.parse({memberships: [{id: 1}, {id: 2, hidden: true}]});