Fix #5205: Creating posts via API fails if you pass any commentary field but not all.
This commit is contained in:
@@ -80,10 +80,10 @@ class ArtistCommentary < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def trim_whitespace
|
def trim_whitespace
|
||||||
self.original_title = original_title.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
self.original_title = original_title.to_s.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||||
self.translated_title = translated_title.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
self.translated_title = translated_title.to_s.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||||
self.original_description = original_description.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
self.original_description = original_description.to_s.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||||
self.translated_description = translated_description.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
self.translated_description = translated_description.to_s.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def original_present?
|
def original_present?
|
||||||
|
|||||||
@@ -760,6 +760,21 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal("translated desc", @post.artist_commentary.translated_description)
|
assert_equal("translated desc", @post.artist_commentary.translated_description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "create a commentary record if a single commentary field is present" do
|
||||||
|
assert_difference("ArtistCommentary.count", 1) do
|
||||||
|
@post = create_post!(
|
||||||
|
user: @user,
|
||||||
|
artist_commentary_title: "title",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(true, @post.artist_commentary.present?)
|
||||||
|
assert_equal("title", @post.artist_commentary.original_title)
|
||||||
|
assert_equal("", @post.artist_commentary.original_description)
|
||||||
|
assert_equal("", @post.artist_commentary.translated_title)
|
||||||
|
assert_equal("", @post.artist_commentary.translated_description)
|
||||||
|
end
|
||||||
|
|
||||||
should "not create a commentary record if the commentary is blank" do
|
should "not create a commentary record if the commentary is blank" do
|
||||||
assert_no_difference("ArtistCommentary.count") do
|
assert_no_difference("ArtistCommentary.count") do
|
||||||
@post = create_post!(
|
@post = create_post!(
|
||||||
|
|||||||
Reference in New Issue
Block a user