* Removed Pixa/Tinami sources
* Upgraded to Rails 3.2.3 * Fixed tests
This commit is contained in:
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
@@ -16,7 +16,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Deletion:" do
|
||||
context "Annihilating a post" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
context "that is status locked" do
|
||||
@@ -40,7 +40,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Deleting a post" do
|
||||
context "that is status locked" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post.update_attributes({:is_status_locked => true}, :as => :admin)
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the fast count" do
|
||||
post = Factory.create(:post, :tag_string => "aaa")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
assert_equal(1, Post.fast_count)
|
||||
assert_equal(1, Post.fast_count("aaa"))
|
||||
post.delete!
|
||||
@@ -61,14 +61,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "toggle the is_deleted flag" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
assert_equal(false, post.is_deleted?)
|
||||
post.delete!
|
||||
assert_equal(true, post.is_deleted?)
|
||||
end
|
||||
|
||||
should "decrement the tag counts" do
|
||||
post = Factory.create(:post, :tag_string => "aaa")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
||||
post.delete!
|
||||
assert_equal(0, Tag.find_by_name("aaa").post_count)
|
||||
@@ -79,17 +79,17 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Parenting:" do
|
||||
context "Assignining a parent to a post" do
|
||||
should "update the has_children flag on the parent" do
|
||||
p1 = Factory.create(:post)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
assert(!p1.has_children?, "Parent should not have any children")
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
p1.reload
|
||||
assert(p1.has_children?, "Parent not updated after child was added")
|
||||
end
|
||||
|
||||
should "update the has_children flag on the old parent" do
|
||||
p1 = Factory.create(:post)
|
||||
p2 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
p2 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c1.parent_id = p2.id
|
||||
c1.save
|
||||
p1.reload
|
||||
@@ -99,15 +99,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "validate that the parent exists" do
|
||||
post = Factory.build(:post, :parent_id => 1_000_000)
|
||||
post = FactoryGirl.build(:post, :parent_id => 1_000_000)
|
||||
post.save
|
||||
assert(post.errors[:parent].any?, "Parent should be invalid")
|
||||
end
|
||||
|
||||
should "fail if the parent has a parent" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
c2 = Factory.build(:post, :parent_id => c1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c2 = FactoryGirl.build(:post, :parent_id => c1.id)
|
||||
c2.save
|
||||
assert(c2.errors[:parent].any?, "Parent should be invalid")
|
||||
end
|
||||
@@ -116,17 +116,17 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Destroying a post with" do
|
||||
context "a parent" do
|
||||
should "reset the has_children flag of the parent" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c1.delete!
|
||||
p1.reload
|
||||
assert_equal(false, p1.has_children?)
|
||||
end
|
||||
|
||||
should "reassign favorites to the parent" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
user = Factory.create(:user)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
user = FactoryGirl.create(:user)
|
||||
c1.add_favorite!(user)
|
||||
c1.delete!
|
||||
p1.reload
|
||||
@@ -135,8 +135,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the parent's has_children flag" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c1.delete!
|
||||
p1.reload
|
||||
assert(!p1.has_children?, "Parent should not have children")
|
||||
@@ -145,15 +145,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "one child" do
|
||||
should "remove the has_children flag" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
p1.delete!
|
||||
assert_equal(false, p1.has_children?)
|
||||
end
|
||||
|
||||
should "remove the parent of that child" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
p1.delete!
|
||||
c1.reload
|
||||
assert_nil(c1.parent)
|
||||
@@ -162,10 +162,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "two or more children" do
|
||||
should "reparent all children to the first child" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
c2 = Factory.create(:post, :parent_id => p1.id)
|
||||
c3 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c2 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c3 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
p1.delete!
|
||||
c1.reload
|
||||
c2.reload
|
||||
@@ -179,8 +179,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Undestroying a post with a parent" do
|
||||
should "not preserve the parent's has_children flag" do
|
||||
p1 = Factory.create(:post)
|
||||
c1 = Factory.create(:post, :parent_id => p1.id)
|
||||
p1 = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
|
||||
c1.delete!
|
||||
c1.undelete!
|
||||
p1.reload
|
||||
@@ -193,7 +193,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Moderation:" do
|
||||
context "A deleted post" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :is_deleted => true)
|
||||
@post = FactoryGirl.create(:post, :is_deleted => true)
|
||||
end
|
||||
|
||||
context "that is status locked" do
|
||||
@@ -225,7 +225,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "An approved post" do
|
||||
should "be flagged" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
assert_difference("PostFlag.count", 1) do
|
||||
post.flag!("bad")
|
||||
end
|
||||
@@ -234,7 +234,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not be flagged if no reason is given" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
assert_difference("PostFlag.count", 0) do
|
||||
assert_raises(PostFlag::Error) do
|
||||
post.flag!("")
|
||||
@@ -245,14 +245,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "An unapproved post" do
|
||||
should "preserve the approver's identity when approved" do
|
||||
post = Factory.create(:post, :is_pending => true)
|
||||
post = FactoryGirl.create(:post, :is_pending => true)
|
||||
post.approve!
|
||||
assert_equal(post.approver_id, CurrentUser.id)
|
||||
end
|
||||
|
||||
context "that was uploaded by person X" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post.flag!("reason")
|
||||
end
|
||||
|
||||
@@ -269,9 +269,9 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that was previously approved by person X" do
|
||||
setup do
|
||||
@user = Factory.create(:janitor_user, :name => "xxx")
|
||||
@user2 = Factory.create(:janitor_user, :name => "yyy")
|
||||
@post = Factory.create(:post, :approver_id => @user.id)
|
||||
@user = FactoryGirl.create(:janitor_user, :name => "xxx")
|
||||
@user2 = FactoryGirl.create(:janitor_user, :name => "yyy")
|
||||
@post = FactoryGirl.create(:post, :approver_id => @user.id)
|
||||
@post.flag!("bad")
|
||||
end
|
||||
|
||||
@@ -294,7 +294,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been reapproved" do
|
||||
should "no longer be flagged or pending" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
post.flag!("bad")
|
||||
post.approve!
|
||||
assert(post.errors.empty?, post.errors.full_messages.join(", "))
|
||||
@@ -307,7 +307,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "A status locked post" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post.update_attributes({:is_status_locked => true}, :as => :admin)
|
||||
end
|
||||
|
||||
@@ -334,13 +334,13 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Tagging:" do
|
||||
context "A post" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
context "tagged with a metatag" do
|
||||
context "for a parent" do
|
||||
setup do
|
||||
@parent = Factory.create(:post)
|
||||
@parent = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
should "update the parent relationships for both posts" do
|
||||
@@ -355,7 +355,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "for a pool" do
|
||||
context "id" do
|
||||
setup do
|
||||
@pool = Factory.create(:pool)
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@post.update_attributes(:tag_string => "aaa pool:#{@pool.id}")
|
||||
end
|
||||
|
||||
@@ -370,7 +370,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "name" do
|
||||
context "that exists" do
|
||||
setup do
|
||||
@pool = Factory.create(:pool, :name => "abc")
|
||||
@pool = FactoryGirl.create(:pool, :name => "abc")
|
||||
@post.update_attributes(:tag_string => "aaa pool:abc")
|
||||
end
|
||||
|
||||
@@ -423,7 +423,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "have an array representation of its tags" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
post.set_tag_string("aaa bbb")
|
||||
assert_equal(%w(aaa bbb), post.tag_array)
|
||||
assert_equal(%w(tag1 tag2), post.tag_array_was)
|
||||
@@ -431,7 +431,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been updated" do
|
||||
should "increment the updater's post_update_count" do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
|
||||
assert_difference("CurrentUser.post_update_count", 1) do
|
||||
post.update_attributes(:tag_string => "zzz")
|
||||
@@ -440,8 +440,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "reset its tag array cache" do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
user = Factory.create(:user)
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
user = FactoryGirl.create(:user)
|
||||
assert_equal(%w(aaa bbb ccc), post.tag_array)
|
||||
post.tag_string = "ddd eee fff"
|
||||
post.tag_string = "ddd eee fff"
|
||||
@@ -452,14 +452,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
should "create the actual tag records" do
|
||||
assert_difference("Tag.count", 3) do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post counts of relevant tag records" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post2 = Factory.create(:post, :tag_string => "bbb ccc ddd")
|
||||
post3 = Factory.create(:post, :tag_string => "ccc ddd eee")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "bbb ccc ddd")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "ccc ddd eee")
|
||||
assert_equal(1, Tag.find_by_name("aaa").post_count)
|
||||
assert_equal(2, Tag.find_by_name("bbb").post_count)
|
||||
assert_equal(3, Tag.find_by_name("ccc").post_count)
|
||||
@@ -474,10 +474,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update its tag counts" do
|
||||
artist_tag = Factory.create(:artist_tag)
|
||||
copyright_tag = Factory.create(:copyright_tag)
|
||||
general_tag = Factory.create(:tag)
|
||||
new_post = Factory.create(:post, :tag_string => "#{artist_tag.name} #{copyright_tag.name} #{general_tag.name}")
|
||||
artist_tag = FactoryGirl.create(:artist_tag)
|
||||
copyright_tag = FactoryGirl.create(:copyright_tag)
|
||||
general_tag = FactoryGirl.create(:tag)
|
||||
new_post = FactoryGirl.create(:post, :tag_string => "#{artist_tag.name} #{copyright_tag.name} #{general_tag.name}")
|
||||
assert_equal(1, new_post.tag_count_artist)
|
||||
assert_equal(1, new_post.tag_count_copyright)
|
||||
assert_equal(1, new_post.tag_count_general)
|
||||
@@ -494,7 +494,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "merge any changes that were made after loading the initial set of tags part 1" do
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
|
||||
# user a adds <ddd>
|
||||
post_edited_by_user_a = Post.find(post.id)
|
||||
@@ -517,7 +517,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
# This is the same as part 1, only the order of operations is reversed.
|
||||
# The results should be the same.
|
||||
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
|
||||
# user a removes <ccc> adds <eee>
|
||||
post_edited_by_user_a = Post.find(post.id)
|
||||
@@ -539,7 +539,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been tagged with a metatag" do
|
||||
should "not include the metatag in its tag string" do
|
||||
post = Factory.create(:post)
|
||||
post = FactoryGirl.create(:post)
|
||||
post.tag_string = "aaa pool:1234 pool:test rating:s fav:bob"
|
||||
post.save
|
||||
assert_equal("aaa", post.tag_string)
|
||||
@@ -551,10 +551,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Favorites:" do
|
||||
context "Removing a post from a user's favorites" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
@post.add_favorite!(@user)
|
||||
end
|
||||
|
||||
@@ -571,7 +571,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not decrement the user's favorite_count if the user did not favorite the post" do
|
||||
@post2 = Factory.create(:post)
|
||||
@post2 = FactoryGirl.create(:post)
|
||||
assert_difference("CurrentUser.favorite_count", 0) do
|
||||
@post2.remove_favorite!(@user)
|
||||
CurrentUser.reload
|
||||
@@ -581,10 +581,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Adding a post to a user's favorites" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = Factory.create(:post)
|
||||
@post = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -626,8 +626,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Pools:" do
|
||||
context "Removing a post from a pool" do
|
||||
should "update the post's pool string" do
|
||||
post = Factory.create(:post)
|
||||
pool = Factory.create(:pool)
|
||||
post = FactoryGirl.create(:post)
|
||||
pool = FactoryGirl.create(:pool)
|
||||
post.add_pool!(pool)
|
||||
post.remove_pool!(pool)
|
||||
post.reload
|
||||
@@ -640,8 +640,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Adding a post to a pool" do
|
||||
should "update the post's pool string" do
|
||||
post = Factory.create(:post)
|
||||
pool = Factory.create(:pool)
|
||||
post = FactoryGirl.create(:post)
|
||||
pool = FactoryGirl.create(:pool)
|
||||
post.add_pool!(pool)
|
||||
post.reload
|
||||
assert_equal("pool:#{pool.id}", post.pool_string)
|
||||
@@ -658,10 +658,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Uploading:" do
|
||||
context "Uploading a post" do
|
||||
should "capture who uploaded the post" do
|
||||
post = Factory.create(:post)
|
||||
user1 = Factory.create(:user)
|
||||
user2 = Factory.create(:user)
|
||||
user3 = Factory.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
user1 = FactoryGirl.create(:user)
|
||||
user2 = FactoryGirl.create(:user)
|
||||
user3 = FactoryGirl.create(:user)
|
||||
|
||||
post.uploader = user1
|
||||
assert_equal(user1.id, post.uploader_id)
|
||||
@@ -676,9 +676,9 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Searching:" do
|
||||
should "return posts for 1 tag" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa")
|
||||
assert_equal(2, relation.count)
|
||||
assert_equal(post2.id, relation.all[0].id)
|
||||
@@ -686,27 +686,27 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for a 2 tag join" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for 1 tag with exclusion" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa -bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for 1 tag with a pattern" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("a*")
|
||||
assert_equal(2, relation.count)
|
||||
assert_equal(post2.id, relation.all[0].id)
|
||||
@@ -714,18 +714,18 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for 2 tags, one with a pattern" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("a* bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for the <id> metatag" do
|
||||
post1 = Factory.create(:post)
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
relation = Post.tag_match("id:#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
@@ -738,10 +738,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <fav> metatag" do
|
||||
post1 = Factory.create(:post)
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
user = Factory.create(:user)
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
user = FactoryGirl.create(:user)
|
||||
post1.add_favorite!(user)
|
||||
relation = Post.tag_match("fav:#{user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
@@ -749,10 +749,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <pool> metatag" do
|
||||
post1 = Factory.create(:post)
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
pool = Factory.create(:pool, :name => "xxx")
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
pool = FactoryGirl.create(:pool, :name => "xxx")
|
||||
post1.add_pool!(pool)
|
||||
relation = Post.tag_match("pool:xxx")
|
||||
assert_equal(1, relation.count)
|
||||
@@ -760,14 +760,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <uploader> metatag" do
|
||||
second_user = Factory.create(:user)
|
||||
post1 = Factory.create(:post, :uploader => CurrentUser.user)
|
||||
second_user = FactoryGirl.create(:user)
|
||||
post1 = FactoryGirl.create(:post, :uploader => CurrentUser.user)
|
||||
|
||||
assert_equal(CurrentUser.id, post1.uploader_id)
|
||||
|
||||
CurrentUser.scoped(second_user, "127.0.0.2") do
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
relation = Post.tag_match("uploader:#{CurrentUser.user.name}")
|
||||
@@ -776,53 +776,53 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for a list of md5 hashes" do
|
||||
post1 = Factory.create(:post, :md5 => "abcd")
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
post1 = FactoryGirl.create(:post, :md5 => "abcd")
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
relation = Post.tag_match("md5:abcd")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for a source search" do
|
||||
post1 = Factory.create(:post, :source => "abcd")
|
||||
post2 = Factory.create(:post, :source => "abcdefg")
|
||||
post3 = Factory.create(:post, :source => "xyz")
|
||||
post1 = FactoryGirl.create(:post, :source => "abcd")
|
||||
post2 = FactoryGirl.create(:post, :source => "abcdefg")
|
||||
post3 = FactoryGirl.create(:post, :source => "xyz")
|
||||
relation = Post.tag_match("source:abcde")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for a tag subscription search" do
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
sub = Factory.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
|
||||
TagSubscription.process_all
|
||||
relation = Post.tag_match("sub:#{CurrentUser.name}")
|
||||
assert_equal(1, relation.count)
|
||||
end
|
||||
|
||||
should "return posts for a particular rating" do
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "q")
|
||||
post3 = Factory.create(:post, :rating => "e")
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "q")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e")
|
||||
relation = Post.tag_match("rating:e")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for a particular negated rating" do
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "s")
|
||||
post3 = Factory.create(:post, :rating => "e")
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "s")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e")
|
||||
relation = Post.tag_match("-rating:s")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts ordered by a particular attribute" do
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "s")
|
||||
post3 = Factory.create(:post, :rating => "e", :score => 5, :image_width => 1000)
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "s")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e", :score => 5, :image_width => 1000)
|
||||
relation = Post.tag_match("order:id")
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
relation = Post.tag_match("order:mpixels")
|
||||
@@ -832,14 +832,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "fail for exclusive tag searches with no other tag" do
|
||||
post1 = Factory.create(:post, :rating => "s", :tag_string => "aaa")
|
||||
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
|
||||
assert_raise(::Post::SearchError) do
|
||||
relation = Post.tag_match("-aaa")
|
||||
end
|
||||
end
|
||||
|
||||
should "succeed for exclusive tag searches combined with a metatag" do
|
||||
post1 = Factory.create(:post, :rating => "s", :tag_string => "aaa")
|
||||
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
|
||||
assert_nothing_raised do
|
||||
relation = Post.tag_match("-aaa id:>0")
|
||||
end
|
||||
@@ -848,8 +848,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Voting:" do
|
||||
should "not allow duplicate votes" do
|
||||
user = Factory.create(:user)
|
||||
post = Factory.create(:post)
|
||||
user = FactoryGirl.create(:user)
|
||||
post = FactoryGirl.create(:post)
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
assert_nothing_raised {post.vote!("up")}
|
||||
assert_raises(PostVote::Error) {post.vote!("up")}
|
||||
@@ -864,7 +864,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Creating a post" do
|
||||
should "increment the post count" do
|
||||
assert_equal(0, Post.fast_count(""))
|
||||
post = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
assert_equal(1, Post.fast_count(""))
|
||||
assert_equal(1, Post.fast_count("aaa"))
|
||||
assert_equal(1, Post.fast_count("bbb"))
|
||||
@@ -884,7 +884,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Reverting: " do
|
||||
context "a post that has been updated" do
|
||||
setup do
|
||||
@post = Factory.create(:post, :rating => "q", :tag_string => "aaa")
|
||||
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa")
|
||||
@post.update_attributes(:tag_string => "aaa bbb ccc ddd")
|
||||
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
|
||||
@post.update_attributes(:tag_string => "bbb mmm yyy", :source => "abc")
|
||||
|
||||
Reference in New Issue
Block a user