diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 403b5b04e..04bd87472 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -5,7 +5,6 @@ class PeopleController < ApplicationController helper :comments before_filter :authenticate_user!, :except => [:show] - before_filter :ensure_page, :only => :show respond_to :html respond_to :json, :only => [:index, :show] @@ -70,6 +69,7 @@ class PeopleController < ApplicationController @aspect = :profile @share_with = (params[:share_with] == 'true') + max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now if @person @profile = @person.profile @@ -95,10 +95,10 @@ class PeopleController < ApplicationController else @commenting_disabled = false end - @posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).limit(15).offset(15*(params[:page]-1)) + @posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)) else @commenting_disabled = true - @posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).offset(15*(params[:page]-1)).order('posts.created_at DESC') + @posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC') end @posts = PostsFake.new(@posts) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 1a52eddb4..3ce661e44 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -55,7 +55,7 @@ class TagsController < ApplicationController @posts = @posts.tagged_with(params[:name]) max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now - @posts = @posts.where(StatusMessage.arel_table[:created_at].lteq(max_time)) + @posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time)) @posts = @posts.includes(:comments, :photos).order('posts.created_at DESC').limit(15) diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index 9c1a4e678..7d9519287 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -4,7 +4,7 @@ module AspectsHelper def next_page_path - aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids], :class => 'paginate') + aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids]) end def remove_link(aspect) diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index a8b16b44a..490200756 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -29,6 +29,6 @@ module PeopleHelper end def next_page_path - person_path(@person, :max_time => @posts.last.created_at.to_i, :class => 'paginate') + person_path(@person, :max_time => @posts.last.created_at.to_i) end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 9511f624e..ee29ec44e 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -4,6 +4,6 @@ module TagsHelper def next_page_path - tag_path(@tag, :max_time => @posts.last.created_at.to_i, :class => 'paginate') + tag_path(@tag, :max_time => @posts.last.created_at.to_i) end end diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 20e7f6b9e..ff1e80855 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -82,7 +82,7 @@ #main_stream.stream = render 'shared/stream', :posts => @posts, :commenting_disabled => @commenting_disabled #pagination - =link_to(t('more'), next_page_path) + =link_to(t('more'), next_page_path, :class => 'paginate') - else #stream diff --git a/features/infinite_scroll.feature b/features/infinite_scroll.feature index fa65f29e5..98181bff1 100644 --- a/features/infinite_scroll.feature +++ b/features/infinite_scroll.feature @@ -5,33 +5,68 @@ Feature: infinite scroll I want the stream to infinite scroll Background: - Given many posts from bob and alice + Given many posts from alice for bob + When I sign in as "bob@bob.bob" Scenario: on the main stream - When I sign in as "bob@bob.bob" Then I should see 15 posts + And I should see "alice - 15 - #seeded" When I scroll down - And I wait for the ajax to finish - #FIXME - And I wait for the ajax to finish Then I should see 30 posts + And I should see "alice - 30 - #seeded" + + When I scroll down + Then I should see 40 posts + And I should see "alice - 40 - #seeded" + + When I scroll down + Then I should see "No more" When I follow "generic" 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 - And I wait for the ajax to finish - And I wait for the ajax to finish Then I should see 30 posts + And I should see "alice - 30 - #seeded" + + When I scroll down + Then I should see 40 posts + And I should see "alice - 40 - #seeded" + + When I scroll down + Then I should see "No more" Scenario: On a tag page - When I sign in as "bob@bob.bob" And I am on the tag page for "seeded" Then I should see 15 posts + And I should see "alice - 15 - #seeded" When I scroll down - And I wait for the ajax to finish - And I wait for the ajax to finish Then I should see 30 posts + And I should see "alice - 30 - #seeded" + + When I scroll down + Then I should see 40 posts + And I should see "alice - 40 - #seeded" + + When I scroll down + Then I should see "No more" + + 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" + + When I scroll down + Then I should see 40 posts + And I should see "alice - 40 - #seeded" + + When I scroll down + Then I should see "No more" diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 167ffaa0f..a11af53b8 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -194,5 +194,6 @@ Then /^I should see (\d+) posts$/ do |n_posts| end And /^I scroll down$/ do - visit('#footer_nav') + evaluate_script("window.scrollBy(0,3000000)") + wait_until(10) { evaluate_script('$("#infscr-loading:visible").length') == 0 } end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 7c399594d..624682688 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -140,18 +140,16 @@ Given /^there is a user "([^\"]*)" who's tagged "([^\"]*)"$/ do |full_name, tag| user.profile.save! end -Given /^many posts from bob and alice$/ do +Given /^many posts from alice for bob$/ do alice = Factory(:user_with_aspect, :username => 'alice', :email => 'alice@alice.alice', :password => 'password', :getting_started => false) bob = Factory(:user_with_aspect, :username => 'bob', :email => 'bob@bob.bob', :password => 'password', :getting_started => false) connect_users_with_aspects(alice, bob) time_interval = 1000 - (1..20).each do |n| - [alice, bob].each do |u| - post = u.post :status_message, :text => "#{u.username} - #{n} - #seeded", :to => u.aspects.first.id - post.created_at = post.created_at - time_interval - post.updated_at = post.updated_at - time_interval - post.save - time_interval += 1000 - end + (1..40).each do |n| + post = alice.post :status_message, :text => "#{alice.username} - #{n} - #seeded", :to => alice.aspects.first.id + post.created_at = post.created_at - time_interval + post.updated_at = post.updated_at - time_interval + post.save + time_interval += 1000 end end diff --git a/public/javascripts/widgets/infinite-scroll.js b/public/javascripts/widgets/infinite-scroll.js index 0aac36ceb..47dca9bf7 100644 --- a/public/javascripts/widgets/infinite-scroll.js +++ b/public/javascripts/widgets/infinite-scroll.js @@ -5,24 +5,26 @@ (function() { var InfiniteScroll = function() { }; - InfiniteScroll.prototype.options = { - navSelector : "#pagination", - nextSelector : ".paginate", - itemSelector : ".stream_element", - pathParse : function( pathStr, nextPage ){ - var newPath = pathStr.replace("?", "?only_posts=true&"); - var last_time = $('#main_stream .stream_element').last().find('.time').attr('integer'); - return newPath.replace( /max_time=\d+/, 'max_time=' + last_time); - }, - bufferPx: 500, - debug: false, - donetext: Diaspora.widgets.i18n.t("infinite_scroll.no_more"), - loadingText: "", - loadingImg: '/images/ajax-loader.gif' + InfiniteScroll.prototype.options = function(){ + return { + navSelector : "#pagination", + nextSelector : ".paginate", + itemSelector : ".stream_element", + pathParse : function( pathStr, nextPage ){ + var newPath = pathStr.replace("?", "?only_posts=true&"); + var last_time = $('#main_stream .stream_element').last().find('.time').attr('integer'); + return newPath.replace( /max_time=\d+/, 'max_time=' + last_time); + }, + bufferPx: 500, + debug: false, + donetext: Diaspora.widgets.i18n.t("infinite_scroll.no_more"), + loadingText: "", + loadingImg: '/images/ajax-loader.gif' + }; }; InfiniteScroll.prototype.initialize = function(){ - $('#main_stream').infinitescroll(this.options, function() { + $('#main_stream').infinitescroll(this.options(), function() { Diaspora.widgets.publish("stream/scrolled"); }); }; diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 8af83537b..caf84e1ad 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -44,19 +44,19 @@ describe TagsController do sign_in :user, alice end it 'displays your own post' do - my_post = alice.post(:status_message, :text => "#what", :to => 'all') + my_post = alice.post(:status_message, :text => "#what", :to => 'all', :created_at => Time.now - 1) get :show, :name => 'what' assigns(:posts).models.should == [my_post] response.status.should == 200 end it "displays a friend's post" do - other_post = bob.post(:status_message, :text => "#hello", :to => 'all') + other_post = bob.post(:status_message, :text => "#hello", :to => 'all', :created_at => Time.now - 1) get :show, :name => 'hello' assigns(:posts).models.should == [other_post] response.status.should == 200 end it 'displays a public post' do - other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all') + other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all', :created_at => Time.now - 1) get :show, :name => 'hello' assigns(:posts).models.should == [other_post] response.status.should == 200 @@ -80,8 +80,8 @@ describe TagsController do end context "when there are posts to display" do before do - @post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all') - alice.post(:status_message, :text => "#hello", :public => true, :to => 'all') + @post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all', :created_at => Time.now - 1) + alice.post(:status_message, :text => "#hello", :public => true, :to => 'all', :created_at => Time.now - 1) end it "succeeds" do get :show, :name => 'what' diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index 4382b752b..0d8f87b05 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -23,6 +23,10 @@ class User add_to_streams(p, aspects) dispatch_post(p, :to => opts[:to]) end + if opts[:created_at] + p.created_at = opts[:created_at] + p.save + end p end end