Add spec for no points selected.

This commit is contained in:
Eugene Burmakin 2025-07-26 14:46:53 +02:00
parent e3d3a92faa
commit 31b23745f8
2 changed files with 14 additions and 2 deletions

View file

@ -18,11 +18,14 @@ class PointsController < ApplicationController
end
def bulk_destroy
point_ids = params[:point_ids]&.compact&.reject(&:blank?)
redirect_to points_url(preserved_params),
alert: 'No points selected.',
status: :see_other and return if params[:point_ids].blank?
status: :see_other and return if point_ids.blank?
current_user.tracked_points.where(id: point_ids).destroy_all
current_user.tracked_points.where(id: params[:point_ids].compact).destroy_all
redirect_to points_url(preserved_params),
notice: 'Points were successfully destroyed.',
status: :see_other

View file

@ -63,5 +63,14 @@ RSpec.describe '/points', type: :request do
expect(response).to redirect_to(points_url(start_at: '2021-01-01', end_at: '2021-01-02'))
end
context 'when no points are selected' do
it 'redirects to the points list' do
delete bulk_destroy_points_url, params: { point_ids: [] }
expect(response).to redirect_to(points_url)
expect(flash[:alert]).to eq('No points selected.')
end
end
end
end