uncommented tests
This commit is contained in:
@@ -1,199 +1,199 @@
|
|||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require File.dirname(__FILE__) + '/../test_helper'
|
||||||
|
|
||||||
class PostTest < ActiveSupport::TestCase
|
class PostTest < ActiveSupport::TestCase
|
||||||
# context "During moderation a post" do
|
context "During moderation a post" do
|
||||||
# setup do
|
setup do
|
||||||
# @post = Factory.create(:post)
|
@post = Factory.create(:post)
|
||||||
# @user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# should "be unapproved once and only once" do
|
|
||||||
# @post.unapprove!("bad", @user, "127.0.0.1")
|
|
||||||
# assert(@post.is_flagged?, "Post should be flagged.")
|
|
||||||
# assert_not_nil(@post.unapproval, "Post should have an unapproval record.")
|
|
||||||
# assert_equal("bad", @post.unapproval.reason)
|
|
||||||
#
|
|
||||||
# assert_raise(Unapproval::Error) {@post.unapprove!("bad", @user, "127.0.0.1")}
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# should "not unapprove if no reason is given" do
|
|
||||||
# assert_raise(Unapproval::Error) {@post.unapprove!("", @user, "127.0.0.1")}
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# should "be deleted" do
|
|
||||||
# @post.delete!
|
|
||||||
# assert(@post.is_deleted?, "Post should be deleted.")
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# should "be approved" do
|
|
||||||
# @post.approve!
|
|
||||||
# assert(!@post.is_pending?, "Post should not be pending.")
|
|
||||||
#
|
|
||||||
# @deleted_post = Factory.create(:post, :is_deleted => true)
|
|
||||||
# @deleted_post.approve!
|
|
||||||
# assert(!@post.is_deleted?, "Post should not be deleted.")
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# context "A post version" do
|
|
||||||
# should "be created on any save" do
|
|
||||||
# @user = Factory.create(:user)
|
|
||||||
# @post = Factory.create(:post)
|
|
||||||
# assert_equal(1, @post.versions.size)
|
|
||||||
#
|
|
||||||
# @post.update_attributes(:rating => "e", :updater_id => @user.id, :updater_ip_addr => "125.0.0.0")
|
|
||||||
# assert_equal(2, @post.versions.size)
|
|
||||||
# assert_equal(@user.id, @post.versions.last.updater_id)
|
|
||||||
# assert_equal("125.0.0.0", @post.versions.last.updater_ip_addr)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# context "A post's tags" do
|
|
||||||
# setup do
|
|
||||||
# @post = Factory.create(:post)
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# should "have an array representation" do
|
|
||||||
# @post.set_tag_string("aaa bbb")
|
|
||||||
# assert_equal(%w(aaa bbb), @post.tag_array)
|
|
||||||
# assert_equal(%w(tag1 tag2), @post.tag_array_was)
|
|
||||||
# end
|
|
||||||
|
|
||||||
should "reset the tag array cache when updated" do
|
should "be unapproved once and only once" do
|
||||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
@post.unapprove!("bad", @user, "127.0.0.1")
|
||||||
user = Factory.create(:user)
|
assert(@post.is_flagged?, "Post should be flagged.")
|
||||||
assert_equal(%w(aaa bbb ccc), post.tag_array)
|
assert_not_nil(@post.unapproval, "Post should have an unapproval record.")
|
||||||
post.tag_string = "ddd eee fff"
|
assert_equal("bad", @post.unapproval.reason)
|
||||||
post.update_attributes(
|
|
||||||
:updater_id => user.id,
|
|
||||||
:updater_ip_addr => "127.0.0.1",
|
|
||||||
:tag_string => "ddd eee fff"
|
|
||||||
)
|
|
||||||
assert_equal("ddd eee fff", post.tag_string)
|
|
||||||
assert_equal(%w(ddd eee fff), post.tag_array)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create the actual tag records" do
|
assert_raise(Unapproval::Error) {@post.unapprove!("bad", @user, "127.0.0.1")}
|
||||||
assert_difference("Tag.count", 3) do
|
end
|
||||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
|
||||||
|
should "not unapprove if no reason is given" do
|
||||||
|
assert_raise(Unapproval::Error) {@post.unapprove!("", @user, "127.0.0.1")}
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deleted" do
|
||||||
|
@post.delete!
|
||||||
|
assert(@post.is_deleted?, "Post should be deleted.")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be approved" do
|
||||||
|
@post.approve!
|
||||||
|
assert(!@post.is_pending?, "Post should not be pending.")
|
||||||
|
|
||||||
|
@deleted_post = Factory.create(:post, :is_deleted => true)
|
||||||
|
@deleted_post.approve!
|
||||||
|
assert(!@post.is_deleted?, "Post should not be deleted.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update the post counts of relevant tag records" do
|
context "A post version" do
|
||||||
post1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
should "be created on any save" do
|
||||||
post2 = Factory.create(:post, :tag_string => "bbb ccc ddd")
|
@user = Factory.create(:user)
|
||||||
post3 = Factory.create(:post, :tag_string => "ccc ddd eee")
|
@post = Factory.create(:post)
|
||||||
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
assert_equal(1, @post.versions.size)
|
||||||
assert_equal(2, Tag.find_by_name("bbb").post_count)
|
|
||||||
assert_equal(3, Tag.find_by_name("ccc").post_count)
|
@post.update_attributes(:rating => "e", :updater_id => @user.id, :updater_ip_addr => "125.0.0.0")
|
||||||
|
assert_equal(2, @post.versions.size)
|
||||||
|
assert_equal(@user.id, @post.versions.last.updater_id)
|
||||||
|
assert_equal("125.0.0.0", @post.versions.last.updater_ip_addr)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# should "be counted" do
|
context "A post's tags" do
|
||||||
# @user = Factory.create(:user)
|
setup do
|
||||||
# @artist_tag = Factory.create(:artist_tag)
|
@post = Factory.create(:post)
|
||||||
# @copyright_tag = Factory.create(:copyright_tag)
|
end
|
||||||
# @general_tag = Factory.create(:tag)
|
|
||||||
# @new_post = Factory.create(:post, :tag_string => "#{@artist_tag.name} #{@copyright_tag.name} #{@general_tag.name}")
|
should "have an array representation" do
|
||||||
# assert_equal(1, @new_post.tag_count_artist)
|
@post.set_tag_string("aaa bbb")
|
||||||
# assert_equal(1, @new_post.tag_count_copyright)
|
assert_equal(%w(aaa bbb), @post.tag_array)
|
||||||
# assert_equal(1, @new_post.tag_count_general)
|
assert_equal(%w(tag1 tag2), @post.tag_array_was)
|
||||||
# assert_equal(0, @new_post.tag_count_character)
|
end
|
||||||
# assert_equal(3, @new_post.tag_count)
|
|
||||||
#
|
should "reset the tag array cache when updated" do
|
||||||
# @new_post.update_attributes(:tag_string => "babs", :updater_id => @user.id, :updater_ip_addr => "127.0.0.1")
|
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
# assert_equal(0, @new_post.tag_count_artist)
|
user = Factory.create(:user)
|
||||||
# assert_equal(0, @new_post.tag_count_copyright)
|
assert_equal(%w(aaa bbb ccc), post.tag_array)
|
||||||
# assert_equal(1, @new_post.tag_count_general)
|
post.tag_string = "ddd eee fff"
|
||||||
# assert_equal(0, @new_post.tag_count_character)
|
post.update_attributes(
|
||||||
# assert_equal(1, @new_post.tag_count)
|
:updater_id => user.id,
|
||||||
# end
|
:updater_ip_addr => "127.0.0.1",
|
||||||
#
|
:tag_string => "ddd eee fff"
|
||||||
# should "be merged with any changes that were made after loading the initial set of tags part 1" do
|
)
|
||||||
# @user = Factory.create(:user)
|
assert_equal("ddd eee fff", post.tag_string)
|
||||||
# @post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
assert_equal(%w(ddd eee fff), post.tag_array)
|
||||||
#
|
end
|
||||||
# # user a adds <ddd>
|
|
||||||
# @post_edited_by_user_a = Post.find(@post.id)
|
should "create the actual tag records" do
|
||||||
# @post_edited_by_user_a.update_attributes(
|
assert_difference("Tag.count", 3) do
|
||||||
# :updater_id => @user.id,
|
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
# :updater_ip_addr => "127.0.0.1",
|
end
|
||||||
# :old_tag_string => "aaa bbb ccc",
|
end
|
||||||
# :tag_string => "aaa bbb ccc ddd"
|
|
||||||
# )
|
should "update the post counts of relevant tag records" do
|
||||||
#
|
post1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
# # user b removes <ccc> adds <eee>
|
post2 = Factory.create(:post, :tag_string => "bbb ccc ddd")
|
||||||
# @post_edited_by_user_b = Post.find(@post.id)
|
post3 = Factory.create(:post, :tag_string => "ccc ddd eee")
|
||||||
# @post_edited_by_user_b.update_attributes(
|
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
||||||
# :updater_id => @user.id,
|
assert_equal(2, Tag.find_by_name("bbb").post_count)
|
||||||
# :updater_ip_addr => "127.0.0.1",
|
assert_equal(3, Tag.find_by_name("ccc").post_count)
|
||||||
# :old_tag_string => "aaa bbb ccc",
|
end
|
||||||
# :tag_string => "aaa bbb eee"
|
|
||||||
# )
|
should "be counted" do
|
||||||
#
|
@user = Factory.create(:user)
|
||||||
# # final should be <aaa>, <bbb>, <ddd>, <eee>
|
@artist_tag = Factory.create(:artist_tag)
|
||||||
# @final_post = Post.find(@post.id)
|
@copyright_tag = Factory.create(:copyright_tag)
|
||||||
# assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
|
@general_tag = Factory.create(:tag)
|
||||||
# end
|
@new_post = Factory.create(:post, :tag_string => "#{@artist_tag.name} #{@copyright_tag.name} #{@general_tag.name}")
|
||||||
#
|
assert_equal(1, @new_post.tag_count_artist)
|
||||||
# should "be merged with any changes that were made after loading the initial set of tags part 2" do
|
assert_equal(1, @new_post.tag_count_copyright)
|
||||||
# # This is the same as part 1, only the order of operations is reversed.
|
assert_equal(1, @new_post.tag_count_general)
|
||||||
# # The results should be the same.
|
assert_equal(0, @new_post.tag_count_character)
|
||||||
#
|
assert_equal(3, @new_post.tag_count)
|
||||||
# @user = Factory.create(:user)
|
|
||||||
# @post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
@new_post.update_attributes(:tag_string => "babs", :updater_id => @user.id, :updater_ip_addr => "127.0.0.1")
|
||||||
#
|
assert_equal(0, @new_post.tag_count_artist)
|
||||||
# # user a removes <ccc> adds <eee>
|
assert_equal(0, @new_post.tag_count_copyright)
|
||||||
# @post_edited_by_user_a = Post.find(@post.id)
|
assert_equal(1, @new_post.tag_count_general)
|
||||||
# @post_edited_by_user_a.update_attributes(
|
assert_equal(0, @new_post.tag_count_character)
|
||||||
# :updater_id => @user.id,
|
assert_equal(1, @new_post.tag_count)
|
||||||
# :updater_ip_addr => "127.0.0.1",
|
end
|
||||||
# :old_tag_string => "aaa bbb ccc",
|
|
||||||
# :tag_string => "aaa bbb eee"
|
should "be merged with any changes that were made after loading the initial set of tags part 1" do
|
||||||
# )
|
@user = Factory.create(:user)
|
||||||
#
|
@post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
# # user b adds <ddd>
|
|
||||||
# @post_edited_by_user_b = Post.find(@post.id)
|
# user a adds <ddd>
|
||||||
# @post_edited_by_user_b.update_attributes(
|
@post_edited_by_user_a = Post.find(@post.id)
|
||||||
# :updater_id => @user.id,
|
@post_edited_by_user_a.update_attributes(
|
||||||
# :updater_ip_addr => "127.0.0.1",
|
:updater_id => @user.id,
|
||||||
# :old_tag_string => "aaa bbb ccc",
|
:updater_ip_addr => "127.0.0.1",
|
||||||
# :tag_string => "aaa bbb ccc ddd"
|
:old_tag_string => "aaa bbb ccc",
|
||||||
# )
|
:tag_string => "aaa bbb ccc ddd"
|
||||||
#
|
)
|
||||||
# # final should be <aaa>, <bbb>, <ddd>, <eee>
|
|
||||||
# @final_post = Post.find(@post.id)
|
# user b removes <ccc> adds <eee>
|
||||||
# assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
|
@post_edited_by_user_b = Post.find(@post.id)
|
||||||
# end
|
@post_edited_by_user_b.update_attributes(
|
||||||
# end
|
:updater_id => @user.id,
|
||||||
#
|
:updater_ip_addr => "127.0.0.1",
|
||||||
# context "Adding a meta-tag" do
|
:old_tag_string => "aaa bbb ccc",
|
||||||
# setup do
|
:tag_string => "aaa bbb eee"
|
||||||
# @post = Factory.create(:post)
|
)
|
||||||
# end
|
|
||||||
#
|
# final should be <aaa>, <bbb>, <ddd>, <eee>
|
||||||
# should "be ignored" do
|
@final_post = Post.find(@post.id)
|
||||||
# @user = Factory.create(:user)
|
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
|
||||||
#
|
end
|
||||||
# @post.update_attributes(
|
|
||||||
# :updater_id => @user.id,
|
should "be merged with any changes that were made after loading the initial set of tags part 2" do
|
||||||
# :updater_ip_addr => "127.0.0.1",
|
# This is the same as part 1, only the order of operations is reversed.
|
||||||
# :tag_string => "aaa pool:1234 pool:test rating:s fav:bob"
|
# The results should be the same.
|
||||||
# )
|
|
||||||
# assert_equal("aaa", @post.tag_string)
|
@user = Factory.create(:user)
|
||||||
# end
|
@post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||||
# end
|
|
||||||
#
|
# user a removes <ccc> adds <eee>
|
||||||
# context "Favoriting a post" do
|
@post_edited_by_user_a = Post.find(@post.id)
|
||||||
# should "update the favorite string" do
|
@post_edited_by_user_a.update_attributes(
|
||||||
# @user = Factory.create(:user)
|
:updater_id => @user.id,
|
||||||
# @post = Factory.create(:post)
|
:updater_ip_addr => "127.0.0.1",
|
||||||
# @post.add_favorite(@user)
|
:old_tag_string => "aaa bbb ccc",
|
||||||
# assert_equal("fav:#{@user.name}", @post.fav_string)
|
:tag_string => "aaa bbb eee"
|
||||||
#
|
)
|
||||||
# @post.remove_favorite(@user)
|
|
||||||
# assert_equal("", @post.fav_string)
|
# user b adds <ddd>
|
||||||
# end
|
@post_edited_by_user_b = Post.find(@post.id)
|
||||||
# end
|
@post_edited_by_user_b.update_attributes(
|
||||||
|
:updater_id => @user.id,
|
||||||
|
:updater_ip_addr => "127.0.0.1",
|
||||||
|
:old_tag_string => "aaa bbb ccc",
|
||||||
|
:tag_string => "aaa bbb ccc ddd"
|
||||||
|
)
|
||||||
|
|
||||||
|
# final should be <aaa>, <bbb>, <ddd>, <eee>
|
||||||
|
@final_post = Post.find(@post.id)
|
||||||
|
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(@final_post.tag_string).sort)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Adding a meta-tag" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be ignored" do
|
||||||
|
@user = Factory.create(:user)
|
||||||
|
|
||||||
|
@post.update_attributes(
|
||||||
|
:updater_id => @user.id,
|
||||||
|
:updater_ip_addr => "127.0.0.1",
|
||||||
|
:tag_string => "aaa pool:1234 pool:test rating:s fav:bob"
|
||||||
|
)
|
||||||
|
assert_equal("aaa", @post.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Favoriting a post" do
|
||||||
|
should "update the favorite string" do
|
||||||
|
@user = Factory.create(:user)
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
@post.add_favorite(@user)
|
||||||
|
assert_equal("fav:#{@user.name}", @post.fav_string)
|
||||||
|
|
||||||
|
@post.remove_favorite(@user)
|
||||||
|
assert_equal("", @post.fav_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "A tag search" do
|
context "A tag search" do
|
||||||
should "return posts for 1 tag" do
|
should "return posts for 1 tag" do
|
||||||
|
|||||||
Reference in New Issue
Block a user