diff --git a/app/models/post.rb b/app/models/post.rb index 8cfee8d0b..8cd934fc6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -21,6 +21,7 @@ class Post < ActiveRecord::Base t.add :created_at t.add :comments_count t.add :likes_count + t.add :reshares_count t.add :last_three_comments t.add :provider_display_name t.add :author diff --git a/app/views/templates/reshare.jst b/app/views/templates/reshare.jst index 7167a8773..aa7ec26e4 100644 --- a/app/views/templates/reshare.jst +++ b/app/views/templates/reshare.jst @@ -19,6 +19,11 @@ + + <% if(root.reshares_count) { %> + - + <%= root.reshares_count %> reshares + <% } %> diff --git a/app/views/templates/stream_element.jst b/app/views/templates/stream_element.jst index 4f3268e1b..544df17cd 100644 --- a/app/views/templates/stream_element.jst +++ b/app/views/templates/stream_element.jst @@ -26,6 +26,11 @@ + + <% if(reshares_count) { %> + - + <%= reshares_count %> reshares + <% } %> diff --git a/features/infinite_scroll.feature b/features/infinite_scroll.feature deleted file mode 100644 index ccab29ae2..000000000 --- a/features/infinite_scroll.feature +++ /dev/null @@ -1,40 +0,0 @@ -@javascript -Feature: infinite scroll - In order to browse without disruption - As medium-sized internet grazing animal - I want the stream to infinite scroll - - Background: - Given many posts from alice for bob - And I resize my window to 800x600 - And I sign in as "bob@bob.bob" - And I follow "Your Aspects" - And I wait for the ajax to finish - - Scenario: on the main stream - When I go to the home page - And I wait for the ajax to finish - Then I should see 15 posts - And I should see "alice - 15 - #seeded" - - When I scroll down - Then I should see 30 posts - And I should see "alice - 30 - #seeded" - - Scenario: On a tag page - When I go to the tag page for "seeded" - Then I should see 15 posts - And I should see "alice - 15 - #seeded" - - When I scroll down - Then I should see 30 posts - And I should see "alice - 30 - #seeded" - - Scenario: On a profile page - And I am on "alice@alice.alice"'s page - Then I should see 15 posts - And I should see "alice - 15 - #seeded" - - When I scroll down - Then I should see 30 posts - And I should see "alice - 30 - #seeded" diff --git a/features/reshare.feature b/features/reshare.feature index a9e764c69..9fdbf8e2f 100644 --- a/features/reshare.feature +++ b/features/reshare.feature @@ -24,16 +24,3 @@ Feature: public repost Then I should see "reshare this!" Then I should see a ".reshare" And I should see "Bob" - - # (NOTE) this should be a jasmine spec - Scenario: I can see the number of reshares - Given "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" - And I wait for the ajax to finish - And I preemptively confirm the alert - And I follow "Reshare" - - And I wait for 2 seconds - When I go to the home page - And I wait for the ajax to finish - Then I should see "1 reshare" diff --git a/public/javascripts/app/views/stream_view.js b/public/javascripts/app/views/stream_view.js index 610ef4bfd..36b513746 100644 --- a/public/javascripts/app/views/stream_view.js +++ b/public/javascripts/app/views/stream_view.js @@ -22,7 +22,7 @@ app.views.Stream = Backbone.View.extend({ return this; }, - infScroll : function(options) { + infScroll : function() { if(this.isLoading()) { return } var $window = $(window); @@ -33,10 +33,12 @@ app.views.Stream = Backbone.View.extend({ if(distFromBottom < bufferPx) { this.render(); } + + return this; }, isLoading : function(){ - return !this._loading.isResolved(); + return this._loading && !this._loading.isResolved(); }, addPost : function(post) { diff --git a/spec/controllers/jasmine_fixtures/stream_spec.rb b/spec/controllers/jasmine_fixtures/stream_spec.rb index 7fb93a6b6..e27830635 100644 --- a/spec/controllers/jasmine_fixtures/stream_spec.rb +++ b/spec/controllers/jasmine_fixtures/stream_spec.rb @@ -13,10 +13,12 @@ describe MultisController do it 'generates the multi_stream_json fixture', :fixture => true do posts = [] - posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id) - posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all') - posts << alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id) - alice.like(1, :target => posts.last) + 10.times do + posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id) + posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all') + posts << alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id) + alice.like(1, :target => posts.last) + end time = Time.now posts.each do |p| @@ -26,9 +28,6 @@ describe MultisController do get :index, :format => :json response.should be_success - - pp response.body - save_fixture(response.body, "multi_stream_json") end end diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 48922fc65..a757d98ea 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -11,6 +11,22 @@ describe("app.views.Post", function(){ this.statusMessage = this.collection.models[0]; }) + it("displays a reshare count", function(){ + this.statusMessage.set({reshares_count : 2}) + var view = new app.views.Post({model : this.statusMessage}).render(); + var statusElement = $(view.el) + + expect(statusElement.html()).toContain("2 reshares") + }) + + it("does not display a reshare count for 'zero'", function(){ + this.statusMessage.set({reshares_count : 0}) + var view = new app.views.Post({model : this.statusMessage}).render(); + var statusElement = $(view.el) + + expect(statusElement.html()).not.toContain("0 reshares") + }) + context("user not signed in", function(){ it("does not provide a Feedback view", function(){ window.current_user = app.user(null); diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index 829275bf1..5e9a78246 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -1,24 +1,31 @@ describe("app.views.Stream", function(){ + beforeEach(function(){ + // should be jasmine helper + window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); + + var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"]; + + this.collection = new app.collections.Stream(posts); + + this.view = new app.views.Stream({collection : this.collection}); + + // do this manually because we've moved loadMore into render?? + this.view.render(); + _.each(this.view.collection.models, function(post){ + this.view.addPost(post); + }, this); + }) + + describe("initialize", function(){ + + it("binds an infinite scroll listener", function(){ + }) + }) describe("#render", function(){ beforeEach(function(){ - // should be jasmine helper - window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); - - var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"]; - - this.collection = new app.collections.Stream(posts); this.statusMessage = this.collection.models[0]; this.reshare = this.collection.models[1]; - - this.view = new app.views.Stream({collection : this.collection}); - - // do this manually because we've moved loadMore into render?? - this.view.render(); - _.each(this.view.collection.models, function(post){ - this.view.addPost(post); - }, this); - this.statusElement = $(this.view.$("#" + this.statusMessage.get("guid"))); this.reshareElement = $(this.view.$("#" + this.reshare.get("guid"))); }) @@ -29,4 +36,43 @@ describe("app.views.Stream", function(){ }) }) }) + + describe("infScroll", function(){ + // NOTE: inf scroll happens at 300px + + beforeEach(function(){ + spyOn(this.view.collection, "fetch") + }) + + context("when the user is at the bottom of the page", function(){ + beforeEach(function(){ + spyOn($.fn, "height").andReturn(0) + spyOn($.fn, "scrollTop").andReturn(100) + }) + + it("calls fetch", function(){ + spyOn(this.view, "isLoading").andReturn(false) + + this.view.infScroll(); + expect(this.view.collection.fetch).toHaveBeenCalled(); + }) + + it("does not call fetch", function(){ + spyOn(this.view, "isLoading").andReturn(true) + + this.view.infScroll(); + expect(this.view.collection.fetch).not.toHaveBeenCalled(); + }) + }) + + it("does not fetch new content when the user is not at the bottom of the page", function(){ + spyOn(this.view, "isLoading").andReturn(false) + + spyOn($.fn, "height").andReturn(0); + spyOn($.fn, "scrollTop").andReturn(-400); + + this.view.infScroll(); + expect(this.view.collection.fetch).not.toHaveBeenCalled(); + }) + }) }) diff --git a/spec/javascripts/app/views_spec.js b/spec/javascripts/app/views_spec.js index 11842192b..5ee20bcdb 100644 --- a/spec/javascripts/app/views_spec.js +++ b/spec/javascripts/app/views_spec.js @@ -49,7 +49,6 @@ describe("app.views.Base", function(){ postRenderTemplate : function(){ $(this.el).append("