[Tests] Fix pool tests

This commit is contained in:
Earlopain 2022-02-10 17:53:51 +01:00
parent f9990932a1
commit b1a8c4960c
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
10 changed files with 7 additions and 71 deletions

View File

@ -21,7 +21,7 @@ class PoolElementsController < ApplicationController
@pool = Pool.find(params[:pool_id])
@post = Post.find(params[:post_id])
@pool.with_lock do
@pool.remove(@post.id)
@pool.remove!(@post)
@pool.save
end
respond_with(@pool, :location => post_path(@post))

View File

@ -3,8 +3,6 @@ require 'test_helper'
class PoolElementsControllerTest < ActionDispatch::IntegrationTest
context "The pools posts controller" do
setup do
mock_pool_archive_service!
start_pool_archive_transaction
@user = travel_to(1.month.ago) {create(:user)}
@mod = create(:moderator_user)
as_user do
@ -13,10 +11,6 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
end
end
teardown do
rollback_pool_archive_transaction
end
context "create action" do
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"}

View File

@ -3,15 +3,9 @@ require 'test_helper'
class PoolVersionsControllerTest < ActionDispatch::IntegrationTest
context "The pool versions controller" do
setup do
mock_pool_archive_service!
start_pool_archive_transaction
@user = create(:user)
end
teardown do
rollback_pool_archive_transaction
end
context "index action" do
setup do
as_user do
@ -32,7 +26,7 @@ class PoolVersionsControllerTest < ActionDispatch::IntegrationTest
end
should "list all versions" do
get pool_versions_path
get_auth pool_versions_path, @user
assert_response :success
assert_select "#pool-version-#{@versions[0].id}"
assert_select "#pool-version-#{@versions[1].id}"
@ -40,7 +34,7 @@ class PoolVersionsControllerTest < ActionDispatch::IntegrationTest
end
should "list all versions that match the search criteria" do
get pool_versions_path, params: {:search => {:updater_id => @user_2.id}}
get_auth pool_versions_path, @user, params: {:search => {:updater_id => @user_2.id}}
assert_response :success
assert_select "#pool-version-#{@versions[0].id}", false
assert_select "#pool-version-#{@versions[1].id}"

View File

@ -3,10 +3,6 @@ require 'test_helper'
class PoolsControllerTest < ActionDispatch::IntegrationTest
context "The pools controller" do
setup do
mock_pool_archive_service!
PoolArchive.sqs_service.stubs(:merge?).returns(false)
start_pool_archive_transaction
travel_to(1.month.ago) do
@user = create(:user)
@mod = create(:moderator_user)
@ -17,10 +13,6 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
end
end
teardown do
rollback_pool_archive_transaction
end
context "index action" do
should "list all pools" do
get pools_path
@ -77,8 +69,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
end
should "not allow updating unpermitted attributes" do
put_auth pool_path(@pool), @user, params: { pool: { is_deleted: true, post_count: -42 }}
assert_equal(false, @pool.reload.is_deleted?)
put_auth pool_path(@pool), @user, params: { pool: { post_count: -42 }}
assert_equal(0, @pool.post_count)
end
end
@ -86,24 +77,10 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
context "destroy action" do
should "destroy a pool" do
delete_auth pool_path(@pool), @mod
@pool.reload
assert_equal(true, @pool.is_deleted?)
end
end
context "undelete action" do
setup do
as(@mod) do
@pool.is_deleted = true
@pool.save
assert_raises(ActiveRecord::RecordNotFound) do
@pool.reload
end
end
should "restore a pool" do
post_auth undelete_pool_path(@pool), @mod
@pool.reload
assert_equal(false, @pool.is_deleted?)
end
end
context "revert action" do

View File

@ -66,7 +66,6 @@ end
class ActiveSupport::TestCase
include PostArchiveTestHelper
include PoolArchiveTestHelper
include DownloadTestHelper
include IqdbTestHelper
include UploadTestHelper
@ -95,7 +94,6 @@ end
class ActionDispatch::IntegrationTest
include PostArchiveTestHelper
include PoolArchiveTestHelper
include TestHelpers
def method_authenticated(method_name, url, user, options)

View File

@ -1,9 +0,0 @@
module PoolArchiveTestHelper
def start_pool_archive_transaction
PoolArchive.connection.begin_transaction joinable: false
end
def rollback_pool_archive_transaction
PoolArchive.connection.rollback_transaction
end
end

View File

@ -10,12 +10,9 @@ class PoolTest < ActiveSupport::TestCase
end
CurrentUser.ip_addr = "127.0.0.1"
start_pool_archive_transaction
end
teardown do
rollback_pool_archive_transaction
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end

View File

@ -1,8 +1,6 @@
require 'test_helper'
class PostArchiveTest < ActiveSupport::TestCase
include PoolArchiveTestHelper
context "A post" do
setup do
Timecop.travel(1.month.ago) do
@ -72,14 +70,13 @@ class PostArchiveTest < ActiveSupport::TestCase
context "that is tagged with a pool:<name> metatag" do
setup do
mock_pool_archive_service!
@pool = FactoryBot.create(:pool)
@post = FactoryBot.create(:post, tag_string: "tagme pool:#{@pool.id}")
end
should "create a version" do
assert_equal("tagme", @post.tag_string)
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
assert_equal("pool:#{@pool.id}", @post.pool_string)
assert_equal(1, @post.versions.size)
assert_equal("tagme", @post.versions.last.tags)

View File

@ -8,9 +8,6 @@ module PostSets
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
mock_pool_archive_service!
start_pool_archive_transaction
@post_1 = FactoryBot.create(:post)
@post_2 = FactoryBot.create(:post)
@post_3 = FactoryBot.create(:post)
@ -21,7 +18,6 @@ module PostSets
end
teardown do
rollback_pool_archive_transaction
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end

View File

@ -777,14 +777,6 @@ class PostTest < ActiveSupport::TestCase
end
context "for a pool" do
setup do
start_pool_archive_transaction
end
teardown do
rollback_pool_archive_transaction
end
context "on creation" do
setup do
@pool = FactoryBot.create(:pool)