From 743b6f0854a69cc7155dfc742c56c1a74efecbbe Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 4 Apr 2020 00:39:58 -0500 Subject: [PATCH] Fix #4377: Save commentary by default. Remove the "Include artist commentary" checkbox. Commentary is included by default unless the commentary fields are blank. --- app/logical/upload_service.rb | 2 +- app/models/upload.rb | 4 ++++ app/policies/upload_policy.rb | 2 +- app/views/uploads/new.html.erb | 1 - test/unit/upload_service_test.rb | 17 ++++++++++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/logical/upload_service.rb b/app/logical/upload_service.rb index 3527b063b..87ff1b672 100644 --- a/app/logical/upload_service.rb +++ b/app/logical/upload_service.rb @@ -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, diff --git a/app/models/upload.rb b/app/models/upload.rb index 33c540aae..f5e812d86 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -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 diff --git a/app/policies/upload_policy.rb b/app/policies/upload_policy.rb index c9dd0d774..fa49fb7ad 100644 --- a/app/policies/upload_policy.rb +++ b/app/policies/upload_policy.rb @@ -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 diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index 981e90edd..c34bdaf92 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -48,7 +48,6 @@ diff --git a/test/unit/upload_service_test.rb b/test/unit/upload_service_test.rb index 617851c12..f8382dd86 100644 --- a/test/unit/upload_service_test.rb +++ b/test/unit/upload_service_test.rb @@ -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)