2016-10-31 07:00:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Route, models: true do
|
2017-03-21 12:04:12 -04:00
|
|
|
let!(:group) { create(:group, path: 'git_lab', name: 'git_lab') }
|
2016-10-31 07:00:53 -04:00
|
|
|
let!(:route) { group.route }
|
|
|
|
|
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:source) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:source) }
|
|
|
|
it { is_expected.to validate_presence_of(:path) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:path) }
|
|
|
|
end
|
|
|
|
|
2017-03-21 12:04:12 -04:00
|
|
|
describe '.inside_path' do
|
|
|
|
let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
|
|
|
|
let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
|
|
|
|
let!(:another_group) { create(:group, path: 'other') }
|
|
|
|
let!(:similar_group) { create(:group, path: 'gitllab') }
|
|
|
|
let!(:another_group_nested) { create(:group, path: 'another', name: 'another', parent: similar_group) }
|
|
|
|
|
|
|
|
it 'returns correct routes' do
|
|
|
|
expect(Route.inside_path('git_lab')).to match_array([nested_group.route, deep_nested_group.route])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-05 07:43:50 -05:00
|
|
|
describe '#rename_descendants' do
|
2017-02-04 13:26:11 -05:00
|
|
|
let!(:nested_group) { create(:group, path: 'test', name: 'test', parent: group) }
|
|
|
|
let!(:deep_nested_group) { create(:group, path: 'foo', name: 'foo', parent: nested_group) }
|
|
|
|
let!(:similar_group) { create(:group, path: 'gitlab-org', name: 'gitlab-org') }
|
2017-03-21 12:04:12 -04:00
|
|
|
let!(:another_group) { create(:group, path: 'gittlab', name: 'gitllab') }
|
|
|
|
let!(:another_group_nested) { create(:group, path: 'git_lab', name: 'git_lab', parent: another_group) }
|
2016-10-31 07:00:53 -04:00
|
|
|
|
2017-02-04 13:26:11 -05:00
|
|
|
context 'path update' do
|
2017-02-08 15:54:33 -05:00
|
|
|
context 'when route name is set' do
|
|
|
|
before { 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/test')).to be_truthy
|
|
|
|
expect(described_class.exists?(path: 'bar/test/foo')).to be_truthy
|
|
|
|
expect(described_class.exists?(path: 'gitlab-org')).to be_truthy
|
2017-03-21 12:04:12 -04:00
|
|
|
expect(described_class.exists?(path: 'gittlab')).to be_truthy
|
|
|
|
expect(described_class.exists?(path: 'gittlab/git_lab')).to be_truthy
|
2017-02-08 15:54:33 -05:00
|
|
|
end
|
|
|
|
end
|
2016-10-31 07:00:53 -04:00
|
|
|
|
2017-02-08 15:54:33 -05:00
|
|
|
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
|
2017-02-04 13:26:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'name update' do
|
|
|
|
it "updates children routes with new path" do
|
2017-03-21 12:04:12 -04:00
|
|
|
route.update_attributes(name: 'bar')
|
2017-03-20 19:17:14 -04:00
|
|
|
|
2017-02-04 13:26:11 -05:00
|
|
|
expect(described_class.exists?(name: 'bar')).to be_truthy
|
|
|
|
expect(described_class.exists?(name: 'bar / test')).to be_truthy
|
|
|
|
expect(described_class.exists?(name: 'bar / test / foo')).to be_truthy
|
|
|
|
expect(described_class.exists?(name: 'gitlab-org')).to be_truthy
|
|
|
|
end
|
2017-03-20 19:17:14 -04:00
|
|
|
|
|
|
|
it 'handles a rename from nil' do
|
|
|
|
# Note: using `update_columns` to skip all validation and callbacks
|
|
|
|
route.update_columns(name: nil)
|
|
|
|
|
|
|
|
expect { route.update_attributes(name: 'bar') }
|
|
|
|
.to change { route.name }.from(nil).to('bar')
|
|
|
|
end
|
2016-10-31 07:00:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|