Update wedding slug rules to accept numbers and other chars
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 38s
Add copyright notice / copyright_notice (pull_request) Successful in 1m7s
Run unit tests / unit_tests (pull_request) Successful in 1m34s

This commit is contained in:
Manuel Bustillo 2024-12-01 18:17:07 +01:00
parent f588b97e18
commit 9d08ef6f18
4 changed files with 21 additions and 3 deletions

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'
}