pools: store post_ids as array instead of string (fix #3979)

This commit is contained in:
evazion
2018-11-08 11:32:58 -06:00
parent 8515bf43b4
commit 115ed16a96
14 changed files with 92 additions and 113 deletions

View File

@@ -21,14 +21,14 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
should "add a post to a pool" do
post_auth pool_element_path, @user, params: {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}
@pool.reload
assert_equal([@post.id], @pool.post_id_array)
assert_equal([@post.id], @pool.post_ids)
end
should "add a post to a pool once and only once" do
as_user { @pool.add!(@post) }
post_auth pool_element_path, @user, params: {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}
@pool.reload
assert_equal([@post.id], @pool.post_id_array)
assert_equal([@post.id], @pool.post_ids)
end
end
@@ -40,7 +40,7 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
should "remove a post from a pool" do
delete_auth pool_element_path, @user, params: {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}
@pool.reload
assert_equal([], @pool.post_id_array)
assert_equal([], @pool.post_ids)
end
should "do nothing if the post is not a member of the pool" do
@@ -50,7 +50,7 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
end
delete_auth pool_element_path, @user, params: {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}
@pool.reload
assert_equal([], @pool.post_id_array)
assert_equal([], @pool.post_ids)
end
end
end

View File

@@ -71,9 +71,9 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
context "update action" do
should "update a pool" do
put_auth pool_path(@pool), @user, params: { pool: { name: "xyz", post_ids: @post.id.to_s }}
put_auth pool_path(@pool), @user, params: { pool: { name: "xyz", post_ids: [@post.id] }}
assert_equal("xyz", @pool.reload.name)
assert_equal(@post.id.to_s, @pool.post_ids)
assert_equal([@post.id], @pool.post_ids)
end
should "not allow updating unpermitted attributes" do
@@ -110,10 +110,10 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
setup do
as_user do
@post_2 = create(:post)
@pool = create(:pool, :post_ids => "#{@post.id}")
@pool = create(:pool, post_ids: [@post.id])
end
CurrentUser.scoped(@user, "1.2.3.4") do
@pool.update(:post_ids => "#{@post.id} #{@post_2.id}")
@pool.update(post_ids: [@post.id, @post_2.id])
end
end
@@ -123,7 +123,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
assert_equal([@post.id], version.post_ids)
put_auth revert_pool_path(@pool), @mod, params: {:version_id => version.id}
@pool.reload
assert_equal([@post.id], @pool.post_id_array)
assert_equal([@post.id], @pool.post_ids)
end
should "not allow reverting to a previous version of another pool" do

View File

@@ -55,7 +55,7 @@ class PoolTest < ActiveSupport::TestCase
context "Creating a pool" do
setup do
@posts = FactoryBot.create_list(:post, 5)
@pool = FactoryBot.create(:pool, post_ids: @posts.map(&:id).join(" "))
@pool = FactoryBot.create(:pool, post_ids: @posts.map(&:id))
end
should "initialize the post count" do
@@ -104,7 +104,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "update its post_ids" do
assert_equal([@p1.id], @pool.post_id_array)
assert_equal([@p1.id], @pool.post_ids)
end
should "update any old posts that were removed" do
@@ -132,7 +132,7 @@ class PoolTest < ActiveSupport::TestCase
context "by #attributes=" do
setup do
@pool.attributes = {post_ids: [@p1, @p2].map(&:id).join(" ")}
@pool.attributes = {post_ids: [@p1.id, @p2.id]}
@pool.synchronize
@pool.save
end
@@ -143,7 +143,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "add the post to the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
assert_equal([@p1.id], @pool.post_ids)
end
should "add the pool to the post" do
@@ -160,7 +160,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "not double add the post to the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
assert_equal([@p1.id], @pool.post_ids)
end
should "not double add the pool to the post" do
@@ -178,7 +178,7 @@ class PoolTest < ActiveSupport::TestCase
CurrentUser.user = FactoryBot.create(:builder_user)
@pool.update_attribute(:is_deleted, true)
@pool.post_ids = "#{@pool.post_ids} #{@p2.id}"
@pool.post_ids += [@p2.id]
@pool.synchronize!
@pool.save
@pool.reload
@@ -186,7 +186,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "add the post to the pool" do
assert_equal("#{@p1.id} #{@p2.id}", @pool.post_ids)
assert_equal([@p1.id, @p2.id], @pool.post_ids)
end
should "add the pool to the post" do
@@ -210,7 +210,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "remove the post from the pool" do
assert_equal("", @pool.post_ids)
assert_equal([], @pool.post_ids)
end
should "remove the pool from the post" do
@@ -228,7 +228,7 @@ class PoolTest < ActiveSupport::TestCase
end
should "not affect the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
assert_equal([@p1.id], @pool.post_ids)
end
should "not affect the post" do
@@ -275,7 +275,7 @@ class PoolTest < ActiveSupport::TestCase
user2 = Timecop.travel(1.month.ago) {FactoryBot.create(:user)}
CurrentUser.scoped(user2, "127.0.0.2") do
@pool.post_ids = "#{@p1.id}"
@pool.post_ids = [@p1.id]
@pool.save
end
@@ -285,7 +285,7 @@ class PoolTest < ActiveSupport::TestCase
assert_equal("127.0.0.2", @pool.versions.last.updater_ip_addr.to_s)
CurrentUser.scoped(user2, "127.0.0.3") do
@pool.post_ids = "#{@p1.id} #{@p2.id}"
@pool.post_ids = [@p1.id, @p2.id]
@pool.save
end
@@ -304,9 +304,8 @@ class PoolTest < ActiveSupport::TestCase
end
should "know what its post ids were previously" do
@pool.post_ids = "#{@p1.id}"
assert_equal("", @pool.post_ids_was)
assert_equal([], @pool.post_id_array_was)
@pool.post_ids = [@p1.id]
assert_equal([], @pool.post_ids_was)
end
should "normalize its name" do
@@ -318,8 +317,8 @@ class PoolTest < ActiveSupport::TestCase
end
should "normalize its post ids" do
@pool.update_attributes(:post_ids => " 1 2 ")
assert_equal("1 2", @pool.post_ids)
@pool.update(category: "collection", post_ids: [1, 2, 2, 3, 1])
assert_equal([1, 2, 3], @pool.post_ids)
end
context "when validating names" do
@@ -343,14 +342,14 @@ class PoolTest < ActiveSupport::TestCase
context "that is synchronized" do
setup do
@pool.reload
@pool.post_ids = "#{@p2.id}"
@pool.post_ids = [@p2.id]
@pool.synchronize!
end
should "update the pool" do
@pool.reload
assert_equal(1, @pool.post_count)
assert_equal("#{@p2.id}", @pool.post_ids)
assert_equal([@p2.id], @pool.post_ids)
end
should "update the posts" do

View File

@@ -115,11 +115,11 @@ class PostTest < ActiveSupport::TestCase
end
should "remove the post from all pools" do
assert_equal("", @pool.post_ids)
assert_equal([], @pool.post_ids)
end
should "remove the post from deleted pools" do
assert_equal("", @deleted_pool.post_ids)
assert_equal([], @deleted_pool.post_ids)
end
should "destroy the record" do
@@ -840,7 +840,7 @@ class PostTest < ActiveSupport::TestCase
should "add the post to the pool" do
@post.reload
@pool.reload
assert_equal("#{@post.id}", @pool.post_ids)
assert_equal([@post.id], @pool.post_ids)
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
end
end
@@ -857,7 +857,7 @@ class PostTest < ActiveSupport::TestCase
should "remove the post from the pool" do
@post.reload
@pool.reload
assert_equal("", @pool.post_ids)
assert_equal([], @pool.post_ids)
assert_equal("", @post.pool_string)
end
end
@@ -871,7 +871,7 @@ class PostTest < ActiveSupport::TestCase
should "add the post to the pool" do
@post.reload
@pool.reload
assert_equal("#{@post.id}", @pool.post_ids)
assert_equal([@post.id], @pool.post_ids)
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
end
end
@@ -886,7 +886,7 @@ class PostTest < ActiveSupport::TestCase
should "add the post to the pool" do
@post.reload
@pool.reload
assert_equal("#{@post.id}", @pool.post_ids)
assert_equal([@post.id], @pool.post_ids)
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
end
end
@@ -897,7 +897,7 @@ class PostTest < ActiveSupport::TestCase
@pool = Pool.find_by_name("abc")
@post.reload
assert_not_nil(@pool)
assert_equal("#{@post.id}", @pool.post_ids)
assert_equal([@post.id], @pool.post_ids)
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
end
end