Skip to content

Commit

Permalink
Merge pull request #263 from tcollier/trim-street-name
Browse files Browse the repository at this point in the history
[fix] Only append suffix to streetName if suffix is present
  • Loading branch information
Marak committed Jul 31, 2015
2 parents ac4ad6d + cab6575 commit 381e5c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ function Address (faker) {

this.streetName = function () {
var result;
var suffix = faker.address.streetSuffix();
if (suffix !== "") {
suffix = " " + suffix
}

switch (faker.random.number(1)) {
case 0:
result = faker.name.lastName() + " " + faker.address.streetSuffix();
result = faker.name.lastName() + suffix;
break;
case 1:
result = faker.name.firstName() + " " + faker.address.streetSuffix();
result = faker.name.firstName() + suffix;
break;
}
return result;
Expand Down
13 changes: 12 additions & 1 deletion test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe("address.js", function () {
});

afterEach(function () {
faker.random.number.restore();
faker.name.firstName.restore();
faker.name.lastName.restore();
faker.address.streetSuffix.restore();
Expand All @@ -87,6 +86,8 @@ describe("address.js", function () {
assert.ok(!faker.name.firstName.called);
assert.ok(faker.name.lastName.calledOnce);
assert.ok(faker.address.streetSuffix.calledOnce);

faker.random.number.restore();
});

it("occasionally returns first name + suffix", function () {
Expand All @@ -98,6 +99,16 @@ describe("address.js", function () {
assert.ok(faker.name.firstName.calledOnce);
assert.ok(!faker.name.lastName.called);
assert.ok(faker.address.streetSuffix.calledOnce);

faker.random.number.restore();
});

it("trims trailing whitespace from the name", function() {
faker.address.streetSuffix.restore();

sinon.stub(faker.address, 'streetSuffix').returns("")
var street_name = faker.address.streetName();
assert.ok(!street_name.match(/ $/));
});
});

Expand Down

0 comments on commit 381e5c2

Please sign in to comment.