Skip to content
Browse files

Merge pull request #15 from mkuklis/build_list

added buildList to Factory
  • Loading branch information...
2 parents 8b5c472 + 0e0afd1 commit f9bf5d839b7d7d1f9ce02bd9d9d5f0e92fbd12dd @bkeepers bkeepers committed
Showing with 32 additions and 0 deletions.
  1. +24 −0 spec/javascripts/rosie.spec.js
  2. +8 −0 src/rosie.js
View
24 spec/javascripts/rosie.spec.js
@@ -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() {
var Thing = function(attrs) {
for(var attr in attrs) {
View
8 src/rosie.js
@@ -75,6 +75,14 @@ Factory.build = function(name, attrs, options) {
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) {
return this.factories[name].attributes(attrs);
};

0 comments on commit f9bf5d8

Please sign in to comment.
Something went wrong with that request. Please try again.