Test and fix pagination on profile, tag and aspect streams
This commit is contained in:
parent
e7e9ef3ad5
commit
38e44b13aa
12 changed files with 88 additions and 48 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue