Add model RelationStatus#transitions
This commit is contained in:
parent
62017b4813
commit
9ec984c782
4 changed files with 25 additions and 1 deletions
|
@ -4,6 +4,16 @@ class RelationStatus < ApplicationRecord
|
|||
CODENAME_RE = /\A[a-z][a-z0-9]*(_[a-z0-9]+)*\z/.freeze
|
||||
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\z/.freeze
|
||||
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
||||
has_many :transitions,
|
||||
class_name: 'RelationTransition',
|
||||
inverse_of: :from_status,
|
||||
foreign_key: :from_status_id,
|
||||
dependent: :restrict_with_exception
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
|
|
@ -9,6 +9,7 @@ class RelationTransition < ApplicationRecord
|
|||
|
||||
belongs_to :from_status,
|
||||
class_name: 'RelationStatus',
|
||||
inverse_of: :transitions,
|
||||
optional: true
|
||||
|
||||
belongs_to :to_status,
|
||||
|
|
|
@ -11,6 +11,16 @@ RSpec.describe RelationStatus do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#transitions' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:transitions)
|
||||
.class_name('RelationTransition')
|
||||
.inverse_of(:from_status)
|
||||
.dependent(:restrict_with_exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#codename' do
|
||||
def allow_value(*)
|
||||
super.for :codename
|
||||
|
|
|
@ -8,7 +8,10 @@ RSpec.describe RelationTransition do
|
|||
describe '#from_status' do
|
||||
it do
|
||||
is_expected.to \
|
||||
belong_to(:from_status).class_name('RelationStatus').optional
|
||||
belong_to(:from_status)
|
||||
.class_name('RelationStatus')
|
||||
.inverse_of(:transitions)
|
||||
.optional
|
||||
end
|
||||
|
||||
it { is_expected.not_to validate_presence_of :from_status }
|
||||
|
|
Reference in a new issue