Configure Devise to send emails using the tenant's slug for the URL #155

Merged
bustikiller merged 4 commits from wedding-creation into main 2024-12-01 17:19:15 +00:00
4 changed files with 21 additions and 3 deletions
Showing only changes of commit 9d08ef6f18 - Show all commits

View File

@ -15,6 +15,8 @@
# index_weddings_on_slug (slug) UNIQUE
#
class Wedding < ApplicationRecord
SLUG_REGEX = /[a-z\d-]+/
validates :date, presence: true
validates :slug, presence: true, uniqueness: true, format: { with: /\A[a-z]+\z/ }
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
end

View File

@ -2,7 +2,7 @@
Rails.application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
scope ":slug", constraints: { slug: /[a-z]+/ } do
scope ":slug", constraints: { slug: Wedding::SLUG_REGEX } do
devise_for :users, skip: [:registration, :session, :confirmation]
devise_scope :user do
post 'users', to: 'users/registrations#create'

View File

@ -3,5 +3,20 @@
require 'rails_helper'
RSpec.describe Wedding, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
describe 'validations' do
subject { build(:wedding) }
describe 'slug' do
it { should allow_value('foo').for(:slug) }
it { should allow_value('foo-bar').for(:slug) }
it { should allow_value('foo-123').for(:slug) }
it { should allow_value('foo-123-').for(:slug) }
it { should allow_value('foo--123').for(:slug) }
it { should_not allow_value('Foo').for(:slug) }
it { should_not allow_value('/foo').for(:slug) }
it { should_not allow_value('foo/123').for(:slug) }
it { should_not allow_value('foo_123').for(:slug) }
it { should_not allow_value('foo/').for(:slug) }
end
end
end

View File

@ -14,6 +14,7 @@ module Swagger
name: 'slug',
in: :path,
type: :string,
pattern: Wedding::SLUG_REGEX,
example: :default,
description: 'Wedding slug'
}