Skip to content

Commit

Permalink
Fixed male/female split check on findName()
Browse files Browse the repository at this point in the history
(It was failing on locales that use a fallback)
  • Loading branch information
Ari Gesher committed Nov 20, 2014
1 parent 8bbe2ef commit ec87c45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var faker = require('../index');
var _name = {

firstName: function () {
if (typeof faker.locales[faker.locale].name.male_first_name !== "undefined" && typeof faker.locales[faker.locale].name.female_first_name !== "undefined") {
if (typeof faker.definitions.name.male_first_name !== "undefined" && typeof faker.definitions.name.female_first_name !== "undefined") {
// some locale datasets ( like ru ) have first_name split by gender. since the name.first_name field does not exist in these datasets,
// we must randomly pick a name from either gender array so faker.name.firstName will return the correct locale data ( and not fallback )
var rand = faker.random.number(1);
Expand All @@ -17,7 +17,7 @@ var _name = {
},

lastName: function () {
if (typeof faker.locales[faker.locale].name.male_last_name !== "undefined" && typeof faker.locales[faker.locale].name.female_last_name !== "undefined") {
if (typeof faker.definitions.name.male_last_name !== "undefined" && typeof faker.defintions.name.female_last_name !== "undefined") {
// some locale datasets ( like ru ) have last_name split by gender. i have no idea how last names can have genders, but also i do not speak russian
// see above comment of firstName method
var rand = faker.random.number(1);
Expand Down
6 changes: 6 additions & 0 deletions test/name.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,11 @@ describe("name.js", function () {

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

it("needs to work with specific locales and respect the fallbacks", function () {
faker.locale = 'en_US';
// this will throw if this is broken
var name = faker.name.findName();
});
});
});

0 comments on commit ec87c45

Please sign in to comment.