Validate Role#name
This commit is contained in:
parent
9605317887
commit
9c34b77f2a
2 changed files with 18 additions and 2 deletions
|
@ -1,11 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Role < ApplicationRecord
|
||||
NAMES = %w[
|
||||
superuser
|
||||
].map(&:freeze).freeze
|
||||
|
||||
has_and_belongs_to_many :accounts, join_table: :account_roles
|
||||
|
||||
belongs_to :resource, polymorphic: true, optional: true
|
||||
|
||||
validates :name, presence: true
|
||||
validates :name,
|
||||
presence: true,
|
||||
inclusion: { in: NAMES }
|
||||
|
||||
validates :resource_type,
|
||||
allow_nil: true,
|
||||
|
|
|
@ -5,7 +5,17 @@ require 'rails_helper'
|
|||
RSpec.describe Role do
|
||||
subject { create :role }
|
||||
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
describe '#name' do
|
||||
def allow_value(*)
|
||||
super.for :name
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
|
||||
it { is_expected.not_to allow_value 'foobar' }
|
||||
|
||||
it { is_expected.to allow_value 'superuser' }
|
||||
end
|
||||
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
|
Reference in a new issue