From 988e158d99b330de28f76f8046ce5be4e6d897a9 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 19:57:08 +0100 Subject: [PATCH] Install acts_as_tenant gem and update documentation --- Gemfile | 1 + Gemfile.lock | 3 +++ config/routes.rb | 32 +++++++++++++---------- db/seeds.rb | 2 +- spec/requests/expenses_spec.rb | 7 +++-- spec/requests/groups_spec.rb | 3 ++- spec/requests/guests_spec.rb | 8 ++++-- spec/requests/schemas.rb | 8 ++++++ spec/requests/users/confirmations_spec.rb | 3 ++- spec/requests/users/registrations_spec.rb | 5 ++-- spec/requests/users/sessions_spec.rb | 7 ++--- 11 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index cc2ec6e..ead69aa 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'jsonapi-rails' gem 'rack-cors' gem 'react-rails' gem 'rubytree' +gem 'acts_as_tenant' group :development, :test do gem 'annotaterb' diff --git a/Gemfile.lock b/Gemfile.lock index bfe49bd..7e795fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,6 +72,8 @@ GEM securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) + acts_as_tenant (1.0.1) + rails (>= 6.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) annotaterb (4.13.0) @@ -387,6 +389,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + acts_as_tenant annotaterb bootsnap chroma diff --git a/config/routes.rb b/config/routes.rb index 35fd068..b407e01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,26 +2,30 @@ Rails.application.routes.draw do mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? - devise_for :users, skip: [:registration, :session, :confirmation] - devise_scope :user do - post 'users', to: 'users/registrations#create' + scope ":slug", constraints: {slug: /[a-z]+/} do + devise_for :users, skip: [:registration, :session, :confirmation] + devise_scope :user do + post 'users', to: 'users/registrations#create' - post '/users/sign_in', to: 'users/sessions#create' - delete '/users/sign_out', to: 'users/sessions#destroy' + post '/users/sign_in', to: 'users/sessions#create' + delete '/users/sign_out', to: 'users/sessions#destroy' - get '/users/confirmation', to: 'users/confirmations#show', as: :confirmation + get '/users/confirmation', to: 'users/confirmations#show', as: :confirmation + end + + resources :groups, only: :index + resources :guests, only: %i[index create update destroy] do + post :bulk_update, on: :collection + end + resources :expenses, only: %i[index update] do + get :summary, on: :collection + end + resources :tables_arrangements, only: %i[index show] end + mount Rswag::Ui::Engine => '/api-docs' mount Rswag::Api::Engine => '/api-docs' - resources :groups, only: :index - resources :guests, only: %i[index create update destroy] do - post :bulk_update, on: :collection - end - resources :expenses, only: %i[index update] do - get :summary, on: :collection - end - resources :tables_arrangements, only: %i[index show] get 'up' => 'rails/health#show', as: :rails_health_check diff --git a/db/seeds.rb b/db/seeds.rb index d1dafe3..8b1f91a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,7 +9,7 @@ Group.delete_all Wedding.delete_all -Wedding.create!(date: 1.year.from_now) +Wedding.create!(slug: :default, date: 1.year.from_now) Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed') Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed') diff --git a/spec/requests/expenses_spec.rb b/spec/requests/expenses_spec.rb index 5e99097..74cf861 100644 --- a/spec/requests/expenses_spec.rb +++ b/spec/requests/expenses_spec.rb @@ -3,10 +3,12 @@ require 'swagger_helper' RSpec.describe 'expenses', type: :request do - path '/expenses' do + path '/{slug}/expenses' do get('list expenses') do tags 'Expenses' produces 'application/json' + parameter Swagger::Schema::SLUG + response(200, 'successful') do schema type: :array, items: { @@ -26,12 +28,13 @@ RSpec.describe 'expenses', type: :request do end end - path '/expenses/{id}' do + path '/{slug}/expenses/{id}' do patch('update expense') do tags 'Expenses' consumes 'application/json' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: 'id', in: :path, type: :string, format: :uuid, description: 'id' parameter name: :body, in: :body, schema: { type: :object, diff --git a/spec/requests/groups_spec.rb b/spec/requests/groups_spec.rb index fd014b5..6d5f057 100644 --- a/spec/requests/groups_spec.rb +++ b/spec/requests/groups_spec.rb @@ -3,10 +3,11 @@ require 'swagger_helper' RSpec.describe 'groups', type: :request do - path '/groups' do + path '/{slug}/groups' do get('list groups') do tags 'Groups' produces 'application/json' + parameter Swagger::Schema::SLUG response(200, 'successful') do schema type: :array, items: { diff --git a/spec/requests/guests_spec.rb b/spec/requests/guests_spec.rb index b73fbcb..9b542fd 100644 --- a/spec/requests/guests_spec.rb +++ b/spec/requests/guests_spec.rb @@ -3,10 +3,11 @@ require 'swagger_helper' RSpec.describe 'guests', type: :request do - path '/guests' do + path '/{slug}/guests' do get('list guests') do tags 'Guests' produces 'application/json' + parameter Swagger::Schema::SLUG response(200, 'successful') do schema type: :array, items: { @@ -33,6 +34,7 @@ RSpec.describe 'guests', type: :request do tags 'Guests' consumes 'application/json' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: :body, in: :body, schema: { type: :object, required: %i[guest], @@ -55,11 +57,12 @@ RSpec.describe 'guests', type: :request do end end - path '/guests/{id}' do + path '/{slug}/guests/{id}' do patch('update guest') do tags 'Guests' consumes 'application/json' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: 'id', in: :path, type: :string, format: :uuid parameter name: :body, in: :body, schema: { type: :object, @@ -85,6 +88,7 @@ RSpec.describe 'guests', type: :request do delete('delete guest') do tags 'Guests' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: 'id', in: :path, type: :string, format: :uuid response_empty_200 diff --git a/spec/requests/schemas.rb b/spec/requests/schemas.rb index 7a49ca0..ce35ad7 100644 --- a/spec/requests/schemas.rb +++ b/spec/requests/schemas.rb @@ -9,5 +9,13 @@ module Swagger updated_at: SwaggerResponseHelper::TIMESTAMP } + + SLUG = { + name: 'slug', + in: :path, + type: :string, + example: :default, + description: 'Wedding slug' + } end end \ No newline at end of file diff --git a/spec/requests/users/confirmations_spec.rb b/spec/requests/users/confirmations_spec.rb index e99794e..12bdfbc 100644 --- a/spec/requests/users/confirmations_spec.rb +++ b/spec/requests/users/confirmations_spec.rb @@ -4,11 +4,12 @@ require 'swagger_helper' RSpec.describe 'users/confirmations', type: :request do - path '/users/confirmation' do + path '/{slug}/users/confirmation' do get('confirm user email') do tags 'Users' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: :confirmation_token, in: :query, type: :string, required: true response(200, 'confirmed') do diff --git a/spec/requests/users/registrations_spec.rb b/spec/requests/users/registrations_spec.rb index f92222c..aa7562f 100644 --- a/spec/requests/users/registrations_spec.rb +++ b/spec/requests/users/registrations_spec.rb @@ -4,12 +4,13 @@ require 'swagger_helper' RSpec.describe 'users/registrations', type: :request do - path '/users' do + path '/{slug}/users' do post('create registration') do tags 'Users Registrations' consumes 'application/json' produces 'application/json' - + + parameter Swagger::Schema::SLUG parameter name: :body, in: :body, schema: { type: :object, required: [:user], diff --git a/spec/requests/users/sessions_spec.rb b/spec/requests/users/sessions_spec.rb index ff7c8a3..a803965 100644 --- a/spec/requests/users/sessions_spec.rb +++ b/spec/requests/users/sessions_spec.rb @@ -4,13 +4,14 @@ require 'swagger_helper' RSpec.describe 'users/sessions', type: :request do - path '/users/sign_in' do + path '/{slug}/users/sign_in' do post('create session') do tags 'Users Sessions' consumes 'application/json' produces 'application/json' + parameter Swagger::Schema::SLUG parameter name: :body, in: :body, schema: { type: :object, required: %i[user], @@ -35,8 +36,8 @@ RSpec.describe 'users/sessions', type: :request do end end - path '/users/sign_out' do - + path '/{slug}/users/sign_out' do + parameter Swagger::Schema::SLUG delete('delete session') do tags 'Users Sessions' consumes 'application/json'