added cached columns for post update count, post upload count, note update count, favorite count to users; fixed tests

This commit is contained in:
albert
2011-11-01 13:45:26 -04:00
parent ec362d79bf
commit cdc958d4f3
12 changed files with 126 additions and 26 deletions

View File

@@ -56,6 +56,12 @@ class NoteTest < ActiveSupport::TestCase
@note = Factory.create(:note, :post => @post)
end
should "increment the updater's note_update_count" do
assert_difference("CurrentUser.note_update_count", 1) do
@note.update_attributes(:body => "zzz")
end
end
should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at)
@note.update_attributes(:x => 1000)

View File

@@ -415,6 +415,15 @@ class PostTest < ActiveSupport::TestCase
end
context "that has been updated" do
should "increment the updater's post_update_count" do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
assert_difference("CurrentUser.post_update_count", 1) do
post.update_attributes(:tag_string => "zzz")
CurrentUser.reload
end
end
should "reset its tag array cache" do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
user = Factory.create(:user)
@@ -525,29 +534,76 @@ class PostTest < ActiveSupport::TestCase
end
context "Favorites:" do
context "Adding a post to a user's favorites" do
should "update the fav strings ont he post" do
user = Factory.create(:user)
post = Factory.create(:post)
post.add_favorite!(user)
post.reload
assert_equal("fav:#{user.id}", post.fav_string)
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.exists?(:user_id => user.id, :post_id => post.id))
post.remove_favorite!(user)
post.reload
assert_equal("", post.fav_string)
assert(!Favorite.exists?(:user_id => user.id, :post_id => post.id))
context "Removing a post from a user's favorites" do
setup do
@user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@post.add_favorite!(@user)
end
post.remove_favorite!(user)
post.reload
assert_equal("", post.fav_string)
assert(!Favorite.exists?(:user_id => user.id, :post_id => post.id))
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "decrement the user's favorite_count" do
assert_difference("CurrentUser.favorite_count", -1) do
@post.remove_favorite!(@user)
CurrentUser.reload
end
end
should "not decrement the user's favorite_count if the user did not favorite the post" do
@post2 = Factory.create(:post)
assert_difference("CurrentUser.favorite_count", 0) do
@post2.remove_favorite!(@user)
CurrentUser.reload
end
end
end
context "Adding a post to a user's favorites" do
setup do
@user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "increment the user's favorite_count" do
assert_difference("CurrentUser.favorite_count", 1) do
@post.add_favorite!(@user)
CurrentUser.reload
end
end
should "update the fav strings ont he post" do
@post.add_favorite!(@user)
@post.reload
assert_equal("fav:#{@user.id}", @post.fav_string)
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.exists?(:user_id => @user.id, :post_id => @post.id))
@post.remove_favorite!(@user)
@post.reload
assert_equal("", @post.fav_string)
assert(!Favorite.exists?(:user_id => @user.id, :post_id => @post.id))
@post.remove_favorite!(@user)
@post.reload
assert_equal("", @post.fav_string)
assert(!Favorite.exists?(:user_id => @user.id, :post_id => @post.id))
end
end
end

View File

@@ -128,6 +128,14 @@ class UploadTest < ActiveSupport::TestCase
assert_equal(198695, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
end
end
should "increment the uploaders post_upload_count" do
@upload = Factory.create(:source_upload)
assert_difference("CurrentUser.post_upload_count", 1) do
@upload.process!
CurrentUser.reload
end
end
should "process completely for a downloaded image" do
@upload = Factory.create(:source_upload,