Validate presence of route by Routable concern

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2016-12-07 19:16:02 +02:00
parent 3f768f9a14
commit b552a4eb18
2 changed files with 5 additions and 0 deletions

View File

@ -7,6 +7,7 @@ module Routable
has_one :route, as: :source, autosave: true, dependent: :destroy
validates_associated :route
validates :route, presence: true
before_validation :update_route_path, if: :full_path_changed?
end

View File

@ -3,6 +3,10 @@ require 'spec_helper'
describe Group, 'Routable' do
let!(:group) { create(:group) }
describe 'Validations' do
it { is_expected.to validate_presence_of(:route) }
end
describe 'Associations' do
it { is_expected.to have_one(:route).dependent(:destroy) }
end