diff options
author | Douwe Maan <douwe@selenight.nl> | 2018-01-31 19:52:09 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2018-02-06 21:06:38 +0300 |
commit | 75144b1e03db342730535f1f49b0e7cd2987d755 (patch) | |
tree | 30295c514e238b48a646d77c6b453e2ec44319f4 /app/models/concerns/routable.rb | |
parent | 8d69436c901a3eee674e72c67d91de3994d30e0c (diff) |
Validate path uniqueness only on Route, and bubble up appropriately
Diffstat (limited to 'app/models/concerns/routable.rb')
-rw-r--r-- | app/models/concerns/routable.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 5c1cce98ad4..dfd7d94450b 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -7,11 +7,12 @@ module Routable has_one :route, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :redirect_routes, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - validates_associated :route validates :route, presence: true scope :with_route, -> { includes(:route) } + after_validation :set_path_errors + before_validation do if full_path_changed? || full_name_changed? prepare_route @@ -125,6 +126,11 @@ module Routable private + def set_path_errors + route_path_errors = self.errors.delete(:"route.path") + self.errors[:path].concat(route_path_errors) if route_path_errors + end + def uncached_full_path if route && route.path.present? @full_path ||= route.path # rubocop:disable Gitlab/ModuleWithInstanceVariables |