Fix #4377: Save commentary by default.

Remove the "Include artist commentary" checkbox. Commentary is included
by default unless the commentary fields are blank.
This commit is contained in:
evazion
2020-04-04 00:39:58 -05:00
parent c6354b2504
commit 743b6f0854
5 changed files with 20 additions and 6 deletions

View File

@@ -77,7 +77,7 @@ class UploadService
)
end
if upload.include_artist_commentary
if upload.has_commentary?
@post.create_artist_commentary(
:original_title => upload.artist_commentary_title,
:original_description => upload.artist_commentary_desc,

View File

@@ -233,6 +233,10 @@ class Upload < ApplicationRecord
as_pending.to_s.truthy?
end
def has_commentary?
artist_commentary_title.present? || artist_commentary_desc.present? || translated_commentary_title.present? || translated_commentary_desc.present?
end
def self.available_includes
[:uploader, :post]
end

View File

@@ -13,7 +13,7 @@ class UploadPolicy < ApplicationPolicy
def permitted_attributes
%i[file source tag_string rating status parent_id artist_commentary_title
artist_commentary_desc include_artist_commentary referer_url
artist_commentary_desc referer_url
md5_confirmation as_pending translated_commentary_title translated_commentary_desc]
end
end

View File

@@ -48,7 +48,6 @@
<div class="artist-commentary" style="display: none;">
<%= f.input :artist_commentary_title, as: :string, label: "Original Title", input_html: { size: 60, value: params[:artist_commentary_title] } %>
<%= f.input :artist_commentary_desc, as: :text, label: "Original Description", input_html: { size: "60x5", value: params[:artist_commentary_desc] } %>
<%= f.input :include_artist_commentary, as: :boolean, label: "Include Commentary", input_html: { checked: params[:include_artist_commentary].present? } %>
</div>
</div>

View File

@@ -1210,10 +1210,9 @@ 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
should "create a commentary record if the commentary is present" do
assert_difference("ArtistCommentary.count", 1) do
@upload.update!(
include_artist_commentary: true,
artist_commentary_title: "blah",
artist_commentary_desc: "blah",
translated_commentary_title: "blah",
@@ -1223,6 +1222,18 @@ class UploadServiceTest < ActiveSupport::TestCase
end
end
should "not create a commentary record if the commentary is blank" do
assert_difference("ArtistCommentary.count", 0) do
@upload.update!(
artist_commentary_title: "",
artist_commentary_desc: "",
translated_commentary_title: "",
translated_commentary_desc: ""
)
UploadService.new({}).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)