From 8b98e9e009bb6c9a8a5017dc88bff0a8aededaac Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Thu, 26 Apr 2018 11:14:01 -0700 Subject: [PATCH] additional tests to look for causes of incorrect post count on pools (#3667) --- test/unit/pool_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index 1b2b4e3ec..fddf0f8d7 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -52,6 +52,17 @@ class PoolTest < ActiveSupport::TestCase end end + context "Creating a pool" do + setup do + @posts = FactoryBot.create_list(:post, 5) + @pool = FactoryBot.create(:pool, post_ids: @posts.map(&:id).join(" ")) + end + + should "initialize the post count" do + assert_equal(@posts.size, @pool.post_count) + end + end + context "Reverting a pool" do setup do PoolArchive.stubs(:enabled?).returns(true) @@ -114,6 +125,18 @@ class PoolTest < ActiveSupport::TestCase @pool.add!(@p1) end + context "by #attributes=" do + setup do + @pool.attributes = {post_ids: [@p1, @p2].map(&:id).join(" ")} + @pool.synchronize + @pool.save + end + + should "initialize the post count" do + assert_equal(2, @pool.post_count) + end + end + should "add the post to the pool" do assert_equal("#{@p1.id}", @pool.post_ids) end