diff options
Diffstat (limited to 'spec/controllers/concerns')
-rw-r--r-- | spec/controllers/concerns/group_tree_spec.rb | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/spec/controllers/concerns/group_tree_spec.rb b/spec/controllers/concerns/group_tree_spec.rb index a0707688e54..e808f1caa6e 100644 --- a/spec/controllers/concerns/group_tree_spec.rb +++ b/spec/controllers/concerns/group_tree_spec.rb @@ -21,82 +21,94 @@ RSpec.describe GroupTree do end describe 'GET #index' do - it 'filters groups' do - other_group = create(:group, name: 'filter') - other_group.add_owner(user) + shared_examples 'returns filtered groups' do + it 'filters groups' do + other_group = create(:group, name: 'filter') + other_group.add_owner(user) - get :index, params: { filter: 'filt' }, format: :json + get :index, params: { filter: 'filt' }, format: :json - expect(assigns(:groups)).to contain_exactly(other_group) - end + expect(assigns(:groups)).to contain_exactly(other_group) + end - context 'for subgroups' do - it 'only renders root groups when no parent was given' do - create(:group, :public, parent: group) + context 'for subgroups' do + it 'only renders root groups when no parent was given' do + create(:group, :public, parent: group) - get :index, format: :json + get :index, format: :json - expect(assigns(:groups)).to contain_exactly(group) - end + expect(assigns(:groups)).to contain_exactly(group) + end - it 'contains only the subgroup when a parent was given' do - subgroup = create(:group, :public, parent: group) + it 'contains only the subgroup when a parent was given' do + subgroup = create(:group, :public, parent: group) - get :index, params: { parent_id: group.id }, format: :json + get :index, params: { parent_id: group.id }, format: :json - expect(assigns(:groups)).to contain_exactly(subgroup) - end + expect(assigns(:groups)).to contain_exactly(subgroup) + end - it 'allows filtering for subgroups and includes the parents for rendering' do - subgroup = create(:group, :public, parent: group, name: 'filter') + it 'allows filtering for subgroups and includes the parents for rendering' do + subgroup = create(:group, :public, parent: group, name: 'filter') - get :index, params: { filter: 'filt' }, format: :json + get :index, params: { filter: 'filt' }, format: :json - expect(assigns(:groups)).to contain_exactly(group, subgroup) - end + expect(assigns(:groups)).to contain_exactly(group, subgroup) + end - it 'does not include groups the user does not have access to' do - parent = create(:group, :private) - subgroup = create(:group, :private, parent: parent, name: 'filter') - subgroup.add_developer(user) - _other_subgroup = create(:group, :private, parent: parent, name: 'filte') + it 'does not include groups the user does not have access to' do + parent = create(:group, :private) + subgroup = create(:group, :private, parent: parent, name: 'filter') + subgroup.add_developer(user) + _other_subgroup = create(:group, :private, parent: parent, name: 'filte') - get :index, params: { filter: 'filt' }, format: :json + get :index, params: { filter: 'filt' }, format: :json - expect(assigns(:groups)).to contain_exactly(parent, subgroup) - end + expect(assigns(:groups)).to contain_exactly(parent, subgroup) + end - it 'preloads parents regardless of pagination' do - allow(Kaminari.config).to receive(:default_per_page).and_return(1) - group = create(:group, :public) - subgroup = create(:group, :public, parent: group) - search_result = create(:group, :public, name: 'result', parent: subgroup) + it 'preloads parents regardless of pagination' do + allow(Kaminari.config).to receive(:default_per_page).and_return(1) + group = create(:group, :public) + subgroup = create(:group, :public, parent: group) + search_result = create(:group, :public, name: 'result', parent: subgroup) - get :index, params: { filter: 'resu' }, format: :json + get :index, params: { filter: 'resu' }, format: :json - expect(assigns(:groups)).to contain_exactly(group, subgroup, search_result) + expect(assigns(:groups)).to contain_exactly(group, subgroup, search_result) + end end - end - context 'json content' do - it 'shows groups as json' do - get :index, format: :json + context 'json content' do + it 'shows groups as json' do + get :index, format: :json - expect(json_response.first['id']).to eq(group.id) - end + expect(json_response.first['id']).to eq(group.id) + end - context 'nested groups' do - it 'expands the tree when filtering' do - subgroup = create(:group, :public, parent: group, name: 'filter') + context 'nested groups' do + it 'expands the tree when filtering' do + subgroup = create(:group, :public, parent: group, name: 'filter') - get :index, params: { filter: 'filt' }, format: :json + get :index, params: { filter: 'filt' }, format: :json - children_response = json_response.first['children'] + children_response = json_response.first['children'] - expect(json_response.first['id']).to eq(group.id) - expect(children_response.first['id']).to eq(subgroup.id) + expect(json_response.first['id']).to eq(group.id) + expect(children_response.first['id']).to eq(subgroup.id) + end end end end + + it_behaves_like 'returns filtered groups' + + context 'when feature flag :linear_group_tree_ancestor_scopes is disabled' do + before do + stub_feature_flags(linear_group_tree_ancestor_scopes: false) + end + + it_behaves_like 'returns filtered groups' + end end end |