diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-03-15 13:45:28 +0100 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-04-06 10:01:14 +0200 |
commit | 63e61cfd83bdc03d5c0657b5f93c3236d6a2d987 (patch) | |
tree | b4f3cef7e96a9e1bcb4e10d2a61b9ad0598145a8 /spec/models/concerns | |
parent | 1735ed613910b38c4c069da9c4637bbc4856db36 (diff) | |
download | gitlab-ce-63e61cfd83bdc03d5c0657b5f93c3236d6a2d987.tar.gz |
use more explicit and explanatory sql statement
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/routable_spec.rb | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 1bd0cb075f7..f191605dbdb 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Group, 'Routable' do - let!(:group) { create(:group, name: 'group 1') } + let!(:group) { create(:group, name: 'foo') } describe 'Validations' do it { is_expected.to validate_presence_of(:route) } @@ -92,20 +92,24 @@ describe Group, 'Routable' do end describe '.member_hierarchy' do + # foo/bar would also match foo/barbaz instead of just foo/bar and foo/bar/baz let!(:user) { create(:user) } - # _______ group _______ + # group + # _______ (foo) _______ # | | # | | # nested_group_1 nested_group_2 + # (bar) (barbaz) # | | # | | # nested_group_1_1 nested_group_2_1 + # (baz) (baz) # - let!(:nested_group_1) { create :group, parent: group, name: 'group 1-1' } - let!(:nested_group_1_1) { create :group, parent: nested_group_1, name: 'group 1-1-1' } - let!(:nested_group_2) { create :group, parent: group, name: 'group 1-2' } - let!(:nested_group_2_1) { create :group, parent: nested_group_2, name: 'group 1-2-1' } + let!(:nested_group_1) { create :group, parent: group, name: 'bar' } + let!(:nested_group_1_1) { create :group, parent: nested_group_1, name: 'baz' } + let!(:nested_group_2) { create :group, parent: group, name: 'barbaz' } + let!(:nested_group_2_1) { create :group, parent: nested_group_2, name: 'baz' } context 'user is not a member of any group' do subject { described_class.member_hierarchy(user.id) } @@ -147,7 +151,7 @@ describe Group, 'Routable' do end end - context 'user is member of the first child (internal node)' do + context 'user is member of the first child (internal node), branch 1' do before { nested_group_1.add_owner(user) } subject { described_class.member_hierarchy(user.id) } @@ -159,6 +163,18 @@ describe Group, 'Routable' do end end + context 'user is member of the first child (internal node), branch 2' do + before { nested_group_2.add_owner(user) } + subject { described_class.member_hierarchy(user.id) } + + it 'returns the groups in the hierarchy' do + is_expected.to match_array [ + group, + nested_group_2, nested_group_2_1 + ] + end + end + context 'user is member of the last child (leaf node)' do before { nested_group_1_1.add_owner(user) } subject { described_class.member_hierarchy(user.id) } |