[Cleanup] Remove artist commentaries

This commit is contained in:
Earlopain 2022-02-03 17:02:49 +01:00
parent 95337c59bd
commit e9f7ac85bf
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
27 changed files with 16 additions and 789 deletions

View File

@ -1,41 +0,0 @@
class ArtistCommentariesController < ApplicationController
respond_to :html, :json, :js
before_action :admin_only
def index
@commentaries = ArtistCommentary.search(search_params).paginate(params[:page], :limit => params[:limit])
respond_with(@commentaries)
end
def show
if params[:id]
@commentary = ArtistCommentary.find(params[:id])
else
@commentary = ArtistCommentary.find_by_post_id!(params[:post_id])
end
respond_with(@commentary) do |format|
format.html { redirect_to post_path(@commentary.post) }
end
end
def create_or_update
@artist_commentary = ArtistCommentary.find_or_initialize_by(post_id: params.dig(:artist_commentary, :post_id))
@artist_commentary.update(commentary_params)
respond_with(@artist_commentary)
end
def revert
@artist_commentary = ArtistCommentary.find_by_post_id!(params[:id])
@version = @artist_commentary.versions.find(params[:version_id])
@artist_commentary.revert_to!(@version)
end
private
def commentary_params
params.fetch(:artist_commentary, {}).except(:post_id).permit(%i[
original_description original_title translated_description translated_title
])
end
end

View File

@ -1,9 +0,0 @@
class ArtistCommentaryVersionsController < ApplicationController
respond_to :html, :json
before_action :admin_only
def index
@commentary_versions = ArtistCommentaryVersion.search(search_params).paginate(params[:page], :limit => params[:limit])
respond_with(@commentary_versions)
end
end

View File

@ -103,7 +103,6 @@ Autocomplete.initialize_tag_autocomplete = function() {
case "comm":
case "noter":
case "noteupdater":
case "artcomm":
case "fav":
case "favoritedby":
case "appealer":

View File

@ -16,11 +16,6 @@ Upload.initialize_all = function() {
}
this.initialize_similar();
this.initialize_submit();
$("#toggle-artist-commentary").on("click.danbooru", function(e) {
Upload.toggle_commentary();
e.preventDefault();
});
}
if ($("#iqdb-similar").length) {
@ -95,16 +90,6 @@ Upload.initialize_image = function() {
$("#image-resize-to-window-link").on("click.danbooru", Upload.update_scale);
}
Upload.toggle_commentary = function() {
if ($(".artist-commentary").is(":visible")) {
$("#toggle-artist-commentary").text("show »");
} else {
$("#toggle-artist-commentary").text("« hide");
}
$(".artist-commentary").slideToggle();
};
$(function() {
Upload.initialize_all();
});

View File

@ -421,14 +421,6 @@ class PostQueryBuilder
when "note_asc"
relation = relation.order("posts.last_noted_at ASC NULLS FIRST")
when "artcomm"
relation = relation.joins("INNER JOIN artist_commentaries ON artist_commentaries.post_id = posts.id")
relation = relation.order("artist_commentaries.updated_at DESC")
when "artcomm_asc"
relation = relation.joins("INNER JOIN artist_commentaries ON artist_commentaries.post_id = posts.id")
relation = relation.order("artist_commentaries.updated_at ASC")
when "mpixels", "mpixels_desc"
relation = relation.where(Arel.sql("posts.image_width is not null and posts.image_height is not null"))
# Use "w*h/1000000", even though "w*h" would give the same result, so this can use

View File

@ -1,139 +0,0 @@
class ArtistCommentary < ApplicationRecord
class RevertError < Exception ; end
before_validation :trim_whitespace
validates :post_id, uniqueness: true
validates :original_title, length: { maximum: 150 }
validates :translated_title, length: { maximum: 150 }
validates :original_description, length: { maximum: Danbooru.config.wiki_page_max_size }
validates :translated_description, length: { maximum: Danbooru.config.wiki_page_max_size }
belongs_to :post, required: true
has_many :versions, -> {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
has_one :previous_version, -> {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
after_save :create_version
module SearchMethods
def text_matches(query)
query = "*#{query}*" unless query =~ /\*/
escaped_query = query.to_escaped_for_sql_like
where("original_title ILIKE ? ESCAPE E'\\\\' OR original_description ILIKE ? ESCAPE E'\\\\' OR translated_title ILIKE ? ESCAPE E'\\\\' OR translated_description ILIKE ? ESCAPE E'\\\\'", escaped_query, escaped_query, escaped_query, escaped_query)
end
def post_tags_match(query)
where(post_id: PostQueryBuilder.new(query).build.reorder(""))
end
def deleted
where(original_title: "", original_description: "", translated_title: "", translated_description: "")
end
def undeleted
where("original_title != '' OR original_description != '' OR translated_title != '' OR translated_description != ''")
end
def search(params)
q = super
if params[:text_matches].present?
q = q.text_matches(params[:text_matches])
end
if params[:post_id].present?
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end
if params[:original_present].to_s.truthy?
q = q.where("(original_title != '') or (original_description != '')")
elsif params[:original_present].to_s.falsy?
q = q.where("(original_title = '') and (original_description = '')")
end
if params[:translated_present].to_s.truthy?
q = q.where("(translated_title != '') or (translated_description != '')")
elsif params[:translated_present].to_s.falsy?
q = q.where("(translated_title = '') and (translated_description = '')")
end
if params[:post_tags_match].present?
q = q.post_tags_match(params[:post_tags_match])
end
q = q.deleted if params[:is_deleted] == "yes"
q = q.undeleted if params[:is_deleted] == "no"
q.apply_default_order(params)
end
end
def trim_whitespace
self.original_title = (original_title || '').gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
self.translated_title = (translated_title || '').gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
self.original_description = (original_description || '').gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
self.translated_description = (translated_description || '').gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
end
def original_present?
original_title.present? || original_description.present?
end
def translated_present?
translated_title.present? || translated_description.present?
end
def any_field_present?
original_present? || translated_present?
end
module VersionMethods
def create_version
return unless saved_changes?
if merge_version?
merge_version
else
create_new_version
end
end
def merge_version?
previous_version && previous_version.updater == CurrentUser.user && previous_version.updated_at > 1.hour.ago
end
def merge_version
previous_version.update(
original_title: original_title,
original_description: original_description,
translated_title: translated_title,
translated_description: translated_description,
)
end
def create_new_version
versions.create(
:original_title => original_title,
:original_description => original_description,
:translated_title => translated_title,
:translated_description => translated_description
)
end
def revert_to(version)
if post_id != version.post_id
raise RevertError.new("You cannot revert to a previous artist commentary of another post.")
end
self.original_description = version.original_description
self.original_title = version.original_title
self.translated_description = version.translated_description
self.translated_title = version.translated_title
end
def revert_to!(version)
revert_to(version)
save!
end
end
extend SearchMethods
include VersionMethods
end

View File

@ -1,19 +0,0 @@
class ArtistCommentaryVersion < ApplicationRecord
belongs_to :post
belongs_to_updater
scope :for_user, ->(user_id) {where("updater_id = ?", user_id)}
def self.search(params)
q = super
if params[:updater_id]
q = q.where("updater_id = ?", params[:updater_id].to_i)
end
if params[:post_id]
q = q.where("post_id = ?", params[:post_id].to_i)
end
q.apply_default_order(params)
end
end

View File

@ -14,7 +14,7 @@ class Tag < ApplicationRecord
]
METATAGS = %w[
-user user -approver approver commenter comm noter noteupdater artcomm
-user user -approver approver commenter comm noter noteupdater
-pool pool ordpool -fav fav -favoritedby favoritedby md5 -rating rating note -note
-locked locked width height mpixels ratio score favcount filesize source
-source id -id date age order limit -status status tagcount parent -parent
@ -24,7 +24,7 @@ class Tag < ApplicationRecord
deletedby -deletedby votedup voteddown -votedup -voteddown duration
] + TagCategory.short_name_list.map {|x| "#{x}tags"} + COUNT_METATAGS + BOOLEAN_METATAGS
SUBQUERY_METATAGS = %w[commenter comm noter noteupdater artcomm flagger -flagger appealer -appealer]
SUBQUERY_METATAGS = %w[commenter comm noter noteupdater flagger -flagger appealer -appealer]
ORDER_METATAGS = %w[
id id_desc
@ -35,7 +35,6 @@ class Tag < ApplicationRecord
comment comment_asc
comment_bumped comment_bumped_asc
note note_asc
artcomm artcomm_asc
mpixels mpixels_asc
portrait landscape
filesize filesize_asc

View File

@ -1,35 +0,0 @@
<p>If the artist of this image posted some interesting additional information about this work, you can copy it here. <%= link_to "View help.", help_page_path(id: "artist_commentary") %></p>
<form id="fetch-commentary" class="simple_form">
<div class="input">
<label>Copy from</label>
<%= select_tag :commentary_source_type, options_for_select(%w[Source Post]) %>
<%= text_field_tag :commentary_source, post.source %>
<%= text_field_tag :commentary_post_id, post.parent_id, :style => "display: none;" %>
<%= button_tag "Fetch" %>
</div>
</form>
<%= form_tag(create_or_update_artist_commentaries_path(:format => :js), :remote => true, :id => "edit-commentary", :class => "simple_form", :method => :put) do %>
<%= hidden_field :artist_commentary, :post_id, :value => post.id %>
<div class="input">
<label for="artist_commentary_original_title">Original title</label>
<%= text_field :artist_commentary, :original_title, :value => post.artist_commentary.try(:original_title) %>
</div>
<div class="input">
<label for="artist_commentary_original_description">Original description</label>
<%= text_area :artist_commentary, :original_description, :size => "40x6", :value => post.artist_commentary.try(:original_description) %>
</div>
<div class="input">
<label for="artist_commentary_translated_title">Translated title</label>
<%= text_field :artist_commentary, :translated_title, :value => post.artist_commentary.try(:translated_title) %>
</div>
<div class="input">
<label for="artist_commentary_translated_description">Translated description</label>
<%= text_area :artist_commentary, :translated_description, :size => "40x6", :value => post.artist_commentary.try(:translated_description) %>
</div>
<% end %>

View File

@ -1,3 +0,0 @@
<%= form_tag(artist_commentaries_path, :method => :get) do %>
<%= text_field "search", "text_matches", :id => "quick_search_text_matches", :placeholder => "Search commentary" %>
<% end %>

View File

@ -1,10 +0,0 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= render "artist_commentaries/quick_search" %></li>
<%= subnav_link_to "Search", search_artist_commentaries_path %>
<%= subnav_link_to "Listing", artist_commentaries_path %>
<%= subnav_link_to "Recent changes", artist_commentary_versions_path %>
<%= subnav_link_to "Translation requests", artist_commentaries_path(:search => {:post_tags_match => "commentary_request"}) %>
<%= subnav_link_to "Help", help_page_path(id: "artist_commentary") %>
</menu>
<% end %>

View File

@ -1,40 +0,0 @@
<h3>Description</h3>
<menu id="commentary-sections">
<% if artist_commentary.original_present? && artist_commentary.translated_present? %>
<li><a href="#original">Original</a></li> |
<li class="active"><a href="#translated">Translated</a></li>
<% elsif artist_commentary.original_present? %>
<li><b>Original</b></li>
<% elsif artist_commentary.translated_present? %>
<li><b>Translated</b></li>
<% end %>
</menu>
<% if artist_commentary.original_present? %>
<%= tag.section id: "original-artist-commentary", style: ("display: none" if artist_commentary.translated_present?) do %>
<h4><%= artist_commentary.original_title %></h4>
<div class="dtext-container">
<%= format_text(artist_commentary.original_description) %>
</div>
<% end %>
<% end %>
<% if artist_commentary.translated_present? %>
<section id="translated-artist-commentary">
<h4>
<% if artist_commentary.translated_title.present? %>
<%= artist_commentary.translated_title %>
<% else %>
<span class="disabled"><%= artist_commentary.original_title %></span>
<% end %>
</h4>
<div class="dtext-container">
<% if artist_commentary.translated_description.present? %>
<%= format_text(artist_commentary.translated_description, :disable_mentions => true) %>
<% else %>
<span class="disabled"><%= format_text(artist_commentary.original_description) %></span>
<% end %>
</div>
</section>
<% end %>

View File

@ -1 +0,0 @@
location.reload();

View File

@ -1,44 +0,0 @@
<div id="c-artist-commentaries">
<div id="a-index">
<h1>Artist Commentary</h1>
<%= render "posts/partials/common/inline_blacklist" %>
<table width="100%" class="striped">
<thead>
<tr>
<th width="1%">Post</th>
<th>Original</th>
<th>Translated</th>
</tr>
</thead>
<tbody>
<% @commentaries.each do |commentary| %>
<tr>
<td><%= PostPresenter.preview(commentary.post, :tags => "status:any") %></td>
<td>
<h3><%= h(commentary.original_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary.translated_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary.translated_description) %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= numbered_paginator(@commentaries) %>
</div>
</div>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Artist Commentary
<% end %>

View File

@ -1 +0,0 @@
location.reload();

View File

@ -1,20 +0,0 @@
<div id="c-artist-commentaries">
<div id="a-search">
<h1>Search Artist Commentary</h1>
<%= simple_form_for(:search, url: artist_commentaries_path, method: :get, defaults: { required: false }) do |f| %>
<%= f.input :text_matches, label: "Text" %>
<%= f.input :post_tags_match, label: "Tags", input_html: { data: { autocomplete: "tag-query" } } %>
<%= f.input :original_present, label: "Original present?", collection: ["yes", "no"] %>
<%= f.input :translated_present, label: "Translation present?", collection: ["yes", "no"] %>
<%= f.input :is_deleted, label: "Deleted?", collection: ["yes", "no"] %>
<%= f.submit "Search" %>
<% end %>
</div>
</div>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Search Artist Commentary
<% end %>

View File

@ -1,50 +0,0 @@
<div id="p-revert-listing">
<table width="100%" class="striped autofit">
<thead>
<tr>
<th width="5%">Post</th>
<th>Original</th>
<th>Translated</th>
<% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th>
<% end %>
<th width="10%">Edited By</th>
<th width="10%">Date</th>
<% if CurrentUser.is_member? %>
<th width="7%"></th>
<% end %>
</tr>
</thead>
<tbody>
<% @commentary_versions.each do |commentary_version| %>
<tr>
<td><%= link_to commentary_version.post_id, post_path(commentary_version.post_id) %></td>
<td>
<h3><%= h(commentary_version.original_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary_version.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary_version.translated_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary_version.translated_description) %>
</div>
</td>
<% if CurrentUser.is_moderator? %>
<td>
<%= link_to_ip commentary_version.updater_ip_addr %>
</td>
<% end %>
<td><%= link_to_user commentary_version.updater %></td>
<td><%= compact_time commentary_version.updated_at %></td>
<% if CurrentUser.is_member? %>
<td>
<%= link_to "Revert to", revert_artist_commentary_path(commentary_version.post_id, :version_id => commentary_version.id, format: :json), class: 'revert-item-link', 'data-noun': 'comment' %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@ -1,44 +0,0 @@
<div id="p-standard-listing">
<table width="100%" class="striped autofit">
<thead>
<tr>
<th width="5%">Post</th>
<th>Version</th>
<th>Original</th>
<th>Translated</th>
<% if CurrentUser.is_moderator? %>
<th width="10%">IP Address</th>
<% end %>
<th width="10%">Edited By</th>
<th width="10%">Date</th>
</tr>
</thead>
<tbody>
<% @commentary_versions.each do |commentary_version| %>
<tr>
<td><%= PostPresenter.preview(commentary_version.post, :tags => "status:any") %></td>
<td><%= link_to "#{commentary_version.post_id}.#{commentary_version.id}»", artist_commentary_versions_path(search: {post_id: commentary_version.post_id}) %></td>
<td>
<h3><%= h(commentary_version.original_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary_version.original_description) %>
</div>
</td>
<td>
<h3><%= h(commentary_version.translated_title) %></h3>
<div class="dtext-container">
<%= format_text(commentary_version.translated_description) %>
</div>
</td>
<% if CurrentUser.is_moderator? %>
<td>
<%= link_to_ip commentary_version.updater_ip_addr %>
</td>
<% end %>
<td><%= link_to_user commentary_version.updater %></td>
<td><%= compact_time commentary_version.updated_at %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@ -1,22 +0,0 @@
<div id="c-artist-commentary-versions">
<div id="a-index">
<h1>Artist Commentary Changes</h1>
<%= render "posts/partials/common/inline_blacklist" %>
<% if params.dig(:search, :post_id).present? %>
<%= render "revert_listing" %>
<% else %>
<%= render "standard_listing" %>
<% end %>
<%= numbered_paginator(@commentary_versions) %>
</div>
</div>
<%= render "artist_commentaries/secondary_links" %>
<% content_for(:page_title) do %>
Artist Commentary Versions
<% end %>

View File

@ -150,12 +150,12 @@
<% if @post.description.present? %>
<div id="post-description-container" class="styled-dtext">
<div id="artist-commentary" class="expandable <%= 'expanded' unless CurrentUser.description_collapsed_initially? %>">
<div id="description" class="expandable <%= 'expanded' unless CurrentUser.description_collapsed_initially? %>">
<div class="expandable-header">
<span class="section-arrow"></span>
<span>Description</span>
</div>
<div class="expandable-content dtext-container original-artist-commentary">
<div class="expandable-content dtext-container">
<%= format_text(@post.description, max_thumbs: 0) %>
</div>
</div>

View File

@ -291,15 +291,6 @@ Rails.application.routes.draw do
get :search
end
end
resources :artist_commentaries, :only => [:index, :show] do
collection do
put :create_or_update
get :search
end
member do
put :revert
end
end
resource :related_tag, :only => [:show, :update]
match "related_tag/bulk", to: "related_tags#bulk", via: [:get, :post]
resource :recommended_posts, only: [:show]

View File

@ -0,0 +1,10 @@
class RemoveArtistCommentaries < ActiveRecord::Migration[6.1]
def change
remove_column :uploads, :artist_commentary_title
remove_column :uploads, :artist_commentary_desc
remove_column :uploads, :include_artist_commentary
drop_table :artist_commentaries
drop_table :artist_commentary_versions
end
end

View File

@ -175,80 +175,6 @@ CREATE TABLE public.ar_internal_metadata (
);
--
-- Name: artist_commentaries; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.artist_commentaries (
id integer NOT NULL,
post_id integer NOT NULL,
original_title text DEFAULT ''::text NOT NULL,
original_description text DEFAULT ''::text NOT NULL,
translated_title text DEFAULT ''::text NOT NULL,
translated_description text DEFAULT ''::text NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: artist_commentaries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.artist_commentaries_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: artist_commentaries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.artist_commentaries_id_seq OWNED BY public.artist_commentaries.id;
--
-- Name: artist_commentary_versions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.artist_commentary_versions (
id integer NOT NULL,
post_id integer NOT NULL,
updater_id integer NOT NULL,
updater_ip_addr inet NOT NULL,
original_title text,
original_description text,
translated_title text,
translated_description text,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.artist_commentary_versions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.artist_commentary_versions_id_seq OWNED BY public.artist_commentary_versions.id;
--
-- Name: artist_urls; Type: TABLE; Schema: public; Owner: -
--
@ -2455,9 +2381,6 @@ CREATE TABLE public.uploads (
file_size integer,
image_width integer,
image_height integer,
artist_commentary_desc text,
artist_commentary_title text,
include_artist_commentary boolean,
context text,
referer_url text,
description text DEFAULT ''::text NOT NULL
@ -2792,20 +2715,6 @@ ALTER SEQUENCE public.wiki_pages_id_seq OWNED BY public.wiki_pages.id;
ALTER TABLE ONLY public.api_keys ALTER COLUMN id SET DEFAULT nextval('public.api_keys_id_seq'::regclass);
--
-- Name: artist_commentaries id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.artist_commentaries ALTER COLUMN id SET DEFAULT nextval('public.artist_commentaries_id_seq'::regclass);
--
-- Name: artist_commentary_versions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.artist_commentary_versions ALTER COLUMN id SET DEFAULT nextval('public.artist_commentary_versions_id_seq'::regclass);
--
-- Name: artist_urls id; Type: DEFAULT; Schema: public; Owner: -
--
@ -3277,22 +3186,6 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
--
-- Name: artist_commentaries artist_commentaries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.artist_commentaries
ADD CONSTRAINT artist_commentaries_pkey PRIMARY KEY (id);
--
-- Name: artist_commentary_versions artist_commentary_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.artist_commentary_versions
ADD CONSTRAINT artist_commentary_versions_pkey PRIMARY KEY (id);
--
-- Name: artist_urls artist_urls_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -3837,34 +3730,6 @@ CREATE UNIQUE INDEX index_api_keys_on_key ON public.api_keys USING btree (key);
CREATE UNIQUE INDEX index_api_keys_on_user_id ON public.api_keys USING btree (user_id);
--
-- Name: index_artist_commentaries_on_post_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_artist_commentaries_on_post_id ON public.artist_commentaries USING btree (post_id);
--
-- Name: index_artist_commentary_versions_on_post_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_artist_commentary_versions_on_post_id ON public.artist_commentary_versions USING btree (post_id);
--
-- Name: index_artist_commentary_versions_on_updater_id_and_post_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_artist_commentary_versions_on_updater_id_and_post_id ON public.artist_commentary_versions USING btree (updater_id, post_id);
--
-- Name: index_artist_commentary_versions_on_updater_ip_addr; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_artist_commentary_versions_on_updater_ip_addr ON public.artist_commentary_versions USING btree (updater_ip_addr);
--
-- Name: index_artist_urls_on_artist_id; Type: INDEX; Schema: public; Owner: -
--
@ -5340,6 +5205,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210506235640'),
('20210625155528'),
('20210718172512'),
('20220106081415');
('20220106081415'),
('20220203154846');

View File

@ -1,9 +0,0 @@
FactoryBot.define do
factory(:artist_commentary) do
post factory: :post
original_title { FFaker::Lorem.sentences.join(" ") }
original_description { FFaker::Lorem.sentences.join(" ") }
translated_title { FFaker::Lorem.sentences.join(" ") }
translated_description { FFaker::Lorem.sentences.join(" ") }
end
end

View File

@ -1,101 +0,0 @@
require 'test_helper'
class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
context "The artist commentaries controller" do
setup do
@user = create(:user)
as_user do
@commentary1 = create(:artist_commentary)
@commentary2 = create(:artist_commentary)
end
end
context "index action" do
should "render" do
get artist_commentaries_path
assert_response :success
end
should "render with search params" do
params = {
search: {
text_matches: @commentary1.original_title,
post_id: @commentary1.post_id,
original_present: "yes",
translated_present: "yes",
post_tags_match: @commentary1.post.tag_array.first,
}
}
get artist_commentaries_path(params)
assert_response :success
end
end
context "show action" do
should "render" do
get artist_commentary_path(@commentary1.id)
assert_redirected_to(@commentary1.post)
get artist_commentary_path(post_id: @commentary1.post_id)
assert_redirected_to(@commentary1.post)
end
end
context "create_or_update action" do
should "render for create" do
params = {
artist_commentary: {
original_title: "foo",
post_id: FactoryBot.create(:post).id,
},
format: "js"
}
assert_difference("ArtistCommentary.count", 1) do
put_auth create_or_update_artist_commentaries_path(params), @user, as: :js
end
assert_response :success
end
should "render for update" do
params = {
artist_commentary: {
post_id: @commentary1.post_id,
original_title: "foo",
},
format: "js"
}
put_auth create_or_update_artist_commentaries_path(params), @user
@commentary1.reload
assert_response :success
assert_equal("foo", @commentary1.reload.original_title)
end
end
context "revert action" do
should "work" do
original_title = @commentary1.original_title
@commentary1.update(original_title: "foo")
@commentary1.reload
put_auth revert_artist_commentary_path(@commentary1.post_id, version_id: @commentary1.versions.first.id, format: "js"), @user
assert_response :success
assert_equal(original_title, @commentary1.reload.original_title)
end
should "return 404 when trying to revert a nonexistent commentary" do
put_auth revert_artist_commentary_path(-1, version_id: -1, format: "js"), @user
assert_response 404
end
should "not allow reverting to a previous version of another artist commentary" do
put_auth revert_artist_commentary_path(@commentary1.post_id, version_id: @commentary2.versions.first.id, format: "js"), @user
@commentary1.reload
assert_not_equal(@commentary1.original_title, @commentary2.original_title)
assert_response :missing
end
end
end
end

View File

@ -1,21 +0,0 @@
require 'test_helper'
class ArtistCommentaryVersionsControllerTest < ActionDispatch::IntegrationTest
context "The artist commentary versions controller" do
setup do
@user = FactoryBot.create(:user)
as_user do
@commentary1 = FactoryBot.create(:artist_commentary)
@commentary2 = FactoryBot.create(:artist_commentary)
end
end
context "index action" do
should "render" do
get artist_commentary_versions_path
assert_response :success
end
end
end
end

View File

@ -1209,12 +1209,6 @@ class UploadServiceTest < ActiveSupport::TestCase
@upload = FactoryBot.create(:source_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100)
end
should "create a commentary record" do
assert_difference(-> { ArtistCommentary.count }) do
subject.new({include_artist_commentary: true, artist_commentary_title: "blah", artist_commentary_desc: "blah"}).create_post_from_upload(@upload)
end
end
should "create a post" do
post = subject.new({}).create_post_from_upload(@upload)
assert_equal([], post.errors.full_messages)