models: rename post/pool archives to post/pool versions.
This commit is contained in:
@@ -4,9 +4,6 @@ module Moderator
|
||||
class IpAddrsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The ip addrs controller" do
|
||||
setup do
|
||||
PoolArchive.delete_all
|
||||
PostArchive.delete_all
|
||||
|
||||
@user = create(:moderator_user, created_at: 1.month.ago)
|
||||
as(@user) { create(:comment, creator: @user) }
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The pools controller" do
|
||||
setup do
|
||||
mock_pool_archive_service!
|
||||
PoolArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PoolVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
start_pool_archive_transaction
|
||||
|
||||
travel_to(1.month.ago) do
|
||||
|
||||
@@ -262,7 +262,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
as_user do
|
||||
@post.update(tag_string: "zzz")
|
||||
end
|
||||
|
||||
@@ -4,11 +4,11 @@ module PoolArchiveTestHelper
|
||||
def send_message(msg, *options)
|
||||
_, json = msg.split(/\n/)
|
||||
json = JSON.parse(json)
|
||||
prev = PoolArchive.where(pool_id: json["pool_id"]).order("id desc").first
|
||||
prev = PoolVersion.where(pool_id: json["pool_id"]).order("id desc").first
|
||||
if merge?(prev, json)
|
||||
prev.update_columns(json)
|
||||
else
|
||||
PoolArchive.create(json)
|
||||
PoolVersion.create(json)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,14 +17,14 @@ module PoolArchiveTestHelper
|
||||
end
|
||||
end
|
||||
|
||||
PoolArchive.stubs(:sqs_service).returns(mock_sqs_service.new)
|
||||
PoolVersion.stubs(:sqs_service).returns(mock_sqs_service.new)
|
||||
end
|
||||
|
||||
def start_pool_archive_transaction
|
||||
PoolArchive.connection.begin_transaction joinable: false
|
||||
PoolVersion.connection.begin_transaction joinable: false
|
||||
end
|
||||
|
||||
def rollback_pool_archive_transaction
|
||||
PoolArchive.connection.rollback_transaction
|
||||
PoolVersion.connection.rollback_transaction
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,8 +18,8 @@ module PostArchiveTestHelper
|
||||
_, json = msg.split(/\n/)
|
||||
json = JSON.parse(json)
|
||||
json.delete("created_at")
|
||||
json["version"] = 1 + PostArchive.where(post_id: json["post_id"]).count
|
||||
prev = PostArchive.where(post_id: json["post_id"]).order("id desc").first
|
||||
json["version"] = 1 + PostVersion.where(post_id: json["post_id"]).count
|
||||
prev = PostVersion.where(post_id: json["post_id"]).order("id desc").first
|
||||
if prev
|
||||
json["added_tags"] = json["tags"].scan(/\S+/) - prev.tags.scan(/\S+/)
|
||||
json["removed_tags"] = prev.tags.scan(/\S+/) - json["tags"].scan(/\S+/)
|
||||
@@ -32,7 +32,7 @@ module PostArchiveTestHelper
|
||||
if merge?(prev, json)
|
||||
prev.update_columns(json)
|
||||
else
|
||||
PostArchive.create(json)
|
||||
PostVersion.create(json)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,14 +41,14 @@ module PostArchiveTestHelper
|
||||
end
|
||||
end
|
||||
|
||||
PostArchive.stubs(:sqs_service).returns(mock_sqs_service.new)
|
||||
PostVersion.stubs(:sqs_service).returns(mock_sqs_service.new)
|
||||
end
|
||||
|
||||
def start_post_archive_transaction
|
||||
PostArchive.connection.begin_transaction joinable: false
|
||||
PostVersion.connection.begin_transaction joinable: false
|
||||
end
|
||||
|
||||
def rollback_post_archive_transaction
|
||||
PostArchive.connection.rollback_transaction
|
||||
PostVersion.connection.rollback_transaction
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,8 +9,8 @@ module Moderator
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
@comment = create(:comment, creator: @user, creator_ip_addr: "127.0.0.1")
|
||||
PoolArchive.stubs(:enabled?).returns(false)
|
||||
PostArchive.stubs(:enabled?).returns(false)
|
||||
PoolVersion.stubs(:enabled?).returns(false)
|
||||
PostVersion.stubs(:enabled?).returns(false)
|
||||
@user.reload
|
||||
end
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
mock_pool_archive_service!
|
||||
PoolArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PoolVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
start_pool_archive_transaction
|
||||
end
|
||||
|
||||
@@ -114,7 +114,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
|
||||
context "Reverting a pool" do
|
||||
setup do
|
||||
PoolArchive.stubs(:enabled?).returns(true)
|
||||
PoolVersion.stubs(:enabled?).returns(true)
|
||||
|
||||
@pool = FactoryBot.create(:pool)
|
||||
@p1 = FactoryBot.create(:post)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostArchiveTest < ActiveSupport::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
class PostVersionTest < ActiveSupport::TestCase
|
||||
include PoolVersionTestHelper
|
||||
|
||||
context "A post" do
|
||||
setup do
|
||||
@@ -19,7 +19,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "#undo" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update(tag_string: "1 2")
|
||||
@post.update(tag_string: "2 3")
|
||||
@@ -36,7 +36,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has multiple versions: " do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update(tag_string: "1 2")
|
||||
@post.update(tag_string: "2 3")
|
||||
@@ -44,7 +44,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "a version record" do
|
||||
setup do
|
||||
@version = PostArchive.last
|
||||
@version = PostVersion.last
|
||||
end
|
||||
|
||||
should "know its previous version" do
|
||||
@@ -102,7 +102,7 @@ class PostArchiveTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been updated" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
@post.update(tag_string: "bbb ccc xxx", source: "")
|
||||
end
|
||||
|
||||
@@ -1265,7 +1265,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been updated" do
|
||||
should "create a new version if it's the first version" do
|
||||
assert_difference("PostArchive.count", 1) do
|
||||
assert_difference("PostVersion.count", 1) do
|
||||
post = FactoryBot.create(:post)
|
||||
end
|
||||
end
|
||||
@@ -1273,7 +1273,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "create a new version if it's been over an hour since the last update" do
|
||||
post = FactoryBot.create(:post)
|
||||
travel(6.hours) do
|
||||
assert_difference("PostArchive.count", 1) do
|
||||
assert_difference("PostVersion.count", 1) do
|
||||
post.update(tag_string: "zzz")
|
||||
end
|
||||
end
|
||||
@@ -1281,14 +1281,14 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
should "merge with the previous version if the updater is the same user and it's been less than an hour" do
|
||||
post = FactoryBot.create(:post)
|
||||
assert_difference("PostArchive.count", 0) do
|
||||
assert_difference("PostVersion.count", 0) do
|
||||
post.update(tag_string: "zzz")
|
||||
end
|
||||
assert_equal("zzz", post.versions.last.tags)
|
||||
end
|
||||
|
||||
should "increment the updater's post_update_count" do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc")
|
||||
|
||||
# XXX in the test environment the update count gets bumped twice: and
|
||||
@@ -2697,7 +2697,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post that has been updated" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryBot.create(:post, :rating => "q", :tag_string => "aaa", :source => "")
|
||||
@post.reload
|
||||
@post.update(:tag_string => "aaa bbb ccc ddd")
|
||||
|
||||
@@ -17,7 +17,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has multiple versions: " do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
@post = FactoryBot.create(:post, :tag_string => "1")
|
||||
@post.update(tag_string: "1 2")
|
||||
@post.update(tag_string: "2 3")
|
||||
@@ -25,7 +25,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
|
||||
context "a version record" do
|
||||
setup do
|
||||
@version = PostArchive.last
|
||||
@version = PostVersion.last
|
||||
end
|
||||
|
||||
should "know its previous version" do
|
||||
@@ -67,7 +67,7 @@ class PostVersionTest < ActiveSupport::TestCase
|
||||
|
||||
context "that has been updated" do
|
||||
setup do
|
||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
travel_to(1.minute.ago) do
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user