support pool version archive
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
class PoolElementsControllerTest < ActionController::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
context "The pools posts controller" do
|
||||
setup do
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
@user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
|
||||
@mod = FactoryGirl.create(:moderator_user)
|
||||
CurrentUser.user = @user
|
||||
@@ -12,6 +17,7 @@ class PoolElementsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
class PoolVersionsControllerTest < ActionController::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
context "The pool versions controller" do
|
||||
setup do
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
class PoolsControllerTest < ActionController::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
context "The pools controller" do
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
@@ -10,9 +13,12 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryGirl.create(:post)
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
@@ -99,10 +105,10 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
should "revert to a previous version" do
|
||||
assert_equal(2, PoolVersion.count)
|
||||
assert_equal(2, PoolArchive.count)
|
||||
@pool.reload
|
||||
version = @pool.versions.first
|
||||
assert_equal("#{@post.id}", version.post_ids)
|
||||
assert_equal([@post.id], version.post_ids)
|
||||
post :revert, {:id => @pool.id, :version_id => version.id}, {:user_id => @mod.id}
|
||||
@pool.reload
|
||||
assert_equal([@post.id], @pool.post_id_array)
|
||||
@@ -111,7 +117,7 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
should "not allow reverting to a previous version of another pool" do
|
||||
@pool2 = FactoryGirl.create(:pool)
|
||||
|
||||
post :revert, { :id => @pool.id, :version_id => @pool2.versions(true).first.id }, {:user_id => @user.id}
|
||||
post :revert, { :id => @pool.id, :version_id => @pool2.versions.first.id }, {:user_id => @user.id}
|
||||
@pool.reload
|
||||
|
||||
assert_not_equal(@pool.name, @pool2.name)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class BulkUpdateRequestsHelperTest < ActionView::TestCase
|
||||
end
|
||||
26
test/helpers/pool_archive_test_helper.rb
Normal file
26
test/helpers/pool_archive_test_helper.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
module PoolArchiveTestHelper
|
||||
def mock_pool_archive_service!
|
||||
mock_sqs_service = Class.new do
|
||||
def send_message(msg)
|
||||
_, json = msg.split(/\n/)
|
||||
json = JSON.parse(json)
|
||||
prev = PoolArchive.where(pool_id: json["pool_id"]).order("id desc").first
|
||||
if prev && prev.updater_ip_addr.to_s == json["updater_ip_addr"]
|
||||
prev.update_columns(json)
|
||||
else
|
||||
PoolArchive.create(json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
PoolArchive.stubs(:sqs_service).returns(mock_sqs_service.new)
|
||||
end
|
||||
|
||||
def start_pool_archive_transaction
|
||||
PoolArchive.connection.begin_transaction joinable: false
|
||||
end
|
||||
|
||||
def rollback_pool_archive_transaction
|
||||
PoolArchive.connection.rollback_transaction
|
||||
end
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SavedSearchesHelperTest < ActionView::TestCase
|
||||
end
|
||||
@@ -1,18 +1,26 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
class PoolTest < ActiveSupport::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
setup do
|
||||
Timecop.travel(1.month.ago) do
|
||||
user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = user
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
end
|
||||
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
@@ -53,33 +61,41 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "Reverting a pool" do
|
||||
setup do
|
||||
PoolArchive.stubs(:enabled?).returns(true)
|
||||
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@p1 = FactoryGirl.create(:post)
|
||||
@p2 = FactoryGirl.create(:post)
|
||||
@p3 = FactoryGirl.create(:post)
|
||||
CurrentUser.ip_addr = "1.2.3.4"
|
||||
@pool.add!(@p1)
|
||||
CurrentUser.ip_addr = "1.2.3.5"
|
||||
@pool.add!(@p2)
|
||||
CurrentUser.ip_addr = "1.2.3.6"
|
||||
@pool.add!(@p3)
|
||||
CurrentUser.ip_addr = "1.2.3.7"
|
||||
@pool.remove!(@p1)
|
||||
CurrentUser.ip_addr = "1.2.3.8"
|
||||
@pool.revert_to!(@pool.versions.all[1])
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
@pool.add!(@p1)
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.5") do
|
||||
@pool.add!(@p2)
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.6") do
|
||||
@pool.add!(@p3)
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.7") do
|
||||
@pool.remove!(@p1)
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.8") do
|
||||
version = @pool.versions[1]
|
||||
@pool.revert_to!(version)
|
||||
end
|
||||
end
|
||||
|
||||
should "have the correct versions" do
|
||||
assert_equal(6, @pool.versions.size)
|
||||
assert_equal("", @pool.versions.all[0].post_ids)
|
||||
assert_equal("#{@p1.id}", @pool.versions.all[1].post_ids)
|
||||
assert_equal("#{@p1.id} #{@p2.id}", @pool.versions.all[2].post_ids)
|
||||
assert_equal("#{@p1.id} #{@p2.id} #{@p3.id}", @pool.versions.all[3].post_ids)
|
||||
assert_equal("#{@p2.id} #{@p3.id}", @pool.versions.all[4].post_ids)
|
||||
assert_equal([], @pool.versions.all[0].post_ids)
|
||||
assert_equal([@p1.id], @pool.versions.all[1].post_ids)
|
||||
assert_equal([@p1.id, @p2.id], @pool.versions.all[2].post_ids)
|
||||
assert_equal([@p1.id, @p2.id, @p3.id], @pool.versions.all[3].post_ids)
|
||||
assert_equal([@p2.id, @p3.id], @pool.versions.all[4].post_ids)
|
||||
end
|
||||
|
||||
should "update its post_ids" do
|
||||
assert_equal("#{@p1.id}", @pool.post_ids)
|
||||
assert_equal([@p1.id], @pool.post_id_array)
|
||||
end
|
||||
|
||||
should "update any old posts that were removed" do
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
module PostSets
|
||||
class PoolTest < ActiveSupport::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@@ -9,6 +12,9 @@ module PostSets
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
|
||||
@post_1 = FactoryGirl.create(:post)
|
||||
@post_2 = FactoryGirl.create(:post)
|
||||
@post_3 = FactoryGirl.create(:post)
|
||||
@@ -19,6 +25,7 @@ module PostSets
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/pool_archive_test_helper'
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
|
||||
setup do
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@@ -35,6 +38,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that belongs to a pool" do
|
||||
setup do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@pool.add!(@post)
|
||||
@post.reload
|
||||
@@ -590,6 +594,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "for a pool" do
|
||||
setup do
|
||||
mock_pool_archive_service!
|
||||
start_pool_archive_transaction
|
||||
end
|
||||
|
||||
teardown do
|
||||
rollback_pool_archive_transaction
|
||||
end
|
||||
|
||||
context "on creation" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
@@ -1143,11 +1156,11 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "clear the pixiv id" do
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://fc06.deviantart.net/fs71/f/2013/295/d/7/you_are_already_dead__by_mar11co-d6rgm0e.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1232,19 +1245,19 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "not save the pixiv id" do
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i1.pixiv.net/novel-cover-original/img/2016/11/03/20/10/58/7436075_f75af69f3eacd1656d3733c72aa959cf.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i2.pixiv.net/background/img/2016/10/30/12/27/30/7059005_da9946b806c10d391a81ed1117cd33d6.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i1.pixiv.net/img15/img/omega777/novel/2612734.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://img08.pixiv.net/profile/nice/1408837.jpg")
|
||||
assert_equal(nil, @post.pixiv_id)
|
||||
assert_nil(@post.pixiv_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1440,6 +1453,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "Pools:" do
|
||||
setup do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
end
|
||||
|
||||
context "Removing a post from a pool" do
|
||||
should "update the post's pool string" do
|
||||
post = FactoryGirl.create(:post)
|
||||
@@ -1615,6 +1632,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <pool> metatag" do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
@@ -1626,6 +1645,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <pool> metatag with a wildcard" do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
@@ -2020,7 +2041,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
should "correctly revert all fields" do
|
||||
assert_equal("aaa bbb ccc ddd", @post.tag_string)
|
||||
assert_equal(nil, @post.source)
|
||||
assert_nil(@post.source)
|
||||
assert_equal("q", @post.rating)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user