models: rename post/pool archives to post/pool versions.
This commit is contained in:
@@ -4,7 +4,7 @@ class PoolVersionsController < ApplicationController
|
||||
around_action :set_timeout
|
||||
|
||||
def index
|
||||
@pool_versions = PoolArchive.paginated_search(params)
|
||||
@pool_versions = PoolVersion.paginated_search(params)
|
||||
@pool_versions = @pool_versions.includes(:updater, :pool) if request.format.html?
|
||||
|
||||
respond_with(@pool_versions)
|
||||
@@ -14,10 +14,10 @@ class PoolVersionsController < ApplicationController
|
||||
end
|
||||
|
||||
def diff
|
||||
@pool_version = PoolArchive.find(params[:id])
|
||||
@pool_version = PoolVersion.find(params[:id])
|
||||
|
||||
if params[:other_id]
|
||||
@other_version = PoolArchive.find(params[:other_id])
|
||||
@other_version = PoolVersion.find(params[:other_id])
|
||||
else
|
||||
@other_version = @pool_version.previous
|
||||
end
|
||||
@@ -25,19 +25,15 @@ class PoolVersionsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def model_name
|
||||
"PoolArchive"
|
||||
end
|
||||
|
||||
def set_timeout
|
||||
PoolArchive.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
PoolVersion.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
yield
|
||||
ensure
|
||||
PoolArchive.connection.execute("SET statement_timeout = 0")
|
||||
PoolVersion.connection.execute("SET statement_timeout = 0")
|
||||
end
|
||||
|
||||
def check_availabililty
|
||||
if !PoolArchive.enabled?
|
||||
if !PoolVersion.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class PostVersionsController < ApplicationController
|
||||
respond_to :js, only: [:undo]
|
||||
|
||||
def index
|
||||
@post_versions = PostArchive.paginated_search(params)
|
||||
@post_versions = PostVersion.paginated_search(params)
|
||||
|
||||
if request.format.html?
|
||||
@post_versions = @post_versions.includes(:updater, post: [:uploader, :versions])
|
||||
@@ -21,7 +21,7 @@ class PostVersionsController < ApplicationController
|
||||
end
|
||||
|
||||
def undo
|
||||
@post_version = PostArchive.find(params[:id])
|
||||
@post_version = PostVersion.find(params[:id])
|
||||
@post_version.undo!
|
||||
|
||||
respond_with(@post_version)
|
||||
@@ -29,19 +29,15 @@ class PostVersionsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def model_name
|
||||
"PostArchive"
|
||||
end
|
||||
|
||||
def set_timeout
|
||||
PostArchive.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
PostVersion.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
yield
|
||||
ensure
|
||||
PostArchive.connection.execute("SET statement_timeout = 0")
|
||||
PostVersion.connection.execute("SET statement_timeout = 0")
|
||||
end
|
||||
|
||||
def check_availabililty
|
||||
if !PostArchive.enabled?
|
||||
if !PostVersion.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,9 @@ module Moderator
|
||||
module Queries
|
||||
class Tag < ::Struct.new(:user, :count)
|
||||
def self.all(min_date, max_level)
|
||||
return [] unless PostArchive.enabled?
|
||||
return [] unless PostVersion.enabled?
|
||||
|
||||
records = PostArchive.where("updated_at > ?", min_date).group(:updater).count.map do |user, count|
|
||||
records = PostVersion.where("updated_at > ?", min_date).group(:updater).count.map do |user, count|
|
||||
new(user, count)
|
||||
end
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ module Moderator
|
||||
add_row(sums, Upload.where(uploader_ip_addr: ip_addrs).group(:uploader).count)
|
||||
add_row(sums, Hash[User.where(last_ip_addr: ip_addrs).collect { |user| [user, 1] }])
|
||||
|
||||
add_row_id(sums, PoolArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolArchive.enabled?
|
||||
add_row_id(sums, PostArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostArchive.enabled?
|
||||
add_row_id(sums, PoolVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolVersion.enabled?
|
||||
add_row_id(sums, PostVersion.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostVersion.enabled?
|
||||
|
||||
sums
|
||||
end
|
||||
@@ -50,8 +50,8 @@ module Moderator
|
||||
add_row(sums, ArtistCommentaryVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, ArtistVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, NoteVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, PoolArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolArchive.enabled?
|
||||
add_row(sums, PostArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostArchive.enabled?
|
||||
add_row(sums, PoolVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolVersion.enabled?
|
||||
add_row(sums, PostVersion.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostVersion.enabled?
|
||||
add_row(sums, WikiPageVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, Comment.where(creator: users).group(:creator_ip_addr).count)
|
||||
add_row(sums, Dmail.where(from: users).group(:creator_ip_addr).count)
|
||||
|
||||
@@ -28,9 +28,9 @@ class RelatedTagQuery
|
||||
|
||||
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.
|
||||
def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20)
|
||||
return [] unless user.present? && PostArchive.enabled?
|
||||
return [] unless user.present? && PostVersion.enabled?
|
||||
|
||||
versions = PostArchive.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
versions = PostVersion.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
tags = versions.flat_map(&:added_tags)
|
||||
tags = tags.reject { |tag| Tag.is_metatag?(tag) }
|
||||
tags = tags.group_by(&:itself).transform_values(&:size).sort_by { |tag, count| [-count, tag] }.map(&:first)
|
||||
|
||||
@@ -118,8 +118,8 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def versions
|
||||
if PoolArchive.enabled?
|
||||
PoolArchive.where("pool_id = ?", id).order("id asc")
|
||||
if PoolVersion.enabled?
|
||||
PoolVersion.where("pool_id = ?", id).order("id asc")
|
||||
else
|
||||
raise "Archive service not configured"
|
||||
end
|
||||
@@ -268,8 +268,8 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
if PoolArchive.enabled?
|
||||
PoolArchive.queue(self, updater, updater_ip_addr)
|
||||
if PoolVersion.enabled?
|
||||
PoolVersion.queue(self, updater, updater_ip_addr)
|
||||
else
|
||||
Rails.logger.warn("Archive service is not configured. Pool versions will not be saved.")
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class PoolArchive < ApplicationRecord
|
||||
class PoolVersion < ApplicationRecord
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to :pool
|
||||
|
||||
@@ -7,7 +7,6 @@ class PoolArchive < ApplicationRecord
|
||||
end
|
||||
|
||||
establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
self.table_name = "pool_versions"
|
||||
|
||||
module SearchMethods
|
||||
def default_order
|
||||
@@ -109,7 +108,7 @@ class PoolArchive < ApplicationRecord
|
||||
|
||||
def previous
|
||||
@previous ||= begin
|
||||
PoolArchive.where("pool_id = ? and version < ?", pool_id, version).order("version desc").limit(1).to_a
|
||||
PoolVersion.where("pool_id = ? and version < ?", pool_id, version).order("version desc").limit(1).to_a
|
||||
end
|
||||
@previous.first
|
||||
end
|
||||
@@ -59,8 +59,8 @@ class Post < ApplicationRecord
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :view_count
|
||||
|
||||
if PostArchive.enabled?
|
||||
has_many :versions, -> { Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC") }, :class_name => "PostArchive", :dependent => :destroy
|
||||
if PostVersion.enabled?
|
||||
has_many :versions, -> { Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC") }, class_name: "PostVersion", dependent: :destroy
|
||||
end
|
||||
|
||||
module FileMethods
|
||||
@@ -1307,7 +1307,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def create_new_version
|
||||
User.where(id: CurrentUser.id).update_all("post_update_count = post_update_count + 1")
|
||||
PostArchive.queue(self) if PostArchive.enabled?
|
||||
PostVersion.queue(self) if PostVersion.enabled?
|
||||
end
|
||||
|
||||
def revert_to(target)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class PostArchive < ApplicationRecord
|
||||
class PostVersion < ApplicationRecord
|
||||
class RevertError < StandardError; end
|
||||
extend Memoist
|
||||
|
||||
@@ -10,7 +10,6 @@ class PostArchive < ApplicationRecord
|
||||
end
|
||||
|
||||
establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
self.table_name = "post_versions"
|
||||
|
||||
def self.check_for_retry(msg)
|
||||
if msg =~ /can't get socket descriptor/ && msg =~ /post_versions/
|
||||
@@ -98,7 +97,7 @@ class PostArchive < ApplicationRecord
|
||||
if association(:post).loaded? && post && post.association(:versions).loaded?
|
||||
ver = [post.versions.sort_by(&:version).reverse.find { |v| v.version < version }]
|
||||
else
|
||||
ver = PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").limit(1).to_a
|
||||
ver = PostVersion.where("post_id = ? and version < ?", post_id, version).order("version desc").limit(1).to_a
|
||||
end
|
||||
end
|
||||
@previous.first
|
||||
@@ -107,7 +107,7 @@ class User < ApplicationRecord
|
||||
has_many :post_disapprovals, :dependent => :destroy
|
||||
has_many :post_flags, foreign_key: :creator_id
|
||||
has_many :post_votes
|
||||
has_many :post_versions, class_name: "PostArchive", foreign_key: :updater_id
|
||||
has_many :post_versions, foreign_key: :updater_id
|
||||
has_many :bans, -> {order("bans.id desc")}
|
||||
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
|
||||
|
||||
@@ -587,8 +587,8 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def pool_version_count
|
||||
return nil unless PoolArchive.enabled?
|
||||
PoolArchive.for_user(id).count
|
||||
return nil unless PoolVersion.enabled?
|
||||
PoolVersion.for_user(id).count
|
||||
end
|
||||
|
||||
def forum_post_count
|
||||
|
||||
@@ -116,7 +116,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def pool_version_count(template)
|
||||
if PoolArchive.enabled?
|
||||
if PoolVersion.enabled?
|
||||
template.link_to(user.pool_version_count, template.pool_versions_path(:search => {:updater_id => user.id}))
|
||||
else
|
||||
"N/A"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<% end %>
|
||||
<% t.column "Pool" do |pool_version| %>
|
||||
<%= link_to pool_version.pretty_name, pool_path(pool_version.pool_id), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<%= link_to "»", pool_versions_path(search: { pool_id: pool_version.pool_id }, anchor: "pool-archive-#{pool_version.id}"), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<%= link_to "»", pool_versions_path(search: { pool_id: pool_version.pool_id }, anchor: "pool-version-#{pool_version.id}"), class: "pool-category-#{pool_version.pool.category}" %>
|
||||
<% end %>
|
||||
<% t.column "Post Changes", td: { class: "col-expand" } do |pool_version| %>
|
||||
<%= render "pool_versions/diff", diff: pool_version.build_diff %>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<%= subnav_link_to "Delete", pool_path(@pool), :method => :delete, :"data-shortcut" => "shift+d", :"data-confirm" => "Are you sure you want to delete this pool?", :remote => true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<%= subnav_link_to "History", pool_versions_path(:search => {:pool_id => @pool.id}) %>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Version" do |post_version| %>
|
||||
<%= link_to "#{post_version.post_id}.#{post_version.version}", post_versions_path(search: { post_id: post_version.post_id }, anchor: "post-archive-#{post_version.id}") %>
|
||||
<%= link_to "#{post_version.post_id}.#{post_version.version}", post_versions_path(search: { post_id: post_version.post_id }, anchor: "post-version-#{post_version.id}") %>
|
||||
<% end %>
|
||||
<% t.column "Tags", td: {class: "col-expand"} do |post_version| %>
|
||||
<%= post_version_diff(post_version) %>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<% end %>
|
||||
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
<p class="fineprint">Recent updates may not have been processed yet. The most recently processed version was <%= time_ago_in_words_tagged(PostArchive.maximum(:updated_at)) %>.</p>
|
||||
<p class="fineprint">Recent updates may not have been processed yet. The most recently processed version was <%= time_ago_in_words_tagged(PostVersion.maximum(:updated_at)) %>.</p>
|
||||
|
||||
<% if @post_versions.length == 0 %>
|
||||
<%= render "post_sets/blank" %>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<li><%= link_to_wiki "Help", "help:pools" %></li>
|
||||
<li><%= link_to("Listing", pools_path) %></li>
|
||||
<li><%= link_to("Gallery", gallery_pools_path) %></li>
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<li><%= link_to("Changes", pool_versions_path) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
<td><%= presenter.artist_commentary_version_count(self) %></td>
|
||||
</tr>
|
||||
|
||||
<% if PoolArchive.enabled? %>
|
||||
<% if PoolVersion.enabled? %>
|
||||
<tr>
|
||||
<th>Pool Changes</th>
|
||||
<td><%= presenter.pool_version_count(self) %></td>
|
||||
|
||||
@@ -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