* meta_search now pulls directly from GitHub

* Updated gems
* [inprogress] New pagination helpers used instead of pagination presenters
* [inprogress] Favorites refactored to use ActiveRecord
* [inprogress] PostSets refactored to use a decorator/dependency injection pattern
* [inprogress] Made pool/post interaction more robust
* Pool#posts now returns an ActiveRelation object
* Fixed unit tests
This commit is contained in:
albert
2011-06-07 17:34:09 -04:00
parent 435d3bf6e2
commit 49b3d43ddd
17 changed files with 248 additions and 136 deletions

View File

@@ -14,10 +14,6 @@ class PoolTest < ActiveSupport::TestCase
end
context "A pool" do
setup do
MEMCACHE.flush_all
end
should "create versions for each distinct user" do
pool = Factory.create(:pool)
user = Factory.create(:user)
@@ -39,9 +35,6 @@ class PoolTest < ActiveSupport::TestCase
p2 = Factory.create(:post)
p3 = Factory.create(:post)
p4 = Factory.create(:post)
p1.add_pool(pool)
p2.add_pool(pool)
p3.add_pool(pool)
pool.add_post!(p1)
pool.add_post!(p2)
pool.add_post!(p3)
@@ -52,7 +45,7 @@ class PoolTest < ActiveSupport::TestCase
posts = pool.posts.all
assert_equal(3, posts.size)
assert_equal([p1.id, p2.id, p3.id], posts.map(&:id))
posts = pool.posts(:limit => 1, :offset => 1).all
posts = pool.posts.limit(1).offset(1).all
assert_equal(1, posts.size)
assert_equal([p2.id], posts.map(&:id))
end
@@ -62,27 +55,75 @@ class PoolTest < ActiveSupport::TestCase
p1 = Factory.create(:post)
p2 = Factory.create(:post)
p3 = Factory.create(:post)
p1.add_pool(pool)
p2.add_pool(pool)
p3.add_pool(pool)
pool.add_post!(p1)
pool.add_post!(p2)
pool.add_post!(p3)
pool.reload
neighbors = pool.neighbor_posts(p1)
assert_nil(neighbors[:previous])
assert_equal(p2.id, neighbors[:next])
assert_nil(neighbors.previous)
assert_equal(p2.id, neighbors.next)
pool.reload
neighbors = pool.neighbor_posts(p2)
assert_equal(p1.id, neighbors[:previous])
assert_equal(p3.id, neighbors[:next])
assert_equal(p1.id, neighbors.previous)
assert_equal(p3.id, neighbors.next)
pool.reload
neighbors = pool.neighbor_posts(p3)
assert_equal(p2.id, neighbors[:previous])
assert_nil(neighbors[:next])
assert_equal(p2.id, neighbors.previous)
assert_nil(neighbors.next)
end
should "know what its post_ids were" do
p1 = Factory.create(:post)
p2 = Factory.create(:post)
pool = Factory.create(:pool, :post_ids => "#{p1.id}")
pool.post_id_array = [p1.id, p2.id]
assert_equal([p1.id], pool.post_id_array_was)
end
should "update its posts if the post_ids is updated directly" do
p1 = Factory.create(:post)
p2 = Factory.create(:post)
pool = Factory.create(:pool, :post_ids => "#{p1.id}")
pool.post_id_array = [p1.id, p2.id]
pool.save
p1.reload
p2.reload
assert_equal("pool:#{pool.id}", p1.pool_string)
assert_equal("pool:#{pool.id}", p2.pool_string)
end
should "set its post count even if post_ids is updated directly" do
p1 = Factory.create(:post)
p2 = Factory.create(:post)
pool = Factory.create(:pool, :post_ids => "#{p1.id}")
pool.post_id_array = [p1.id, p2.id]
pool.save
assert_equal(2, pool.post_count)
end
should "increment the post count every time a post is added" do
p1 = Factory.create(:post)
pool = Factory.create(:pool)
pool.add_post!(p1)
assert_equal(1, pool.post_count)
end
should "not double increment when the same post is readded" do
p1 = Factory.create(:post)
pool = Factory.create(:pool)
pool.add_post!(p1)
pool.add_post!(p1)
assert_equal(1, pool.post_count)
end
should "not double decrement" do
p1 = Factory.create(:post)
pool = Factory.create(:pool)
pool.remove_post!(p1)
assert_equal(0, pool.post_count)
end
end

View File

@@ -16,9 +16,6 @@ module PostSets
@pool.add_post!(@post_2)
@pool.add_post!(@post_1)
@pool.add_post!(@post_3)
@post_2.add_pool(@pool)
@post_1.add_pool(@pool)
@post_3.add_pool(@pool)
@set = PostSets::Pool.new(@pool, :page => 1)
end

View File

@@ -356,20 +356,31 @@ class PostTest < ActiveSupport::TestCase
end
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.add_pool!(pool)
post.remove_pool!(pool)
post.reload
assert_equal("", post.pool_string)
post.remove_pool!(pool)
post.reload
assert_equal("", post.pool_string)
end
end
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.add_pool(pool)
post.add_pool!(pool)
post.reload
assert_equal("pool:#{pool.id}", post.pool_string)
post.add_pool(pool)
post.add_pool!(pool)
post.reload
assert_equal("pool:#{pool.id}", post.pool_string)
post.remove_pool(pool)
post.reload
assert_equal("", post.pool_string)
post.remove_pool(pool)
post.remove_pool!(pool)
post.reload
assert_equal("", post.pool_string)
end
@@ -474,7 +485,7 @@ class PostTest < ActiveSupport::TestCase
post2 = Factory.create(:post)
post3 = Factory.create(:post)
pool = Factory.create(:pool)
post1.add_pool(pool)
post1.add_pool!(pool)
relation = Post.tag_match("pool:#{pool.name}")
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)

View File

@@ -2,7 +2,7 @@ require_relative '../test_helper'
class UploadTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = Factory.create(:contributor_user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all

View File

@@ -1,39 +1,28 @@
require_relative '../test_helper'
class UserFeedbackTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A user's feedback" do
setup do
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "should not validate if the creator is not privileged" do
user = Factory.create(:user)
admin = Factory.create(:admin_user)
moderator = Factory.create(:moderator_user)
janitor = Factory.create(:janitor_user)
contributor = Factory.create(:contributor_user)
privileged = Factory.create(:privileged_user)
member = Factory.create(:user)
feedback = Factory.create(:user_feedback, :user => user, :creator => admin)
CurrentUser.user = privileged
feedback = Factory.create(:user_feedback, :user => user)
assert(feedback.errors.empty?)
feedback = Factory.create(:user_feedback, :user => user, :creator => moderator)
assert(feedback.errors.empty?)
feedback = Factory.create(:user_feedback, :user => user, :creator => janitor)
assert(feedback.errors.empty?)
feedback = Factory.create(:user_feedback, :user => user, :creator => contributor)
assert(feedback.errors.empty?)
feedback = Factory.create(:user_feedback, :user => user, :creator => privileged)
assert(feedback.errors.empty?)
feedback = Factory.build(:user_feedback, :user => user, :creator => member)
CurrentUser.user = member
feedback = Factory.build(:user_feedback, :user => user)
feedback.save
assert(feedback.errors.any?)
end