fixed tests, implemented sql based partitioning for favorites

This commit is contained in:
albert
2011-07-16 20:16:34 -04:00
parent fc9755b748
commit 469ae14805
10 changed files with 1291 additions and 4555 deletions

View File

@@ -24,8 +24,8 @@ module PostSets
context "a favorite set for before the most recent post" do
setup do
id = ::Favorite.model_for(@user.id).where(:user_id => @user.id, :post_id => @post_3.id).first.id
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_3.id).first.id
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id, "b#{id}")
end
@@ -39,8 +39,8 @@ module PostSets
context "a favorite set for after the second most recent post" do
setup do
id = ::Favorite.model_for(@user.id).where(:user_id => @user.id, :post_id => @post_2.id).first.id
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_2.id).first.id
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id, "a#{id}")
end
@@ -54,7 +54,7 @@ module PostSets
context "a favorite set for page 2" do
setup do
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id, 2)
end
@@ -68,7 +68,7 @@ module PostSets
context "a favorite set with no page specified" do
setup do
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
::Favorite.stubs(:records_per_page).returns(1)
@set = PostSets::Favorite.new(@user.id)
end

View File

@@ -85,8 +85,8 @@ class PostTest < ActiveSupport::TestCase
c1.add_favorite!(user)
c1.delete!
p1.reload
assert(!Favorite.model_for(user.id).exists?(:post_id => c1.id, :user_id => user.id))
assert(Favorite.model_for(user.id).exists?(:post_id => p1.id, :user_id => user.id))
assert(!Favorite.exists?(:post_id => c1.id, :user_id => user.id))
assert(Favorite.exists?(:post_id => p1.id, :user_id => user.id))
end
should "update the parent's has_children flag" do
@@ -335,22 +335,22 @@ class PostTest < ActiveSupport::TestCase
post.add_favorite!(user)
post.reload
assert_equal("fav:#{user.id}", post.fav_string)
assert(Favorite.model_for(user.id).exists?(:user_id => user.id, :post_id => post.id))
assert(Favorite.exists?(:user_id => user.id, :post_id => post.id))
post.add_favorite!(user)
post.reload
assert_equal("fav:#{user.id}", post.fav_string)
assert(Favorite.model_for(user.id).exists?(:user_id => user.id, :post_id => post.id))
assert(Favorite.exists?(:user_id => user.id, :post_id => post.id))
post.remove_favorite!(user)
post.reload
assert_equal("", post.fav_string)
assert(!Favorite.model_for(user.id).exists?(:user_id => user.id, :post_id => post.id))
assert(!Favorite.exists?(:user_id => user.id, :post_id => post.id))
post.remove_favorite!(user)
post.reload
assert_equal("", post.fav_string)
assert(!Favorite.model_for(user.id).exists?(:user_id => user.id, :post_id => post.id))
assert(!Favorite.exists?(:user_id => user.id, :post_id => post.id))
end
end
end