2016-10-31 07:00:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Group, 'Routable' do
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
|
2016-12-07 12:16:02 -05:00
|
|
|
describe 'Validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:route) }
|
|
|
|
end
|
|
|
|
|
2016-10-31 07:00:53 -04:00
|
|
|
describe 'Associations' do
|
|
|
|
it { is_expected.to have_one(:route).dependent(:destroy) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Callbacks' do
|
|
|
|
it 'creates route record on create' do
|
|
|
|
expect(group.route.path).to eq(group.path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates route record on path change' do
|
|
|
|
group.update_attributes(path: 'wow')
|
|
|
|
|
|
|
|
expect(group.route.path).to eq('wow')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ensure route path uniqueness across different objects' do
|
|
|
|
create(:group, parent: group, path: 'xyz')
|
|
|
|
duplicate = build(:project, namespace: group, path: 'xyz')
|
|
|
|
|
|
|
|
expect { duplicate.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Route path has already been taken, Route is invalid')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.find_by_full_path' do
|
|
|
|
let!(:nested_group) { create(:group, parent: group) }
|
|
|
|
|
|
|
|
it { expect(described_class.find_by_full_path(group.to_param)).to eq(group) }
|
|
|
|
it { expect(described_class.find_by_full_path(group.to_param.upcase)).to eq(group) }
|
|
|
|
it { expect(described_class.find_by_full_path(nested_group.to_param)).to eq(nested_group) }
|
|
|
|
it { expect(described_class.find_by_full_path('unknown')).to eq(nil) }
|
|
|
|
end
|
|
|
|
|
2016-12-09 10:27:11 -05:00
|
|
|
describe '.where_full_path_in' do
|
2016-10-31 07:00:53 -04:00
|
|
|
context 'without any paths' do
|
|
|
|
it 'returns an empty relation' do
|
2016-12-09 10:27:11 -05:00
|
|
|
expect(described_class.where_full_path_in([])).to eq([])
|
2016-10-31 07:00:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without any valid paths' do
|
|
|
|
it 'returns an empty relation' do
|
2016-12-09 10:27:11 -05:00
|
|
|
expect(described_class.where_full_path_in(%w[unknown])).to eq([])
|
2016-10-31 07:00:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid paths' do
|
|
|
|
let!(:nested_group) { create(:group, parent: group) }
|
|
|
|
|
|
|
|
it 'returns the projects matching the paths' do
|
2016-12-09 10:27:11 -05:00
|
|
|
result = described_class.where_full_path_in([group.to_param, nested_group.to_param])
|
2016-10-31 07:00:53 -04:00
|
|
|
|
|
|
|
expect(result).to contain_exactly(group, nested_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns projects regardless of the casing of paths' do
|
2016-12-09 10:27:11 -05:00
|
|
|
result = described_class.where_full_path_in([group.to_param.upcase, nested_group.to_param.upcase])
|
2016-10-31 07:00:53 -04:00
|
|
|
|
|
|
|
expect(result).to contain_exactly(group, nested_group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|