Commit 95e0fac5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix Route#rename_children behavior

Given group `gitlab` and `gitlab-org` exists. When rename `gitlab` it
will rename `gitlab-org` group route too. This commit fixes it
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a50cd9eb
...@@ -13,7 +13,7 @@ class Route < ActiveRecord::Base ...@@ -13,7 +13,7 @@ class Route < ActiveRecord::Base
def rename_children def rename_children
# We update each row separately because MySQL does not have regexp_replace. # We update each row separately because MySQL does not have regexp_replace.
# rubocop:disable Rails/FindEach # rubocop:disable Rails/FindEach
Route.where('path LIKE ?', "#{path_was}%").each do |route| Route.where('path LIKE ?', "#{path_was}/%").each do |route|
# Note that update column skips validation and callbacks. # Note that update column skips validation and callbacks.
# We need this to avoid recursive call of rename_children method # We need this to avoid recursive call of rename_children method
route.update_column(:path, route.path.sub(path_was, path)) route.update_column(:path, route.path.sub(path_was, path))
......
---
title: Fix Route#rename_children behavior
merge_request:
author:
require 'spec_helper' require 'spec_helper'
describe Route, models: true do describe Route, models: true do
let!(:group) { create(:group) } let!(:group) { create(:group, path: 'gitlab') }
let!(:route) { group.route } let!(:route) { group.route }
describe 'relationships' do describe 'relationships' do
...@@ -17,13 +17,15 @@ describe Route, models: true do ...@@ -17,13 +17,15 @@ describe Route, models: true do
describe '#rename_children' do describe '#rename_children' do
let!(:nested_group) { create(:group, path: "test", parent: group) } let!(:nested_group) { create(:group, path: "test", parent: group) }
let!(:deep_nested_group) { create(:group, path: "foo", parent: nested_group) } let!(:deep_nested_group) { create(:group, path: "foo", parent: nested_group) }
let!(:similar_group) { create(:group, path: 'gitlab-org') }
it "updates children routes with new path" do before { route.update_attributes(path: 'bar') }
route.update_attributes(path: 'bar')
it "updates children routes with new path" do
expect(described_class.exists?(path: 'bar')).to be_truthy expect(described_class.exists?(path: 'bar')).to be_truthy
expect(described_class.exists?(path: 'bar/test')).to be_truthy expect(described_class.exists?(path: 'bar/test')).to be_truthy
expect(described_class.exists?(path: 'bar/test/foo')).to be_truthy expect(described_class.exists?(path: 'bar/test/foo')).to be_truthy
expect(described_class.exists?(path: 'gitlab-org')).to be_truthy
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment