Skip to content

Commit

Permalink
Merge pull request #86 from stefanpenner/subword-uncountable-fix
Browse files Browse the repository at this point in the history
Corrected behaviour where words that contain uncountable subwords were being treated as uncountable words
  • Loading branch information
olivia committed Aug 16, 2015
2 parents 5eb8993 + 2fe334f commit 9fd8128
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
14 changes: 7 additions & 7 deletions addon/lib/system/inflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Ember from 'ember';
var capitalize = Ember.String.capitalize;

var BLANK_REGEX = /^\s*$/;
var LAST_WORD_DASHED_REGEX = /([\w/-]+[_/-])([a-z\d]+$)/;
var LAST_WORD_CAMELIZED_REGEX = /([\w/-]+)([A-Z][a-z\d]*$)/;
var LAST_WORD_DASHED_REGEX = /([\w/-]+[_/-\s])([a-z\d]+$)/;
var LAST_WORD_CAMELIZED_REGEX = /([\w/-\s]+)([A-Z][a-z\d]*$)/;
var CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;

function loadUncountable(rules, uncountable) {
Expand Down Expand Up @@ -241,7 +241,7 @@ Inflector.prototype = {
*/
inflect: function(word, typeRules, irregular) {
var inflection, substitution, result, lowercase, wordSplit,
firstPhrase, lastWord, isBlank, isCamelized, rule;
firstPhrase, lastWord, isBlank, isCamelized, rule, isUncountable;

isBlank = !word || BLANK_REGEX.test(word);

Expand All @@ -260,10 +260,10 @@ Inflector.prototype = {
lastWord = wordSplit[2].toLowerCase();
}

for (rule in this.rules.uncountable) {
if (lowercase.match(rule+"$")) {
return word;
}
isUncountable = this.rules.uncountable[lowercase] || this.rules.uncountable[lastWord];

if (isUncountable) {
return word;
}

for (rule in this.rules.irregular) {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-inflector",
"version": "1.8.0",
"version": "1.9.1",
"dependencies": {
"ember": "1.13.5",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-inflector",
"version": "1.9.0",
"version": "1.9.1",
"description": "ember-inflector goal is to be rails compatible.",
"directories": {
"doc": "doc",
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/inflector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ test('words containing irregular and uncountable words can be pluralized', funct
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
assert.equal(inflector.pluralize('woman'), 'women');
assert.equal(inflector.pluralize('salesperson'), 'salespeople');
assert.equal(inflector.pluralize('pufferfish'), 'pufferfish');
});


Expand All @@ -329,6 +328,16 @@ test('words containing irregular and uncountable words can be singularized', fun
assert.equal(inflector.singularize('pufferfish'), 'pufferfish');
});

test('partial words containing uncountable words can be pluralized', function(assert) {
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
assert.equal(inflector.pluralize('price'), 'prices');
});

test('partial words containing uncountable words can be singularized', function(assert) {
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
assert.equal(inflector.singularize('subspecies'), 'subspecy');
});

test('CamelCase and UpperCamelCase is preserved for irregular and uncountable pluralizations', function(assert) {
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
assert.equal(inflector.pluralize('SuperWoman'), 'SuperWomen');
Expand Down

0 comments on commit 9fd8128

Please sign in to comment.