Update visits specs

This commit is contained in:
Eugene Burmakin 2024-07-27 12:35:47 +02:00
parent 87258df41e
commit 8bb966b546
6 changed files with 25 additions and 113 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- A background job to calculate your visits. This job will calculate your visits based on the areas you've created. - A background job to calculate your visits. This job will calculate your visits based on the areas you've created.
- Visits page. This page will show you all your visits, calculated based on the areas you've created. You can see the date and time of the visit, the area you've visited, and the duration of the visit. - Visits page. This page will show you all your visits, calculated based on the areas you've created. You can see the date and time of the visit, the area you've visited, and the duration of the visit.
- A possibility to confirm or decline a visit. When you create an area, the visit is not calculated immediately. You need to confirm or decline the visit. You can do this on the Visits page. Click on the visit, then click on the "Confirm" or "Decline" button. If you confirm the visit, it will be added to your timeline. If you decline the visit, it will be removed from your timeline. - A possibility to confirm or decline a visit. When you create an area, the visit is not calculated immediately. You need to confirm or decline the visit. You can do this on the Visits page. Click on the visit, then click on the "Confirm" or "Decline" button. If you confirm the visit, it will be added to your timeline. If you decline the visit, it will be removed from your timeline.
- Settings for visit calculation. You can set the minimum time spent in the area to consider it as a visit. This setting can be found in the Settings page.
- [ ] Tests - [ ] Tests
- [x] Swagger doc for Areas endpoint - [x] Swagger doc for Areas endpoint
- [ ] Atomicity for visits creation - [ ] Atomicity for visits creation

View file

@ -9,7 +9,6 @@ gem 'chartkick'
gem 'data_migrate' gem 'data_migrate'
gem 'devise' gem 'devise'
gem 'geocoder' gem 'geocoder'
gem 'groupdate'
gem 'importmap-rails' gem 'importmap-rails'
gem 'kaminari' gem 'kaminari'
gem 'lograge' gem 'lograge'

View file

@ -137,8 +137,6 @@ GEM
csv (>= 3.0.0) csv (>= 3.0.0)
globalid (1.2.1) globalid (1.2.1)
activesupport (>= 6.1) activesupport (>= 6.1)
groupdate (6.4.0)
activesupport (>= 6.1)
hashdiff (1.1.0) hashdiff (1.1.0)
i18n (1.14.5) i18n (1.14.5)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
@ -425,7 +423,6 @@ DEPENDENCIES
ffaker ffaker
foreman foreman
geocoder geocoder
groupdate
importmap-rails importmap-rails
kaminari kaminari
lograge lograge

View file

@ -2,7 +2,7 @@
class VisitsController < ApplicationController class VisitsController < ApplicationController
before_action before_action
before_action :set_visit, only: %i[edit update destroy] before_action :set_visit, only: %i[update]
def index def index
visits = current_user visits = current_user
@ -16,8 +16,6 @@ class VisitsController < ApplicationController
@visits = Kaminari.paginate_array(visits).page(params[:page]).per(10) @visits = Kaminari.paginate_array(visits).page(params[:page]).per(10)
end end
def edit; end
def update def update
if @visit.update(visit_params) if @visit.update(visit_params)
redirect_to visits_url, notice: 'Visit was successfully updated.', status: :see_other redirect_to visits_url, notice: 'Visit was successfully updated.', status: :see_other
@ -26,11 +24,6 @@ class VisitsController < ApplicationController
end end
end end
def destroy
@visit.destroy!
redirect_to visits_url, notice: 'Visit was successfully destroyed.', status: :see_other
end
private private
def set_visit def set_visit

View file

@ -26,7 +26,7 @@ Rails.application.routes.draw do
post 'settings/generate_api_key', to: 'settings#generate_api_key', as: :generate_api_key post 'settings/generate_api_key', to: 'settings#generate_api_key', as: :generate_api_key
resources :imports resources :imports
resources :visits, only: %i[index show edit update destroy] resources :visits, only: %i[index update]
resources :exports, only: %i[index create destroy] resources :exports, only: %i[index create destroy]
resources :points, only: %i[index] do resources :points, only: %i[index] do
collection do collection do

View file

@ -1,123 +1,45 @@
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to test the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
RSpec.describe '/visits', type: :request do RSpec.describe '/visits', type: :request do
# This should return the minimal set of attributes required to create a valid let(:user) { create(:user) }
# Visit. As you add validations to Visit, be sure to
# adjust the attributes here as well.
let(:valid_attributes) do
skip('Add a hash of attributes valid for your model')
end
let(:invalid_attributes) do before do
skip('Add a hash of attributes invalid for your model') stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
sign_in user
end end
describe 'GET /index' do describe 'GET /index' do
it 'renders a successful response' do it 'renders a successful response' do
Visit.create! valid_attributes
get visits_url get visits_url
expect(response).to be_successful expect(response).to be_successful
end end
end end
describe 'GET /show' do
it 'renders a successful response' do
visit = Visit.create! valid_attributes
get visit_url(visit)
expect(response).to be_successful
end
end
describe 'GET /edit' do
it 'renders a successful response' do
visit = Visit.create! valid_attributes
get edit_visit_url(visit)
expect(response).to be_successful
end
end
describe 'POST /create' do
context 'with valid parameters' do
it 'creates a new Visit' do
expect do
post visits_url, params: { visit: valid_attributes }
end.to change(Visit, :count).by(1)
end
it 'redirects to the created visit' do
post visits_url, params: { visit: valid_attributes }
expect(response).to redirect_to(visit_url(Visit.last))
end
end
context 'with invalid parameters' do
it 'does not create a new Visit' do
expect do
post visits_url, params: { visit: invalid_attributes }
end.to change(Visit, :count).by(0)
end
it "renders a response with 422 status (i.e. to display the 'new' template)" do
post visits_url, params: { visit: invalid_attributes }
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
describe 'PATCH /update' do describe 'PATCH /update' do
context 'with valid parameters' do context 'with valid parameters' do
let(:new_attributes) do let(:visit) { create(:visit, user:, status: :pending) }
skip('Add a hash of attributes valid for your model')
it 'confirms the requested visit' do
patch visit_url(visit), params: { visit: { status: :confirmed } }
expect(visit.reload.status).to eq('confirmed')
end end
it 'updates the requested visit' do it 'rejects the requested visit' do
visit = Visit.create! valid_attributes patch visit_url(visit), params: { visit: { status: :declined } }
patch visit_url(visit), params: { visit: new_attributes }
visit.reload expect(visit.reload.status).to eq('declined')
skip('Add assertions for updated state')
end end
it 'redirects to the visit' do it 'redirects to the visit index page' do
visit = Visit.create! valid_attributes patch visit_url(visit), params: { visit: { status: :confirmed } }
patch visit_url(visit), params: { visit: new_attributes }
visit.reload
expect(response).to redirect_to(visit_url(visit))
end
end
context 'with invalid parameters' do
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
visit = Visit.create! valid_attributes
patch visit_url(visit), params: { visit: invalid_attributes }
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
describe 'DELETE /destroy' do
it 'destroys the requested visit' do
visit = Visit.create! valid_attributes
expect do
delete visit_url(visit)
end.to change(Visit, :count).by(-1)
end
it 'redirects to the visits list' do
visit = Visit.create! valid_attributes
delete visit_url(visit)
expect(response).to redirect_to(visits_url) expect(response).to redirect_to(visits_url)
end end
end end
end
end end