Skip to content

Commit

Permalink
Merge pull request #96 from HeroicEric/correctly-pluralize-floats
Browse files Browse the repository at this point in the history
Correctly pluralize floats between 1 and 2
  • Loading branch information
fivetanley committed Dec 8, 2015
2 parents 4d6aa7b + 2bfa456 commit 9a742cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions addon/lib/helpers/pluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import makeHelper from '../utils/make-helper';
* @param {String|Property} word word to pluralize
*/
export default makeHelper(function (params) {
var count, word;
let count, word;

if (params.length === 1) {
word = params[0];
Expand All @@ -28,9 +28,10 @@ export default makeHelper(function (params) {
count = params[0];
word = params[1];

if ((count | 0) !== 1) {
if (parseFloat(count) !== 1) {
word = pluralize(word);
}

return count + " " + word;
}
});
1 change: 0 additions & 1 deletion tests/unit/inflector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,3 @@ test('Ember.Inflector.singularize passes same test cases as ActiveSupport::Infle
assert.equal(inflector.singularize('slices'), 'slice');
assert.equal(inflector.singularize('police'), 'police');
});

21 changes: 21 additions & 0 deletions tests/unit/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,34 @@ test("helpers - pluralize - bound count 1", function(assert) {
assert.equal(this.$().text(), '1 orange');
});

test("helpers - pluralize - bound count 1.0 float", function(assert) {
this.set('count', 1.0);
this.set('singular', 'owl');
this.render('{{pluralize count singular}}');
assert.equal(this.$().text(), '1 owl');
});

test("helpers - pluralize - bound count 1.5 float", function(assert) {
this.set('count', 1.5);
this.set('singular', 'owl');
this.render('{{pluralize count singular}}');
assert.equal(this.$().text(), '1.5 owls');
});

test("helpers - pluralize - bound count 1.0 string", function(assert) {
this.set('count', '1.0');
this.set('singular', 'owl');
this.render('{{pluralize count singular}}');
assert.equal(this.$().text(), '1.0 owl');
});

test("helpers - pluralize - bound count 1.5 string", function(assert) {
this.set('count', '1.5');
this.set('singular', 'owl');
this.render('{{pluralize count singular}}');
assert.equal(this.$().text(), '1.5 owls');
});

test("helpers - pluralize - bound count 2", function(assert) {
this.set('count', 2);
this.set('singular', 'omnivore');
Expand Down

0 comments on commit 9a742cf

Please sign in to comment.