From cfd7adbfc7726f2d4a6603b27dd3fb8a99b6ff6e Mon Sep 17 00:00:00 2001 From: Marcello Rocha Date: Wed, 27 Aug 2025 15:24:11 +0200 Subject: [PATCH 1/3] Make the render a stream update --- .../admin/custom_fields/hierarchy/items_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb index bb0786ed2280..a01be8bb4080 100644 --- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb +++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb @@ -91,7 +91,10 @@ def update end, lambda do |validation_result| add_errors_to_edit_form(validation_result) - render action: :edit + update_via_turbo_stream( + component: ItemComponent.new(item: @active_item, show_edit_form: true) + ) + respond_with_turbo_streams end ) end From 8008cc51d62c002b460591792559b0c0b1ae2b23 Mon Sep 17 00:00:00 2001 From: Marcello Rocha Date: Wed, 27 Aug 2025 15:35:29 +0200 Subject: [PATCH 2/3] Disable rubocop for the update action --- .../admin/custom_fields/hierarchy/items_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb index a01be8bb4080..daa9e5de3a48 100644 --- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb +++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb @@ -77,6 +77,7 @@ def create ) end + # rubocop:disable Metrics/AbcSize def update input = item_input item_service @@ -86,18 +87,15 @@ def update short: input[:short], score: input[:score]) .either( - lambda do |_| - redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other) - end, + ->(*) { redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other) }, lambda do |validation_result| add_errors_to_edit_form(validation_result) - update_via_turbo_stream( - component: ItemComponent.new(item: @active_item, show_edit_form: true) - ) + update_via_turbo_stream(component: ItemComponent.new(item: @active_item, show_edit_form: true)) respond_with_turbo_streams end ) end + # rubocop:enable Metrics/AbcSize def move item_service From 2e9b2e98406fa7059b7035cd8c4fca9e363f51fb Mon Sep 17 00:00:00 2001 From: Marcello Rocha Date: Wed, 27 Aug 2025 15:48:05 +0200 Subject: [PATCH 3/3] Updates test --- .../hierarchy/items_controller_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb b/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb index dfa243548292..4dc5d7c9bc7f 100644 --- a/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb +++ b/spec/controllers/admin/custom_fields/hierarchy/items_controller_spec.rb @@ -132,10 +132,16 @@ end context "when validation fails" do - it "renders the new page" do - post :update, params: { custom_field_id: custom_field.id, id: luke.id, label: nil } - expect(response).to be_successful - expect(response).to render_template "edit" + before do + allow(controller).to receive(:respond_with_turbo_streams).and_call_original + allow(controller).to receive(:add_errors_to_edit_form).and_call_original + end + + it "renders the errors on the page" do + post :update, params: { custom_field_id: custom_field.id, id: luke.id, label: nil, format: :turbo_stream } + + expect(controller).to have_received(:respond_with_turbo_streams).once + expect(controller).to have_received(:add_errors_to_edit_form).once end end end