Improve sequential paginator

fixes #2044, fixes #1298
This commit is contained in:
Toks
2013-12-04 14:41:50 -05:00
parent 067d15d754
commit 9585e32914
4 changed files with 80 additions and 10 deletions

View File

@@ -34,10 +34,15 @@ module PostSets
assert_equal(1, @set.posts.size)
assert_equal(@post_1.id, @set.posts.first.id)
end
should "know what page it's on" do
refute(@set.favorites.is_first_page?)
refute(@set.favorites.is_last_page?)
end
end
end
context "a favorite set for after the second most recent post" do
context "a favorite set for after the third most recent post" do
setup do
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_2.id).first.id
::Favorite.stubs(:records_per_page).returns(1)
@@ -45,10 +50,55 @@ module PostSets
end
context "a sequential paginator" do
should "return the most recent element" do
should "return the second most recent element" do
assert_equal(1, @set.posts.size)
assert_equal(@post_1.id, @set.posts.first.id)
end
should "know what page it's on" do
refute(@set.favorites.is_first_page?)
refute(@set.favorites.is_last_page?)
end
end
end
context "a favorite set for before the second most recent post" do
setup do
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id, "b#{id}")
end
context "a sequential paginator" do
should "return the third most recent element" do
assert_equal(1, @set.posts.size)
assert_equal(@post_2.id, @set.posts.first.id)
end
should "know what page it's on" do
refute(@set.favorites.is_first_page?)
assert(@set.favorites.is_last_page?)
end
end
end
context "a favorite set for after the second most recent post" do
setup do
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id, "a#{id}")
end
context "a sequential paginator" do
should "return the most recent element" do
assert_equal(1, @set.posts.size)
assert_equal(@post_3.id, @set.posts.first.id)
end
should "know what page it's on" do
assert(@set.favorites.is_first_page?)
refute(@set.favorites.is_last_page?)
end
end
end
@@ -63,6 +113,11 @@ module PostSets
assert_equal(1, @set.posts.size)
assert_equal(@post_1.id, @set.posts.first.id)
end
should "know what page it's on" do
refute(@set.favorites.is_first_page?)
refute(@set.favorites.is_last_page?)
end
end
end
@@ -76,6 +131,11 @@ module PostSets
assert_equal(1, @set.posts.size)
assert_equal(@post_3.id, @set.posts.first.id)
end
should "know what page it's on" do
assert(@set.favorites.is_first_page?)
refute(@set.favorites.is_last_page?)
end
end
end
end