Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def create
)
end

# rubocop:disable Metrics/AbcSize
def update
input = item_input
item_service
Expand All @@ -86,15 +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)
render action: :edit
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading