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
|
CODENAME_RE = /\A[a-z][a-z0-9]*(_[a-z0-9]+)*\z/.freeze
|
||||||
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\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 #
|
# Validations #
|
||||||
###############
|
###############
|
||||||
|
|
|
@ -9,6 +9,7 @@ class RelationTransition < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :from_status,
|
belongs_to :from_status,
|
||||||
class_name: 'RelationStatus',
|
class_name: 'RelationStatus',
|
||||||
|
inverse_of: :transitions,
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
belongs_to :to_status,
|
belongs_to :to_status,
|
||||||
|
|
|
@ -11,6 +11,16 @@ RSpec.describe RelationStatus do
|
||||||
end
|
end
|
||||||
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
|
describe '#codename' do
|
||||||
def allow_value(*)
|
def allow_value(*)
|
||||||
super.for :codename
|
super.for :codename
|
||||||
|
|
|
@ -8,7 +8,10 @@ RSpec.describe RelationTransition do
|
||||||
describe '#from_status' do
|
describe '#from_status' do
|
||||||
it do
|
it do
|
||||||
is_expected.to \
|
is_expected.to \
|
||||||
belong_to(:from_status).class_name('RelationStatus').optional
|
belong_to(:from_status)
|
||||||
|
.class_name('RelationStatus')
|
||||||
|
.inverse_of(:transitions)
|
||||||
|
.optional
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.not_to validate_presence_of :from_status }
|
it { is_expected.not_to validate_presence_of :from_status }
|
||||||
|
|
Reference in a new issue