added pool unit test
This commit is contained in:
@@ -2,4 +2,6 @@ Factory.define(:pool) do |f|
|
||||
f.name {Faker::Name.first_name}
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.description {Faker::Lorem.sentences}
|
||||
f.updater_id {|x| x.creator_id}
|
||||
f.updater_ip_addr "127.0.0.1"
|
||||
end
|
||||
|
||||
@@ -11,4 +11,5 @@ Factory.define(:post) do |f|
|
||||
f.image_width 100
|
||||
f.image_height 200
|
||||
f.file_size 2000
|
||||
f.rating "q"
|
||||
end
|
||||
|
||||
@@ -1,8 +1,65 @@
|
||||
require 'test_helper'
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class PoolTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "A pool" do
|
||||
should "create versions for each distinct user" do
|
||||
pool = Factory.create(:pool)
|
||||
user = Factory.create(:user)
|
||||
assert_equal(1, pool.versions(true).size)
|
||||
pool.update_attributes(:post_ids => "1", :updater_id => user.id, :updater_ip_addr => "128.0.0.1")
|
||||
assert_equal(2, pool.versions(true).size)
|
||||
pool.update_attributes(:post_ids => "1 2", :updater_id => user.id, :updater_ip_addr => "128.0.0.1")
|
||||
assert_equal(2, pool.versions(true).size)
|
||||
pool.revert_to!(PoolVersion.first)
|
||||
assert_equal("", pool.post_ids)
|
||||
end
|
||||
|
||||
should "have posts" do
|
||||
pool = Factory.create(:pool)
|
||||
p1 = Factory.create(:post)
|
||||
p2 = Factory.create(:post)
|
||||
p3 = Factory.create(:post)
|
||||
p4 = Factory.create(:post)
|
||||
p1.add_pool(pool)
|
||||
p2.add_pool(pool)
|
||||
p3.add_pool(pool)
|
||||
|
||||
assert_equal("#{p1.id} #{p2.id} #{p3.id}", pool.post_ids)
|
||||
assert_equal([p1.id, p2.id, p3.id], pool.post_id_array)
|
||||
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
|
||||
assert_equal(1, posts.size)
|
||||
assert_equal([p2.id], posts.map(&:id))
|
||||
end
|
||||
|
||||
should "return the neighboring posts for any member element" do
|
||||
pool = Factory.create(:pool)
|
||||
p1 = Factory.create(:post)
|
||||
p2 = Factory.create(:post)
|
||||
p3 = Factory.create(:post)
|
||||
p1.add_pool(pool)
|
||||
p2.add_pool(pool)
|
||||
p3.add_pool(pool)
|
||||
neighbors = pool.neighbor_posts(p1)
|
||||
assert_nil(neighbors[:previous])
|
||||
assert_equal(p2.id, neighbors[:next])
|
||||
neighbors = pool.neighbor_posts(p2)
|
||||
assert_equal(p1.id, neighbors[:previous])
|
||||
assert_equal(p3.id, neighbors[:next])
|
||||
neighbors = pool.neighbor_posts(p3)
|
||||
assert_equal(p2.id, neighbors[:previous])
|
||||
assert_nil(neighbors[:next])
|
||||
end
|
||||
end
|
||||
|
||||
context "An anonymous pool" do
|
||||
should "have a name starting with anonymous" do
|
||||
user = Factory.create(:user)
|
||||
pool = Pool.create_anonymous(user, "127.0.0.1")
|
||||
assert_match(/^anonymous:\d+$/, pool.name)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +45,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
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)
|
||||
|
||||
@post.revert_to!(PostVersion.first)
|
||||
assert_equal("tag1 tag2", @post.tag_string)
|
||||
assert_equal("q", @post.rating)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user