diff --git a/app/assets/javascripts/app/collections/aspect_selections.js b/app/assets/javascripts/app/collections/aspect_selections.js index 49ea754e4..bfe3fb94e 100644 --- a/app/assets/javascripts/app/collections/aspect_selections.js +++ b/app/assets/javascripts/app/collections/aspect_selections.js @@ -3,27 +3,29 @@ app.collections.AspectSelections = Backbone.Collection.extend({ model: app.models.AspectSelection, - selectedAspects: function(attribute){ - return _.pluck(_.filter(this.toJSON(), function(a){ - return a.selected; - }), attribute); + selectedGetAttribute: function(attribute) { + return _.pluck(_.filter(this.toJSON(), function(a) { + return a.selected; + }), attribute); }, - allSelected: function(){ - return this.length === _.filter(this.toJSON(), function(a){ return a.selected; }).length; + allSelected: function() { + return this.length === _.filter(this.toJSON(), function(a) { return a.selected; }).length; }, - selectAll: function(){ - this.map(function(a){ a.set({ 'selected' : true })} ); + selectAll: function() { + this.map(function(a) { a.set({"selected": true}); }); }, - deselectAll: function(){ - this.map(function(a){ a.set({ 'selected' : false })} ); + deselectAll: function() { + this.map(function(a) { a.set({"selected": false}); }); }, - toSentence: function(){ - var separator = Diaspora.I18n.t("comma") + ' '; - return this.selectedAspects('name').join(separator).replace(/,\s([^,]+)$/, ' ' + Diaspora.I18n.t("and") + ' $1') || Diaspora.I18n.t("my_aspects"); + toSentence: function() { + var separator = Diaspora.I18n.t("comma") + " "; + var pattern = new RegExp(Diaspora.I18n.t("comma") + "\\s([^" + Diaspora.I18n.t("comma") + "]+)$"); + return this.selectedGetAttribute("name").join(separator).replace(pattern, " " + Diaspora.I18n.t("and") + " $1") + || Diaspora.I18n.t("my_aspects"); } }); // @license-end diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 9a62b707d..f5c42f13b 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -142,7 +142,7 @@ app.Router = Backbone.Router.extend({ }, aspects_stream : function(){ - var ids = app.aspectSelections.selectedAspects("id"); + var ids = app.aspectSelections.selectedGetAttribute("id"); app.stream = new app.models.StreamAspects([], { aspects_ids: ids }); app.stream.fetch(); this._initializeStreamView(); diff --git a/spec/javascripts/app/collections/aspect_selections_spec.js b/spec/javascripts/app/collections/aspect_selections_spec.js index 446f50813..448a9eed3 100644 --- a/spec/javascripts/app/collections/aspect_selections_spec.js +++ b/spec/javascripts/app/collections/aspect_selections_spec.js @@ -1,86 +1,86 @@ -describe("app.collections.AspectSelections", function(){ - beforeEach(function(){ - var my_aspects = [ - { name: 'Work', selected: true }, - { name: 'Friends', selected: false }, - { name: 'Acquaintances', selected: false } +describe("app.collections.AspectSelections", function() { + beforeEach(function() { + var myAspects = [ + {name: "Work", selected: true}, + {name: "Friends", selected: false}, + {name: "Acquaintances", selected: false} ]; - this.aspects = new app.collections.AspectSelections(my_aspects); + this.aspects = new app.collections.AspectSelections(myAspects); }); - describe("#selectAll", function(){ - it("selects every aspect in the collection", function(){ + describe("#selectAll", function() { + it("selects every aspect in the collection", function() { this.aspects.selectAll(); - this.aspects.each(function(aspect){ - expect(aspect.get('selected')).toBeTruthy(); + this.aspects.each(function(aspect) { + expect(aspect.get("selected")).toBeTruthy(); }); }); }); - describe("#deselectAll", function(){ - it("deselects every aspect in the collection", function(){ + describe("#deselectAll", function() { + it("deselects every aspect in the collection", function() { this.aspects.deselectAll(); - this.aspects.each(function(aspect){ - expect(aspect.get('selected')).toBeFalsy(); + this.aspects.each(function(aspect) { + expect(aspect.get("selected")).toBeFalsy(); }); }); }); - describe("#allSelected", function(){ - it("returns true if every aspect is selected", function(){ - this.aspects.at(1).set('selected', true); - this.aspects.at(2).set('selected', true); + describe("#allSelected", function() { + it("returns true if every aspect is selected", function() { + this.aspects.at(1).set("selected", true); + this.aspects.at(2).set("selected", true); expect(this.aspects.allSelected()).toBeTruthy(); }); - it("returns false if at least one aspect is not selected", function(){ + it("returns false if at least one aspect is not selected", function() { expect(this.aspects.allSelected()).toBeFalsy(); }); }); - describe("#toSentence", function(){ - describe('without aspects', function(){ - beforeEach(function(){ - this.aspects = new app.collections.AspectSelections([{ name: 'Work', selected: false }]); + describe("#toSentence", function() { + describe("without aspects", function() { + beforeEach(function() { + this.aspects = new app.collections.AspectSelections([{name: "Work", selected: false}]); }); - it("returns the name of the aspect", function(){ + it("returns the name of the aspect", function() { expect(this.aspects.toSentence()).toEqual("My aspects"); }); }); - describe("with one aspect", function(){ - beforeEach(function(){ - this.aspects = new app.collections.AspectSelections([{ name: 'Work', selected: true }]); + describe("with one aspect", function() { + beforeEach(function() { + this.aspects = new app.collections.AspectSelections([{name: "Work", selected: true}]); }); - it("returns the name of the aspect", function(){ - expect(this.aspects.toSentence()).toEqual('Work'); + it("returns the name of the aspect", function() { + expect(this.aspects.toSentence()).toEqual("Work"); }); }); - describe("with three aspect", function(){ - it("returns the name of the selected aspect", function(){ - expect(this.aspects.toSentence()).toEqual('Work'); + describe("with three aspect", function() { + it("returns the name of the selected aspect", function() { + expect(this.aspects.toSentence()).toEqual("Work"); }); - it("returns the names of the two selected aspects", function(){ - this.aspects.at(1).set('selected', true); - expect(this.aspects.toSentence()).toEqual('Work and Friends'); + it("returns the names of the two selected aspects", function() { + this.aspects.at(1).set("selected", true); + expect(this.aspects.toSentence()).toEqual("Work and Friends"); }); - it("returns the names of the selected aspects in a comma-separated sentence", function(){ - this.aspects.at(1).set('selected', true); - this.aspects.at(2).set('selected', true); - expect(this.aspects.toSentence()).toEqual('Work, Friends and Acquaintances'); + it("returns the names of the selected aspects in a comma-separated sentence", function() { + this.aspects.at(1).set("selected", true); + this.aspects.at(2).set("selected", true); + expect(this.aspects.toSentence()).toEqual("Work, Friends and Acquaintances"); }); }); }); - describe("#selectedAspects", function(){ - describe("by name", function(){ - it("returns the names of the selected aspects", function(){ - expect(this.aspects.selectedAspects('name')).toEqual(["Work"]); + describe("#selectedGetAttribute", function() { + describe("by name", function() { + it("returns the names of the selected aspects", function() { + expect(this.aspects.selectedGetAttribute("name")).toEqual(["Work"]); }); }); });