From d388b1b3bdf6b0cd4de0b55885f9d47cae8882ad Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 11 Feb 2010 23:26:38 -0500 Subject: [PATCH] added pool/uploader tests to post unit test --- app/models/post.rb | 4 ++-- test/unit/post_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index e5474a5a9..858fad418 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 9b362d984..fd46d6a05 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -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