Update wedding slug rules to accept numbers and other chars
This commit is contained in:
parent
f588b97e18
commit
9d08ef6f18
@ -15,6 +15,8 @@
|
|||||||
# index_weddings_on_slug (slug) UNIQUE
|
# index_weddings_on_slug (slug) UNIQUE
|
||||||
#
|
#
|
||||||
class Wedding < ApplicationRecord
|
class Wedding < ApplicationRecord
|
||||||
|
SLUG_REGEX = /[a-z\d-]+/
|
||||||
|
|
||||||
validates :date, presence: true
|
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
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
|
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_for :users, skip: [:registration, :session, :confirmation]
|
||||||
devise_scope :user do
|
devise_scope :user do
|
||||||
post 'users', to: 'users/registrations#create'
|
post 'users', to: 'users/registrations#create'
|
||||||
|
@ -3,5 +3,20 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Wedding, type: :model do
|
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
|
end
|
||||||
|
@ -14,6 +14,7 @@ module Swagger
|
|||||||
name: 'slug',
|
name: 'slug',
|
||||||
in: :path,
|
in: :path,
|
||||||
type: :string,
|
type: :string,
|
||||||
|
pattern: Wedding::SLUG_REGEX,
|
||||||
example: :default,
|
example: :default,
|
||||||
description: 'Wedding slug'
|
description: 'Wedding slug'
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user