Skip to content

Commit

Permalink
Fixed a bug where true values would fail looking for traits.
Browse files Browse the repository at this point in the history
- If a trait was passed with a true value, but wasn't
a trait, it could fail if the defined factory didn't have any
traits defined. Fixed that.

- Added tests. Bumped version. Remade gulp files.
  • Loading branch information
blakewest committed Dec 10, 2014
1 parent 9caba39 commit da14f49
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "replicator",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/hinthealth/replicator",
"authors": [
"Blake West <[email protected]>",
Expand Down
4 changes: 3 additions & 1 deletion dist/replicator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/replicator.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
};

function getPropsForOneTrait(factoryName, trait) {
// Shouldn't be needed. Just to be paranoid.
sharedTraits[factoryName] = sharedTraits[factoryName] || {};
return sharedTraits[factoryName][trait];
}

Expand Down Expand Up @@ -109,7 +111,7 @@
// Set on data store
sharedRegistry[factoryName] = props;
factoryCounts[factoryName] = 1;
trait[factoryName] = {};
sharedTraits[factoryName] = {};

return factory;
}
Expand Down
24 changes: 17 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,35 @@ describe('Replicator', function() {
describe('when passed a hash', function() {
describe('with values other than true', function() {
it('should set them as properties',function() {
Replicator.define('user', {is_confirmed: false});
Replicator.makeFactory('user', {is_confirmed: true})().is_confirmed.should.eql(true);
Replicator.define('user', {name: "joe"});
Replicator.makeFactory('user', {name: "blake"})().name.should.eql("blake");
});
});
describe('with true values', function() {
describe('that match traits', function() {
it('should set the traits', function() {
Replicator
.define('user', {name: 'Joe', is_confirmed: false})
.trait('is_confirmed', {is_confirmed: true, age: 18});
.trait('isConfirmed', {is_confirmed: true, age: 18});

Replicator.makeFactory('user', {is_confirmed: true})()
Replicator.makeFactory('user', {isConfirmed: true})()
.should.eql({name: 'Joe', is_confirmed: true, age: 18});
});
});
describe('that don\'t match traits', function() {
it('should set them as properties',function() {
Replicator.define('user', {is_confirmed: false});
Replicator.makeFactory('user', {is_confirmed: true})().is_confirmed.should.eql(true);
describe('but are valid properties', function() {
it('should set them as properties',function() {
Replicator.define('patient', {is_confirmed: false});
Replicator.makeFactory('patient', {is_confirmed: true})().is_confirmed.should.eql(true);
});
});
describe('but are not valid properties', function() {
it('should throw a helpful error message', function() {
Replicator.define('patient', {is_confirmed: false});
( function() {
Replicator.makeFactory('patient', {withPaymentMethod: true})().is_confirmed.should.eql(true);
}).should.throw(/unregistered/)
});
});
});
});
Expand Down

0 comments on commit da14f49

Please sign in to comment.