diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-02-08 15:04:31 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-02-08 15:04:31 +0000 |
commit | 7fa767fe35e7e7f023ee972bc6034fbdccf84ee7 (patch) | |
tree | 73aaebc95bc57dc9cae5078c835b041f45b36629 /spec | |
parent | 4b4e07cf47f82390255808fa4afdfe6c7fd96b5f (diff) | |
parent | f642a4608d99b1344d862134900c2e078eda9cfc (diff) | |
download | gitlab-ce-7fa767fe35e7e7f023ee972bc6034fbdccf84ee7.tar.gz |
Merge branch 'dz-limit-nested-groups' into 'master'
Limit level of nesting for groups
See merge request !9000
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/namespace_spec.rb | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 7bb1657bc3a..ec389f20d78 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -3,21 +3,32 @@ require 'spec_helper' describe Namespace, models: true do let!(:namespace) { create(:namespace) } - it { is_expected.to have_many :projects } - it { is_expected.to have_many :project_statistics } - it { is_expected.to belong_to :parent } - it { is_expected.to have_many :children } + describe 'associations' do + it { is_expected.to have_many :projects } + it { is_expected.to have_many :project_statistics } + it { is_expected.to belong_to :parent } + it { is_expected.to have_many :children } + end - it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_id) } - it { is_expected.to validate_length_of(:name).is_at_most(255) } + describe 'validations' do + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_id) } + it { is_expected.to validate_length_of(:name).is_at_most(255) } + it { is_expected.to validate_length_of(:description).is_at_most(255) } + it { is_expected.to validate_presence_of(:path) } + it { is_expected.to validate_length_of(:path).is_at_most(255) } + it { is_expected.to validate_presence_of(:owner) } - it { is_expected.to validate_length_of(:description).is_at_most(255) } + it 'does not allow too deep nesting' do + ancestors = (1..21).to_a + nested = build(:namespace, parent: namespace) - it { is_expected.to validate_presence_of(:path) } - it { is_expected.to validate_length_of(:path).is_at_most(255) } + allow(nested).to receive(:ancestors).and_return(ancestors) - it { is_expected.to validate_presence_of(:owner) } + expect(nested).not_to be_valid + expect(nested.errors[:parent_id].first).to eq('has too deep level of nesting') + end + end describe "Respond to" do it { is_expected.to respond_to(:human_name) } |