added pool/uploader tests to post unit test

This commit is contained in:
albert 2010-02-11 23:26:38 -05:00
parent 72d1ece96a
commit d388b1b3bd
2 changed files with 30 additions and 2 deletions

View File

@ -187,7 +187,7 @@ class Post < ActiveRecord::Base
if old_tag_string
# If someone else committed changes to this post before we did,
# then try to merge the tag changes together.
current_tags = Tag.scan_tags(tag_string_was)
current_tags = tag_array_was()
new_tags = tag_array()
old_tags = Tag.scan_tags(old_tag_string)
set_tag_string(((current_tags + new_tags) - old_tags + (current_tags & new_tags)).uniq.join(" "))
@ -451,7 +451,7 @@ class Post < ActiveRecord::Base
self.pool_string.strip!
end
def remove_pool(user_id)
def remove_pool(pool)
self.pool_string.gsub!(/pool:#{pool.name}\b\s*/, " ")
self.pool_string.strip!
end

View File

@ -194,6 +194,34 @@ class PostTest < ActiveSupport::TestCase
assert_equal("", @post.fav_string)
end
end
context "Pooling a post" do
should "work" do
post = Factory.create(:post)
pool = Factory.create(:pool)
post.add_pool(pool)
assert_equal("pool:#{pool.name}", post.pool_string)
post.remove_pool(pool)
assert_equal("", post.pool_string)
end
end
context "A post's uploader" do
should "be defined" do
post = Factory.create(:post)
user1 = Factory.create(:user)
user2 = Factory.create(:user)
user3 = Factory.create(:user)
post.uploader = user1
assert_equal("uploader:#{user1.name}", post.uploader_string)
post.uploader_id = user2.id
assert_equal("uploader:#{user2.name}", post.uploader_string)
assert_equal(user2.id, post.uploader_id)
assert_equal(user2.name, post.uploader_name)
end
end
context "A tag search" do
should "return posts for 1 tag" do