Skip to content

Commit

Permalink
added buildList to Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuklis committed Apr 2, 2013
1 parent 8b5c472 commit 0e0afd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/javascripts/rosie.spec.js
Expand Up @@ -46,6 +46,30 @@ describe('Factory', function() {
}); });
}); });


describe('buildList', function () {
beforeEach(function() {
Factory.define('thing').attr('name', 'Thing 1');
});

it('should return array of objects', function() {
expect(Factory.buildList('thing', 10).length).toEqual(10);
});

it('should return array of objects with attributes set', function() {
var things = Factory.buildList('thing', 10);
for(var i = 0; i < 10; i++) {
expect(things[i]).toEqual({name: 'Thing 1'});
}
});

it('should return array of objects with attributes set', function() {
var things = Factory.buildList('thing', 10, {name:'changed'});
for(var i = 0; i < 10; i++) {
expect(things[i]).toEqual({name: 'changed'});
}
});
});

describe('extend', function() { describe('extend', function() {
var Thing = function(attrs) { var Thing = function(attrs) {
for(var attr in attrs) { for(var attr in attrs) {
Expand Down
8 changes: 8 additions & 0 deletions src/rosie.js
Expand Up @@ -75,6 +75,14 @@ Factory.build = function(name, attrs, options) {
return obj; return obj;
}; };


Factory.buildList = function(name, size, attrs, options) {
var objs = [];
for(var i = 0; i < size; i++) {
objs.push(Factory.build(name, attrs, options));
}
return objs;
};

Factory.attributes = function(name, attrs) { Factory.attributes = function(name, attrs) {
return this.factories[name].attributes(attrs); return this.factories[name].attributes(attrs);
}; };
Expand Down

0 comments on commit 0e0afd1

Please sign in to comment.