From 4cb365a6f4e6756911bde8f8bde4dafb617c82f1 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 17 Aug 2017 01:02:06 +0200 Subject: [PATCH] Fix missing photos in the single post view closes #7545 --- app/assets/javascripts/app/views/content_view.js | 7 +++---- spec/javascripts/app/views/content_view_spec.js | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/views/content_view.js b/app/assets/javascripts/app/views/content_view.js index 7027ea97c..5a5a9e9af 100644 --- a/app/assets/javascripts/app/views/content_view.js +++ b/app/assets/javascripts/app/views/content_view.js @@ -17,15 +17,14 @@ app.views.Content = app.views.Base.extend({ largePhoto : function() { var photos = this.model.get("photos"); - if(!photos || photos.length === 0) { return } + if (!photos || photos.length === 0) { return false; } return photos[0]; }, smallPhotos : function() { var photos = this.model.get("photos"); - if(!photos || photos.length < 2) { return } - photos.splice(0, 1); // remove first photo as it is already shown as largePhoto - return photos; + if (!photos || photos.length < 2) { return false; } + return photos.slice(1); // remove first photo as it is already shown as largePhoto }, expandPost: function(evt) { diff --git a/spec/javascripts/app/views/content_view_spec.js b/spec/javascripts/app/views/content_view_spec.js index 90fa3c4af..2315b4473 100644 --- a/spec/javascripts/app/views/content_view_spec.js +++ b/spec/javascripts/app/views/content_view_spec.js @@ -4,11 +4,17 @@ describe("app.views.Content", function(){ this.view = new app.views.Content({model : this.post}); }); - describe("rendering", function(){ + describe("smallPhotos", function() { it("should return all but the first photo from the post", function() { this.post.set({photos : [1,2]}); // set 2 Photos expect(this.view.smallPhotos().length).toEqual(1); }); + + it("shouldn't change the photos array", function() { + this.post.set({photos: [1, 2]}); // set 2 Photos + this.view.smallPhotos(); + expect(this.post.get("photos").length).toEqual(2); + }); }); describe("presenter", function(){