2024-04-25 16:46:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
RSpec.describe '/points', type: :request do
|
2024-04-25 16:46:20 -04:00
|
|
|
describe 'GET /index' do
|
2024-05-23 14:12:23 -04:00
|
|
|
before do
|
|
|
|
|
stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
|
|
|
|
|
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is not logged in' do
|
|
|
|
|
it 'redirects to login page' do
|
|
|
|
|
get points_url
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is logged in' do
|
2024-03-15 19:01:00 -04:00
|
|
|
before do
|
|
|
|
|
sign_in create(:user)
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
it 'renders a successful response' do
|
|
|
|
|
get points_url
|
2024-03-15 19:01:00 -04:00
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
expect(response).to be_successful
|
2024-03-15 19:01:00 -04:00
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
2024-05-23 14:12:23 -04:00
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
describe 'DELETE /bulk_destroy' do
|
2024-05-25 07:26:56 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
let(:point1) { create(:point, user:) }
|
|
|
|
|
let(:point2) { create(:point, user:) }
|
2024-03-15 19:01:00 -04:00
|
|
|
|
2024-05-23 14:12:23 -04:00
|
|
|
before do
|
2024-05-25 07:26:56 -04:00
|
|
|
sign_in user
|
2024-05-23 14:12:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'destroys the selected points' do
|
|
|
|
|
delete bulk_destroy_points_url, params: { point_ids: [point1.id, point2.id] }
|
|
|
|
|
|
|
|
|
|
expect(Point.find_by(id: point1.id)).to be_nil
|
|
|
|
|
expect(Point.find_by(id: point2.id)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns a 303 status code' do
|
|
|
|
|
delete bulk_destroy_points_url, params: { point_ids: [point1.id, point2.id] }
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(303)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'redirects to the points list' do
|
|
|
|
|
delete bulk_destroy_points_url, params: { point_ids: [point1.id, point2.id] }
|
|
|
|
|
|
|
|
|
|
expect(response).to redirect_to(points_url)
|
2024-03-15 19:01:00 -04:00
|
|
|
end
|
2024-09-28 10:43:36 -04:00
|
|
|
|
|
|
|
|
it 'preserves the start_at and end_at parameters' do
|
|
|
|
|
delete bulk_destroy_points_url,
|
|
|
|
|
params: { point_ids: [point1.id, point2.id], start_at: '2021-01-01', end_at: '2021-01-02' }
|
|
|
|
|
|
|
|
|
|
expect(response).to redirect_to(points_url(start_at: '2021-01-01', end_at: '2021-01-02'))
|
|
|
|
|
end
|
2025-07-26 08:46:53 -04:00
|
|
|
|
|
|
|
|
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
|
2024-03-15 19:01:00 -04:00
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|