Validate presence of route by Routable concern
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
3f768f9a14
commit
b552a4eb18
2 changed files with 5 additions and 0 deletions
|
@ -7,6 +7,7 @@ module Routable
|
||||||
has_one :route, as: :source, autosave: true, dependent: :destroy
|
has_one :route, as: :source, autosave: true, dependent: :destroy
|
||||||
|
|
||||||
validates_associated :route
|
validates_associated :route
|
||||||
|
validates :route, presence: true
|
||||||
|
|
||||||
before_validation :update_route_path, if: :full_path_changed?
|
before_validation :update_route_path, if: :full_path_changed?
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,10 @@ require 'spec_helper'
|
||||||
describe Group, 'Routable' do
|
describe Group, 'Routable' do
|
||||||
let!(:group) { create(:group) }
|
let!(:group) { create(:group) }
|
||||||
|
|
||||||
|
describe 'Validations' do
|
||||||
|
it { is_expected.to validate_presence_of(:route) }
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Associations' do
|
describe 'Associations' do
|
||||||
it { is_expected.to have_one(:route).dependent(:destroy) }
|
it { is_expected.to have_one(:route).dependent(:destroy) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue