Fix #5208: The posts version of create or update artist commentary endpoint does not work without the post ID parameter being passed in the body
Fix /posts/:post_id/artist_commentary/create_or_update not working without passing `artist_commentary[post_id]` in the form body.
This commit is contained in:
@@ -26,7 +26,7 @@ class ArtistCommentariesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_or_update
|
def create_or_update
|
||||||
post_id = params[:artist_commentary].delete(:post_id)
|
post_id = params[:artist_commentary].delete(:post_id) || params[:post_id]
|
||||||
@artist_commentary = authorize ArtistCommentary.find_or_initialize_by(post_id: post_id)
|
@artist_commentary = authorize ArtistCommentary.find_or_initialize_by(post_id: post_id)
|
||||||
@artist_commentary.update(permitted_attributes(@artist_commentary))
|
@artist_commentary.update(permitted_attributes(@artist_commentary))
|
||||||
respond_with(@artist_commentary)
|
respond_with(@artist_commentary)
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<%= edit_form_for(artist_commentary, url: create_or_update_artist_commentaries_path(format: :js), remote: true, method: :put, html: { id: "edit-commentary" }) do |f| %>
|
<%= edit_form_for(artist_commentary, url: create_or_update_post_artist_commentary_path(post_id: post.id, format: :js), remote: true, method: :put, html: { id: "edit-commentary" }) do |f| %>
|
||||||
<%= f.input :post_id, as: :hidden, input_html: { value: post.id } %>
|
|
||||||
|
|
||||||
<%= f.input :original_title, as: :string, input_html: { value: artist_commentary.try(:original_title) } %>
|
<%= f.input :original_title, as: :string, input_html: { value: artist_commentary.try(:original_title) } %>
|
||||||
<%= f.input :original_description, input_html: { value: artist_commentary.try(:original_description) } %>
|
<%= f.input :original_description, input_html: { value: artist_commentary.try(:original_description) } %>
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
params = {
|
params = {
|
||||||
artist_commentary: {
|
artist_commentary: {
|
||||||
original_title: "foo",
|
original_title: "foo",
|
||||||
post_id: FactoryBot.create(:post).id
|
post_id: create(:post).id
|
||||||
},
|
},
|
||||||
format: "js"
|
format: "js"
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,19 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal("foo", @commentary.reload.original_title)
|
assert_equal("foo", @commentary.reload.original_title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "work for /posts/:post_id/artist_commentary/create_or_update" do
|
||||||
|
params = {
|
||||||
|
post_id: create(:post).id,
|
||||||
|
artist_commentary: { original_title: "foo" },
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_difference("ArtistCommentary.count", 1) do
|
||||||
|
put_auth create_or_update_post_artist_commentary_path(params), @user, xhr: true
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "revert action" do
|
context "revert action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user