mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Update visits specs
This commit is contained in:
parent
87258df41e
commit
8bb966b546
6 changed files with 25 additions and 113 deletions
|
|
@ -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.
|
||||
- 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.
|
||||
- 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
|
||||
- [x] Swagger doc for Areas endpoint
|
||||
- [ ] Atomicity for visits creation
|
||||
|
|
|
|||
1
Gemfile
1
Gemfile
|
|
@ -9,7 +9,6 @@ gem 'chartkick'
|
|||
gem 'data_migrate'
|
||||
gem 'devise'
|
||||
gem 'geocoder'
|
||||
gem 'groupdate'
|
||||
gem 'importmap-rails'
|
||||
gem 'kaminari'
|
||||
gem 'lograge'
|
||||
|
|
|
|||
|
|
@ -137,8 +137,6 @@ GEM
|
|||
csv (>= 3.0.0)
|
||||
globalid (1.2.1)
|
||||
activesupport (>= 6.1)
|
||||
groupdate (6.4.0)
|
||||
activesupport (>= 6.1)
|
||||
hashdiff (1.1.0)
|
||||
i18n (1.14.5)
|
||||
concurrent-ruby (~> 1.0)
|
||||
|
|
@ -425,7 +423,6 @@ DEPENDENCIES
|
|||
ffaker
|
||||
foreman
|
||||
geocoder
|
||||
groupdate
|
||||
importmap-rails
|
||||
kaminari
|
||||
lograge
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class VisitsController < ApplicationController
|
||||
before_action
|
||||
before_action :set_visit, only: %i[edit update destroy]
|
||||
before_action :set_visit, only: %i[update]
|
||||
|
||||
def index
|
||||
visits = current_user
|
||||
|
|
@ -16,8 +16,6 @@ class VisitsController < ApplicationController
|
|||
@visits = Kaminari.paginate_array(visits).page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @visit.update(visit_params)
|
||||
redirect_to visits_url, notice: 'Visit was successfully updated.', status: :see_other
|
||||
|
|
@ -26,11 +24,6 @@ class VisitsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@visit.destroy!
|
||||
redirect_to visits_url, notice: 'Visit was successfully destroyed.', status: :see_other
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_visit
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Rails.application.routes.draw do
|
|||
post 'settings/generate_api_key', to: 'settings#generate_api_key', as: :generate_api_key
|
||||
|
||||
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 :points, only: %i[index] do
|
||||
collection do
|
||||
|
|
|
|||
|
|
@ -1,123 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
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
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# 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(:user) { create(:user) }
|
||||
|
||||
let(:invalid_attributes) do
|
||||
skip('Add a hash of attributes invalid for your model')
|
||||
before do
|
||||
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
|
||||
|
||||
describe 'GET /index' do
|
||||
it 'renders a successful response' do
|
||||
Visit.create! valid_attributes
|
||||
get visits_url
|
||||
|
||||
expect(response).to be_successful
|
||||
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
|
||||
context 'with valid parameters' do
|
||||
let(:new_attributes) do
|
||||
skip('Add a hash of attributes valid for your model')
|
||||
let(:visit) { create(:visit, user:, status: :pending) }
|
||||
|
||||
it 'confirms the requested visit' do
|
||||
patch visit_url(visit), params: { visit: { status: :confirmed } }
|
||||
|
||||
expect(visit.reload.status).to eq('confirmed')
|
||||
end
|
||||
|
||||
it 'updates the requested visit' do
|
||||
visit = Visit.create! valid_attributes
|
||||
patch visit_url(visit), params: { visit: new_attributes }
|
||||
visit.reload
|
||||
skip('Add assertions for updated state')
|
||||
it 'rejects the requested visit' do
|
||||
patch visit_url(visit), params: { visit: { status: :declined } }
|
||||
|
||||
expect(visit.reload.status).to eq('declined')
|
||||
end
|
||||
|
||||
it 'redirects to the visit' do
|
||||
visit = Visit.create! valid_attributes
|
||||
patch visit_url(visit), params: { visit: new_attributes }
|
||||
visit.reload
|
||||
expect(response).to redirect_to(visit_url(visit))
|
||||
end
|
||||
end
|
||||
it 'redirects to the visit index page' do
|
||||
patch visit_url(visit), params: { visit: { status: :confirmed } }
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue