Skip to content

Commit

Permalink
Merge pull request #713 from jonny64/master
Browse files Browse the repository at this point in the history
locale ru: add name.middleName with russian gender for russian passport (отчество)
  • Loading branch information
Marak authored Aug 28, 2020
2 parents a5a0e22 + 905e9b5 commit b2099af
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ function Name (faker) {
return faker.random.arrayElement(faker.definitions.name.last_name);
};

/**
* middleName
*
* @method middleName
* @param {mixed} gender
* @memberof faker.name
*/
this.middleName = function (gender) {
if (typeof faker.definitions.name.male_middle_name !== "undefined" && typeof faker.definitions.name.female_middle_name !== "undefined") {
if (typeof gender !== 'number') {
gender = faker.random.number(1);
}
if (gender === 0) {
return faker.random.arrayElement(faker.locales[faker.locale].name.male_middle_name);
} else {
return faker.random.arrayElement(faker.locales[faker.locale].name.female_middle_name);
}
}
return faker.random.arrayElement(faker.definitions.name.middle_name);
};

/**
* findName
*
Expand Down
45 changes: 45 additions & 0 deletions test/name.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,51 @@ describe("name.js", function () {
});
});

describe("middleName()", function () {

it("returns a random middle name", function () {
sinon.stub(faker.name, 'middleName').returns('foo');

var middle_name = faker.name.middleName();

assert.equal(middle_name, 'foo');

faker.name.middleName.restore();
});

describe('when using a locale with gender specific middle names', function () {
beforeEach(function(){
this.oldLocale = faker.locale;
faker.locale = 'TEST';

faker.locales['TEST'] = {
name: {
male_middle_name: ['Genaddiesvich'],
female_middle_name: ['Genaddievna']
}
};
});

afterEach(function () {
faker.locale = this.oldLocale;
delete faker.locale['TEST'];
})

it("returns male prefix", function () {
var middle_name = faker.name.middleName(0);

assert.equal(middle_name, 'Genaddiesvich')
});

it("returns female prefix", function () {
var middle_name = faker.name.middleName(1);

assert.equal(middle_name, 'Genaddievna');
});
});
});


describe("findName()", function () {
it("usually returns a first name and last name", function () {
sinon.stub(faker.random, 'number').returns(5);
Expand Down

0 comments on commit b2099af

Please sign in to comment.