Merge branch 'dz-fix-route-rename-descendants' into 'master'
Fix route rename descendants if route.name is blank See merge request !9074
This commit is contained in:
commit
a6a3df644e
|
@ -15,14 +15,19 @@ class Route < ActiveRecord::Base
|
|||
descendants = Route.where('path LIKE ?', "#{path_was}/%")
|
||||
|
||||
descendants.each do |route|
|
||||
attributes = {
|
||||
path: route.path.sub(path_was, path),
|
||||
name: route.name.sub(name_was, name)
|
||||
}
|
||||
attributes = {}
|
||||
|
||||
if path_changed? && route.path.present?
|
||||
attributes[:path] = route.path.sub(path_was, path)
|
||||
end
|
||||
|
||||
if name_changed? && route.name.present?
|
||||
attributes[:name] = route.name.sub(name_was, name)
|
||||
end
|
||||
|
||||
# Note that update_columns skips validation and callbacks.
|
||||
# We need this to avoid recursive call of rename_descendants method
|
||||
route.update_columns(attributes)
|
||||
route.update_columns(attributes) unless attributes.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ describe Route, models: true do
|
|||
let!(:similar_group) { create(:group, path: 'gitlab-org', name: 'gitlab-org') }
|
||||
|
||||
context 'path update' do
|
||||
context 'when route name is set' do
|
||||
before { route.update_attributes(path: 'bar') }
|
||||
|
||||
it "updates children routes with new path" do
|
||||
|
@ -30,6 +31,17 @@ describe Route, models: true do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when route name is nil' do
|
||||
before do
|
||||
route.update_column(:name, nil)
|
||||
end
|
||||
|
||||
it "does not fail" do
|
||||
expect(route.update_attributes(path: 'bar')).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'name update' do
|
||||
before { route.update_attributes(name: 'bar') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue